Index: chrome/browser/resources/md_bookmarks/dnd_manager.js |
diff --git a/chrome/browser/resources/md_bookmarks/dnd_manager.js b/chrome/browser/resources/md_bookmarks/dnd_manager.js |
index cda4c8cad756423f5b60c3913d2df179c0b979d1..51b68c93a040ce7213371e135decc76754932d75 100644 |
--- a/chrome/browser/resources/md_bookmarks/dnd_manager.js |
+++ b/chrome/browser/resources/md_bookmarks/dnd_manager.js |
@@ -286,11 +286,49 @@ cr.define('bookmarks', function() { |
onDrop_: function(e) { |
if (this.dropDestination_) { |
e.preventDefault(); |
+ |
+ var dropInfo = this.calculateDropInfo_(this.dropDestination_); |
+ if (dropInfo.index != -1) |
+ chrome.bookmarkManagerPrivate.drop(dropInfo.parentId, dropInfo.index); |
+ else |
+ chrome.bookmarkManagerPrivate.drop(dropInfo.parentId); |
} |
this.dropDestination_ = null; |
this.dropIndicator_.finish(); |
}, |
+ /** |
+ * @param {DropDestination} dropDestination |
+ * @return {?{parentId: string, index: number}} |
tsergeant
2017/03/29 00:32:48
Nit: This shouldn't be nullable, there's no early
calamity
2017/03/29 03:35:37
Done.
|
+ */ |
+ calculateDropInfo_: function(dropDestination) { |
+ var node = getBookmarkNode(dropDestination.element); |
+ var position = dropDestination.position; |
+ var parentId = position == DropPosition.ON || !node.parentId ? |
+ node.id : |
+ node.parentId; |
+ var index = -1; |
+ |
+ if (position != DropPosition.ON) { |
+ var state = bookmarks.Store.getInstance().data; |
+ var listItems = bookmarks.util.getDisplayedList(state); |
tsergeant
2017/03/29 00:32:48
I think that since you can't drop onto search resu
calamity
2017/03/29 03:35:37
Changed, added a comment.
tsergeant
2017/03/29 04:28:01
I actually meant that you can replace the whole if
calamity
2017/03/30 01:57:54
Ah yeah, I made this a bit more clear.
|
+ // TODO(calamity): Handle dropping to an empty bookmark list. |
+ if (isBookmarkItem(dropDestination.element)) { |
+ index = listItems.indexOf(node.id); |
+ } else { |
+ index = state.nodes[node.parentId].children.indexOf(node.id); |
+ } |
+ |
+ if (position == DropPosition.BELOW) |
+ index++; |
+ } |
+ |
+ return { |
+ index: index, |
+ parentId: parentId, |
+ }; |
+ }, |
+ |
/** @private */ |
clearDragData_: function() { |
this.dragInfo_.clearDragData(); |