| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 Polymer({ | 5 Polymer({ |
| 6 is: 'bookmarks-list', | 6 is: 'bookmarks-list', |
| 7 | 7 |
| 8 behaviors: [ | 8 behaviors: [ |
| 9 bookmarks.StoreClient, | 9 bookmarks.StoreClient, |
| 10 ], | 10 ], |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 /** | 123 /** |
| 124 * @param {KeyboardEvent} e | 124 * @param {KeyboardEvent} e |
| 125 * @private | 125 * @private |
| 126 */ | 126 */ |
| 127 onItemKeydown_: function(e) { | 127 onItemKeydown_: function(e) { |
| 128 var handled = true; | 128 var handled = true; |
| 129 var list = this.$.bookmarksCard; | 129 var list = this.$.bookmarksCard; |
| 130 var focusMoved = false; | 130 var focusMoved = false; |
| 131 var focusedIndex = | 131 var focusedIndex = |
| 132 this.getIndexForItemElement_(/** @type {HTMLElement} */ (e.target)); | 132 this.getIndexForItemElement_(/** @type {HTMLElement} */ (e.target)); |
| 133 var oldFocusedIndex = focusedIndex; |
| 133 if (e.key == 'ArrowUp') { | 134 if (e.key == 'ArrowUp') { |
| 134 focusedIndex--; | 135 focusedIndex--; |
| 135 focusMoved = true; | 136 focusMoved = true; |
| 136 } else if (e.key == 'ArrowDown') { | 137 } else if (e.key == 'ArrowDown') { |
| 137 focusedIndex++; | 138 focusedIndex++; |
| 138 focusMoved = true; | 139 focusMoved = true; |
| 139 e.preventDefault(); | 140 e.preventDefault(); |
| 140 } else if (e.key == 'Home') { | 141 } else if (e.key == 'Home') { |
| 141 focusedIndex = 0; | 142 focusedIndex = 0; |
| 142 focusMoved = true; | 143 focusMoved = true; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 159 } | 160 } |
| 160 | 161 |
| 161 if (focusMoved) { | 162 if (focusMoved) { |
| 162 focusedIndex = Math.min(list.items.length - 1, Math.max(0, focusedIndex)); | 163 focusedIndex = Math.min(list.items.length - 1, Math.max(0, focusedIndex)); |
| 163 list.focusItem(focusedIndex); | 164 list.focusItem(focusedIndex); |
| 164 | 165 |
| 165 if (e.ctrlKey && !e.shiftKey) { | 166 if (e.ctrlKey && !e.shiftKey) { |
| 166 this.dispatch( | 167 this.dispatch( |
| 167 bookmarks.actions.updateAnchor(this.displayedIds_[focusedIndex])); | 168 bookmarks.actions.updateAnchor(this.displayedIds_[focusedIndex])); |
| 168 } else { | 169 } else { |
| 170 // If shift-selecting with no anchor, use the old focus index. |
| 171 if (e.shiftKey && this.getState().selection.anchor == null) { |
| 172 this.dispatch(bookmarks.actions.updateAnchor( |
| 173 this.displayedIds_[oldFocusedIndex])); |
| 174 } |
| 175 |
| 169 // If the focus moved from something other than a Ctrl + move event, | 176 // If the focus moved from something other than a Ctrl + move event, |
| 170 // update the selection. | 177 // update the selection. |
| 171 var config = { | 178 var config = { |
| 172 clear: !e.ctrlKey, | 179 clear: !e.ctrlKey, |
| 173 range: e.shiftKey, | 180 range: e.shiftKey, |
| 174 toggle: false, | 181 toggle: false, |
| 175 }; | 182 }; |
| 176 | 183 |
| 177 this.dispatch(bookmarks.actions.selectItem( | 184 this.dispatch(bookmarks.actions.selectItem( |
| 178 this.displayedIds_[focusedIndex], this.getState(), config)); | 185 this.displayedIds_[focusedIndex], this.getState(), config)); |
| 179 } | 186 } |
| 180 } | 187 } |
| 181 | 188 |
| 182 if (handled) | 189 if (handled) |
| 183 e.stopPropagation(); | 190 e.stopPropagation(); |
| 184 }, | 191 }, |
| 185 }); | 192 }); |
| OLD | NEW |