Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: chrome/browser/resources/md_bookmarks/list.js

Issue 2924673003: [MD Bookmarks] Make shift-selection behave well with no anchor. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/webui/md_bookmarks/md_bookmarks_focus_test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 });
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webui/md_bookmarks/md_bookmarks_focus_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698