Chromium Code Reviews| Index: chrome/browser/resources/md_bookmarks/store.js |
| diff --git a/chrome/browser/resources/md_bookmarks/store.js b/chrome/browser/resources/md_bookmarks/store.js |
| index 8f0ef849e334c115d6178bff4e4628950a34fcd8..6447c2ef470e2407b92b959042b225f9634bfaa1 100644 |
| --- a/chrome/browser/resources/md_bookmarks/store.js |
| +++ b/chrome/browser/resources/md_bookmarks/store.js |
| @@ -12,10 +12,9 @@ var BookmarksStore = Polymer({ |
| notify: true, |
| }, |
| - /** @type {?string} */ |
| + /** @type {string} */ |
| selectedId: { |
| type: String, |
| - observer: 'updateSelectedDisplay_', |
| notify: true, |
| }, |
| @@ -41,7 +40,10 @@ var BookmarksStore = Polymer({ |
| idToNodeMap_: Object, |
| /** @type {?number} */ |
| - anchorIndex_: Number, |
| + anchorIndex_: { |
|
tsergeant
2017/02/08 03:11:10
Any particular reason why this needed to change? N
angelayang
2017/02/09 04:17:36
Previously anchorIndex is set to null on initializ
|
| + type: Number, |
| + value: null, |
| + }, |
| /** @type {Set<string>} */ |
| searchResultSet_: Object, |
| @@ -96,18 +98,18 @@ var BookmarksStore = Polymer({ |
| BookmarksStore.initNodes(this.rootNode, this.idToNodeMap_); |
| // Initialize the store's fields from the router. |
| - if (this.$.router.searchTerm) |
| - this.searchTerm = this.$.router.searchTerm; |
| - else |
| - this.fire('selected-folder-changed', this.$.router.selectedId); |
| + this.selectFolder_(this.$.router.selectedId); |
| + this.searchTerm = this.$.router.searchTerm; |
| }, |
| /** @private */ |
| deselectFolders_: function() { |
| + if (!this.idToNodeMap_[this.selectedId]) |
| + return; |
| + |
| this.unlinkPaths('displayedList'); |
| this.set( |
| this.idToNodeMap_[this.selectedId].path + '.isSelectedFolder', false); |
| - this.selectedId = null; |
| }, |
| /** |
| @@ -116,9 +118,6 @@ var BookmarksStore = Polymer({ |
| * @return {boolean} |
| */ |
| isAncestorOfSelected_: function(folder) { |
| - if (!this.selectedId) |
| - return false; |
| - |
| var selectedNode = this.idToNodeMap_[this.selectedId]; |
| return selectedNode.path.startsWith(folder.path); |
| }, |
| @@ -129,36 +128,19 @@ var BookmarksStore = Polymer({ |
| return; |
| if (!this.searchTerm) { |
| - this.fire('selected-folder-changed', this.rootNode.children[0].id); |
| + this.selectFolder_(this.selectedId); |
| } else { |
| chrome.bookmarks.search(this.searchTerm, function(results) { |
| this.anchorIndex_ = null; |
| this.clearSelectedItems_(); |
| this.searchResultSet_ = new Set(); |
| - if (this.selectedId) |
| - this.deselectFolders_(); |
| - |
| + this.deselectFolders_(); |
| this.setupSearchResults_(results); |
| }.bind(this)); |
| } |
| }, |
| - /** @private */ |
| - updateSelectedDisplay_: function() { |
| - // Don't change to the selected display if ID was cleared. |
| - if (!this.selectedId) |
| - return; |
| - |
| - this.clearSelectedItems_(); |
| - this.anchorIndex_ = null; |
| - |
| - var selectedNode = this.idToNodeMap_[this.selectedId]; |
| - this.linkPaths('displayedList', selectedNode.path + '.children'); |
| - this._setDisplayedList( |
| - /** @type {Array<BookmarkTreeNode>} */ (selectedNode.children)); |
| - }, |
| - |
| /** |
| * Remove all descendants of a given node from the map. |
| * @param {string} id |
| @@ -177,6 +159,34 @@ var BookmarksStore = Polymer({ |
| }, |
| /** |
| + * Changes the selected folder to that of the id or else defaults to the |
| + * Bookmarks Bar. |
| + * @param {string} id The id of the folder to be selected. |
| + * @private |
| + */ |
| + selectFolder_: function(id) { |
|
tsergeant
2017/02/08 03:11:10
I think we should make this a public method.
This
|
| + if (!this.idToNodeMap_) |
| + return; |
| + |
| + if (!this.idToNodeMap_[id] || this.idToNodeMap_[id].url) |
| + id = this.rootNode.children[0].id; |
| + |
| + this.deselectFolders_(); |
| + if (this.searchTerm) { |
| + this.selectedId = id; |
| + } else { |
| + var newFolder = this.idToNodeMap_[id]; |
| + this.set(newFolder.path + '.isSelectedFolder', true); |
| + this.selectedId = id; |
| + |
| + // Update the displayed list to the selected folder. |
| + var selectedNode = this.idToNodeMap_[this.selectedId]; |
| + this.linkPaths('displayedList', selectedNode.path + '.children'); |
| + this._setDisplayedList(selectedNode.children); |
| + } |
| + }, |
| + |
| + /** |
| * Remove all selected items in the list. |
| * @private |
| */ |
| @@ -187,7 +197,6 @@ var BookmarksStore = Polymer({ |
| for (var i = 0; i < this.displayedList.length; i++) { |
| if (!this.displayedList[i].isSelectedItem) |
| continue; |
| - |
| this.set('displayedList.#' + i + '.isSelectedItem', false); |
| } |
| }, |
| @@ -290,7 +299,7 @@ var BookmarksStore = Polymer({ |
| // Updates selectedId if the removed node is an ancestor of the current |
| // selected node. |
| if (isAncestor) |
| - this.fire('selected-folder-changed', removeInfo.parentId); |
| + this.selectFolder_(removeInfo.parentId); |
| // Only update the displayedList if the removed node is in the |
| // displayedList. |
| @@ -304,7 +313,7 @@ var BookmarksStore = Polymer({ |
| this.updateSearchDisplay_(); |
| } else { |
| if (!isAncestor) |
| - this.fire('selected-folder-changed', this.selectedId); |
| + this.selectFolder_(this.selectedId); |
| this._setDisplayedList(parentNode.children); |
| } |
| @@ -344,22 +353,10 @@ var BookmarksStore = Polymer({ |
| * @private |
| */ |
| onSelectedFolderChanged_: function(e) { |
| - if (this.searchTerm) |
| + if (/** @type {boolean} */ (e.detail.clearSearch)) |
| this.searchTerm = ''; |
| - // Deselect the old folder if defined. |
| - if (this.selectedId && this.idToNodeMap_[this.selectedId]) |
| - this.set( |
| - this.idToNodeMap_[this.selectedId].path + '.isSelectedFolder', false); |
| - |
| - // Check if the selected id is that of a defined folder. |
| - var id = /** @type {string} */ (e.detail); |
| - if (!this.idToNodeMap_[id] || this.idToNodeMap_[id].url) |
| - id = this.rootNode.children[0].id; |
| - |
| - var newFolder = this.idToNodeMap_[id]; |
| - this.set(newFolder.path + '.isSelectedFolder', true); |
| - this.selectedId = id; |
| + this.selectFolder_(/** @type {string} */ (e.detail.id)); |
| }, |
| /** |
| @@ -371,7 +368,7 @@ var BookmarksStore = Polymer({ |
| var folder = this.idToNodeMap_[e.detail.id]; |
| this.set(folder.path + '.isOpen', e.detail.open); |
| if (!folder.isOpen && this.isAncestorOfSelected_(folder)) |
| - this.fire('selected-folder-changed', folder.id); |
| + this.selectFolder_(folder.id); |
| }, |
| /** |