From 829809ec98802b1d19d8f1793d90079833899560 Mon Sep 17 00:00:00 2001 From: "deepak.m1" Date: Thu, 8 Jan 2015 22:41:46 -0800 Subject: [PATCH] In Bookmark manager 'Add page' and 'Add Folder' always add new page or folder at the end. 1.When we add new page or new folder after selecting some page bookmarked entry in Bookmark manager, then new item should be added immediately below the selected item. 2.when we add new page or new folder after selecting some folder bookmarked entry in Bookmark manager, then new item should be added as last item inside selected folder. 3.when we add new page or new folder without selecting any bookmarked entry in Bookmark manager, then new item should be added in the last of already existing bookmarked entries. Added code in addPage() and newFolder() in main.js for getting the index of new node to be added so that it will be at proper location. BUG=409816 Review URL: https://codereview.chromium.org/795483004 Cr-Commit-Position: refs/heads/master@{#310719} --- .../browser/resources/bookmark_manager/js/main.js | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/chrome/browser/resources/bookmark_manager/js/main.js b/chrome/browser/resources/bookmark_manager/js/main.js index efab6e96b883..cfab1ac1d80f 100644 --- a/chrome/browser/resources/bookmark_manager/js/main.js +++ b/chrome/browser/resources/bookmark_manager/js/main.js @@ -1029,12 +1029,18 @@ function newFolder(opt_target) { performGlobalUndo = null; // This can't be undone, so disable global undo. var parentId = computeParentFolderForNewItem(); - + var selectedItem = bmm.list.selectedItem; + var newIndex; // Callback is called after tree and list data model updated. function createFolder(callback) { + if (selectedItem && document.activeElement != bmm.tree && + !bmm.isFolder(selectedItem)) { + newIndex = bmm.list.dataModel.indexOf(selectedItem) + 1; + } chrome.bookmarks.create({ title: loadTimeData.getString('new_folder_name'), - parentId: parentId + parentId: parentId, + index: newIndex }, callback); } @@ -1048,8 +1054,8 @@ function newFolder(opt_target) { } function editNewFolderInList() { - createFolder(function() { - var index = bmm.list.dataModel.length - 1; + createFolder(function(newNode) { + var index = newNode.index; var sm = bmm.list.selectionModel; sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index; scrollIntoViewAndMakeEditable(index); @@ -1080,20 +1086,29 @@ function scrollIntoViewAndMakeEditable(index) { */ function addPage() { var parentId = computeParentFolderForNewItem(); - + var selectedItem = bmm.list.selectedItem; + var newIndex; function editNewBookmark() { + if (selectedItem && document.activeElement != bmm.tree && + !bmm.isFolder(selectedItem)) { + newIndex = bmm.list.dataModel.indexOf(selectedItem) + 1; + } + var fakeNode = { title: '', url: '', parentId: parentId, + index: newIndex, id: 'new' }; var dataModel = bmm.list.dataModel; - var length = dataModel.length; - dataModel.splice(length, 0, fakeNode); + var index = dataModel.length; + if (newIndex != undefined) + index = newIndex; + dataModel.splice(index, 0, fakeNode); var sm = bmm.list.selectionModel; - sm.anchorIndex = sm.leadIndex = sm.selectedIndex = length; - scrollIntoViewAndMakeEditable(length); + sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index; + scrollIntoViewAndMakeEditable(index); }; navigateTo(parentId, editNewBookmark); -- 2.11.4.GIT