Chromium Code Reviews| Index: ui/file_manager/file_manager/foreground/js/ui/navigation_list.js |
| diff --git a/ui/file_manager/file_manager/foreground/js/ui/navigation_list.js b/ui/file_manager/file_manager/foreground/js/ui/navigation_list.js |
| index 4368c9bef67dde49ab94587971f2ae3dc2874e9e..22bad9adcf500c7bdf57a20755cc07cbde6d8b25 100644 |
| --- a/ui/file_manager/file_manager/foreground/js/ui/navigation_list.js |
| +++ b/ui/file_manager/file_manager/foreground/js/ui/navigation_list.js |
| @@ -201,6 +201,9 @@ NavigationList.prototype.decorate = function(volumeManager, directoryModel) { |
| this.scrollBar_ = new ScrollBar(); |
| this.scrollBar_.initialize(this.parentNode, this); |
| + // Keeps track of selected model item to detect if it is changed actually. |
| + this.currentModelItem_ = null; |
| + |
| // Overriding default role 'list' set by cr.ui.List.decorate() to 'listbox' |
| // role for better accessibility on ChromeOS. |
| this.setAttribute('role', 'listbox'); |
| @@ -287,6 +290,7 @@ NavigationList.prototype.selectByIndex = function(index) { |
| if (index < 0 || index > this.dataModel.length - 1) |
| return false; |
| + this.selectionModel.selectedIndex = index; |
| this.activateModelItem_(this.dataModel.item(index)); |
| return true; |
| }; |
| @@ -299,16 +303,11 @@ NavigationList.prototype.selectByIndex = function(index) { |
| */ |
| NavigationList.prototype.activateModelItem_ = function(modelItem) { |
| var onEntryResolved = function(entry) { |
| - // If the root item of active directory was same as newly activated |
| - // root item, keep the active directory as it was. |
| - var currentDir = this.directoryModel_.getCurrentDirEntry(); |
| - if (util.isSameEntry(entry, currentDir) || |
| - util.isDescendantEntry(entry, currentDir)) { |
| - return; |
| + // Change directory to the model item's root directory if needed. |
|
yoshiki
2014/06/05 15:11:23
nit: Changes
fukino
2014/06/06 02:15:24
Done.
|
| + if (!util.isSameEntry(this.directoryModel_.getCurrentDirEntry(), entry)) { |
| + metrics.recordUserAction('FolderShortcut.Navigate'); |
| + this.directoryModel_.changeDirectoryEntry(entry); |
| } |
| - |
| - metrics.recordUserAction('FolderShortcut.Navigate'); |
| - this.directoryModel_.changeDirectoryEntry(entry); |
| }.bind(this); |
| if (modelItem.isVolume) { |
| @@ -350,12 +349,25 @@ NavigationList.prototype.onBeforeSelectionChange_ = function(event) { |
| * @private |
| */ |
| NavigationList.prototype.onSelectionChange_ = function(event) { |
| + var index = this.selectionModel.selectedIndex; |
| + if (index < 0 || index > this.dataModel.length - 1) |
| + return; |
| + |
| + // If the selected model item is not changed actually, we don't change the |
| + // current directory even if the selected index is changed. |
| + var modelItem = this.dataModel.item(index); |
| + if (modelItem === this.currentModelItem_) |
| + return; |
| + |
| + // Remember the selected model item. |
|
yoshiki
2014/06/05 15:11:23
nit: remembers
fukino
2014/06/06 02:15:25
Done.
|
| + this.currentModelItem_ = modelItem; |
| + |
| // This handler is invoked even when the navigation list itself changes the |
| // selection. In such case, we shouldn't handle the event. |
| if (this.dontHandleSelectionEvent_) |
| return; |
| - this.selectByIndex(this.selectionModel.selectedIndex); |
| + this.activateModelItem_(modelItem); |
| }; |
| /** |