| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 /** | 5 /** |
| 6 * @fileoverview Module for functions which produce action objects. These are | 6 * @fileoverview Module for functions which produce action objects. These are |
| 7 * listed in one place to document available actions and their parameters. | 7 * listed in one place to document available actions and their parameters. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 cr.define('bookmarks.actions', function() { | 10 cr.define('bookmarks.actions', function() { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 /** | 142 /** |
| 143 * @param {string} id | 143 * @param {string} id |
| 144 * @param {boolean} add | 144 * @param {boolean} add |
| 145 * @param {boolean} range | 145 * @param {boolean} range |
| 146 * @param {BookmarksPageState} state | 146 * @param {BookmarksPageState} state |
| 147 * @return {!Action} | 147 * @return {!Action} |
| 148 */ | 148 */ |
| 149 function selectItem(id, add, range, state) { | 149 function selectItem(id, add, range, state) { |
| 150 var anchor = state.selection.anchor; | 150 var anchor = state.selection.anchor; |
| 151 var toSelect = []; | 151 var toSelect = []; |
| 152 var newAnchor = id; |
| 152 | 153 |
| 153 // TODO(tsergeant): Make it possible to deselect items by ctrl-clicking them | 154 // TODO(tsergeant): Make it possible to deselect items by ctrl-clicking them |
| 154 // again. | 155 // again. |
| 155 if (range && anchor) { | 156 if (range && anchor) { |
| 156 var displayedList = bookmarks.util.getDisplayedList(state); | 157 var displayedList = bookmarks.util.getDisplayedList(state); |
| 157 var selectedIndex = displayedList.indexOf(id); | 158 var selectedIndex = displayedList.indexOf(id); |
| 158 assert(selectedIndex != -1); | 159 assert(selectedIndex != -1); |
| 159 var anchorIndex = displayedList.indexOf(anchor); | 160 var anchorIndex = displayedList.indexOf(anchor); |
| 160 if (anchorIndex == -1) | 161 if (anchorIndex == -1) |
| 161 anchorIndex = selectedIndex; | 162 anchorIndex = selectedIndex; |
| 162 | 163 |
| 164 // When performing a range selection, don't change the anchor from what |
| 165 // was used in this selection. |
| 166 newAnchor = displayedList[anchorIndex]; |
| 167 |
| 163 var startIndex = Math.min(anchorIndex, selectedIndex); | 168 var startIndex = Math.min(anchorIndex, selectedIndex); |
| 164 var endIndex = Math.max(anchorIndex, selectedIndex); | 169 var endIndex = Math.max(anchorIndex, selectedIndex); |
| 165 | 170 |
| 166 for (var i = startIndex; i <= endIndex; i++) | 171 for (var i = startIndex; i <= endIndex; i++) |
| 167 toSelect.push(displayedList[i]); | 172 toSelect.push(displayedList[i]); |
| 168 } else { | 173 } else { |
| 169 toSelect.push(id); | 174 toSelect.push(id); |
| 170 } | 175 } |
| 171 | 176 |
| 172 return { | 177 return { |
| 173 name: 'select-items', | 178 name: 'select-items', |
| 174 add: add, | 179 add: add, |
| 175 anchor: id, | 180 anchor: newAnchor, |
| 176 items: toSelect, | 181 items: toSelect, |
| 177 }; | 182 }; |
| 178 } | 183 } |
| 179 | 184 |
| 180 /** | 185 /** |
| 181 * @param {string} term | 186 * @param {string} term |
| 182 * @return {!Action} | 187 * @return {!Action} |
| 183 */ | 188 */ |
| 184 function setSearchTerm(term) { | 189 function setSearchTerm(term) { |
| 185 if (!term) | 190 if (!term) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 211 moveBookmark: moveBookmark, | 216 moveBookmark: moveBookmark, |
| 212 refreshNodes: refreshNodes, | 217 refreshNodes: refreshNodes, |
| 213 removeBookmark: removeBookmark, | 218 removeBookmark: removeBookmark, |
| 214 reorderChildren: reorderChildren, | 219 reorderChildren: reorderChildren, |
| 215 selectFolder: selectFolder, | 220 selectFolder: selectFolder, |
| 216 selectItem: selectItem, | 221 selectItem: selectItem, |
| 217 setSearchResults: setSearchResults, | 222 setSearchResults: setSearchResults, |
| 218 setSearchTerm: setSearchTerm, | 223 setSearchTerm: setSearchTerm, |
| 219 }; | 224 }; |
| 220 }); | 225 }); |
| OLD | NEW |