diff --git a/browser/components/places/content/controller.js b/browser/components/places/content/controller.js index 3ef44a44d8f1..b4a8bd6cedb5 100755 --- a/browser/components/places/content/controller.js +++ b/browser/components/places/content/controller.js @@ -62,9 +62,15 @@ const TYPE_HTML = "text/html"; // Place entries as raw URL text const TYPE_UNICODE = "text/unicode"; +// No change to the view, preserve current selection const RELOAD_ACTION_NOTHING = 0; +// Inserting items new to the view, select the inserted rows const RELOAD_ACTION_INSERT = 1; +// Removing items from the view, select the first item after the last selected const RELOAD_ACTION_REMOVE = 2; +// Moving items within a view, don't treat the dropped items as additional +// rows. +const RELOAD_ACTION_MOVE = 3; function STACK(args) { var temp = arguments.callee.caller; @@ -1015,7 +1021,8 @@ var PlacesControllerDragHelper = { var copy = session.dragAction & Ci.nsIDragService.DRAGDROP_ACTION_COPY; var transactions = []; var xferable = this._initTransferable(targetView, orientation); - for (var i = 0; i < session.numDropItems; ++i) { + var dropCount = session.numDropItems; + for (var i = 0; i < dropCount; ++i) { session.getData(xferable, i); var data = { }, flavor = { }; @@ -1030,14 +1037,23 @@ var PlacesControllerDragHelper = { insertionPoint.index, copy)); } - if (sourceView) - sourceView.willReloadView(RELOAD_ACTION_REMOVE, sourceView, null, - session.numDropItems); - PlacesController.willReloadView(RELOAD_ACTION_INSERT, targetView, - insertionPoint, session.numDropItems); + if (sourceView == targetView) { + // When we're rearranging the contents of the current view, we + // invoke separate handling that takes care not to count the + // dropCount as added rows - they just changed index. + PlacesController.willReloadView(RELOAD_ACTION_MOVE, targetView, + insertionPoint, dropCount); + } + else { + if (sourceView) + sourceView.willReloadView(RELOAD_ACTION_REMOVE, sourceView, null, + dropCount); + PlacesController.willReloadView(RELOAD_ACTION_INSERT, targetView, + insertionPoint, dropCount); + } var txn = new PlacesAggregateTransaction("DropItems", transactions); PlacesController._hist.transactionManager.doTransaction(txn); - if (sourceView) + if (sourceView && sourceView != targetView) sourceView.didReloadView(sourceView); PlacesController.didReloadView(targetView); } diff --git a/browser/components/places/content/tree.xml b/browser/components/places/content/tree.xml index 1eb197b35c37..f2d94278acc8 100644 --- a/browser/components/places/content/tree.xml +++ b/browser/components/places/content/tree.xml @@ -478,6 +478,25 @@ this._selection.push({ min: min.value, max: max.value }); } break; + case RELOAD_ACTION_MOVE: + // Insert index of insertion and number of rows to insert + var query = this._places.getNewQuery(); + query.setFolders([insertionPoint.folderId], 1); + query.itemTypes = this.filterOptions; + var options = this._places.getNewQueryOptions(); + options.setGroupingMode([Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER], 1); + var result = this._places.executeQuery(query, options); + if (insertionPoint.index > -1) { + var node = result.getChild(insertionPoint.index - 1); + var index = this.getResult().treeIndexForNode(node); + if (insertionPoint.index == result.childCount) + ++index; + } + else + index = this.getResult().childCount; + var max = index + count - 1; + this._selection = [{ min: index, max: max }]; + break; case RELOAD_ACTION_INSERT: // Insert index of insertion and number of rows to insert var query = this._places.getNewQuery(); @@ -505,8 +524,8 @@ this._selection = [{ min: min.value, max: min.value }]; break; } - if (this._selection.length) - LOG("SET UP RANGE: " + this._selection[0].toSource() + " for " + this.id + " action = " + action); + //if (this._selection.length) + // LOG("SET UP RANGE: " + this._selection[0].toSource() + " for " + this.id + " action = " + action); ]]> @@ -519,7 +538,7 @@ selection.clearSelection(); for (var i = 0; i < this._selection.length; ++i) { var range = this._selection[i]; - LOG("RESELECTING RANGE: " + range.min + "," + range.max + " in: " + this.id); + //LOG("RESELECTING RANGE: " + range.min + "," + range.max + " in: " + this.id); selection.rangedSelect(range.min, range.max, true); } if (view != this.view)