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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 | 134 |
135 /** @return {!Action} */ | 135 /** @return {!Action} */ |
136 function deselectItems() { | 136 function deselectItems() { |
137 return { | 137 return { |
138 name: 'deselect-items', | 138 name: 'deselect-items', |
139 }; | 139 }; |
140 } | 140 } |
141 | 141 |
142 /** | 142 /** |
143 * @param {string} id | 143 * @param {string} id |
144 * @param {boolean} add | |
145 * @param {boolean} range | |
146 * @param {BookmarksPageState} state | 144 * @param {BookmarksPageState} state |
145 * @param {{add: boolean, | |
tsergeant
2017/05/18 23:13:37
`add` is a confusing name now, since if `add` is t
calamity
2017/05/19 06:46:56
#+1
| |
146 range: boolean, | |
147 toggle: boolean, | |
148 updateAnchor: boolean}} config | |
tsergeant
2017/05/18 23:13:37
Every call site at the moment has `updateAnchor ==
calamity
2017/05/19 06:46:56
I thought I'd need special config for mouse vs key
| |
147 * @return {!Action} | 149 * @return {!Action} |
148 */ | 150 */ |
149 function selectItem(id, add, range, state) { | 151 function selectItem(id, state, config) { |
152 assert(!(config.range && config.toggle)); | |
tsergeant
2017/05/18 23:13:37
toggle is a no-op unless add is true, so do you al
calamity
2017/05/19 06:46:56
Done.
| |
153 | |
150 var anchor = state.selection.anchor; | 154 var anchor = state.selection.anchor; |
151 var toSelect = []; | 155 var toSelect = []; |
152 | 156 |
153 // TODO(tsergeant): Make it possible to deselect items by ctrl-clicking them | 157 if (config.range && anchor) { |
154 // again. | |
155 if (range && anchor) { | |
156 var displayedList = bookmarks.util.getDisplayedList(state); | 158 var displayedList = bookmarks.util.getDisplayedList(state); |
157 var selectedIndex = displayedList.indexOf(id); | 159 var selectedIndex = displayedList.indexOf(id); |
158 assert(selectedIndex != -1); | 160 assert(selectedIndex != -1); |
159 var anchorIndex = displayedList.indexOf(anchor); | 161 var anchorIndex = displayedList.indexOf(anchor); |
160 if (anchorIndex == -1) | 162 if (anchorIndex == -1) |
161 anchorIndex = selectedIndex; | 163 anchorIndex = selectedIndex; |
162 | 164 |
163 var startIndex = Math.min(anchorIndex, selectedIndex); | 165 var startIndex = Math.min(anchorIndex, selectedIndex); |
164 var endIndex = Math.max(anchorIndex, selectedIndex); | 166 var endIndex = Math.max(anchorIndex, selectedIndex); |
165 | 167 |
166 for (var i = startIndex; i <= endIndex; i++) | 168 for (var i = startIndex; i <= endIndex; i++) |
167 toSelect.push(displayedList[i]); | 169 toSelect.push(displayedList[i]); |
168 } else { | 170 } else { |
169 toSelect.push(id); | 171 toSelect.push(id); |
170 } | 172 } |
171 | 173 |
172 return { | 174 return { |
173 name: 'select-items', | 175 name: 'select-items', |
174 add: add, | 176 add: config.add, |
175 anchor: id, | 177 toggle: config.toggle, |
178 anchor: config.updateAnchor ? id : anchor, | |
176 items: toSelect, | 179 items: toSelect, |
177 }; | 180 }; |
178 } | 181 } |
179 | 182 |
180 /** | 183 /** |
181 * @param {string} term | 184 * @param {string} term |
182 * @return {!Action} | 185 * @return {!Action} |
183 */ | 186 */ |
184 function setSearchTerm(term) { | 187 function setSearchTerm(term) { |
185 if (!term) | 188 if (!term) |
(...skipping 25 matching lines...) Expand all Loading... | |
211 moveBookmark: moveBookmark, | 214 moveBookmark: moveBookmark, |
212 refreshNodes: refreshNodes, | 215 refreshNodes: refreshNodes, |
213 removeBookmark: removeBookmark, | 216 removeBookmark: removeBookmark, |
214 reorderChildren: reorderChildren, | 217 reorderChildren: reorderChildren, |
215 selectFolder: selectFolder, | 218 selectFolder: selectFolder, |
216 selectItem: selectItem, | 219 selectItem: selectItem, |
217 setSearchResults: setSearchResults, | 220 setSearchResults: setSearchResults, |
218 setSearchTerm: setSearchTerm, | 221 setSearchTerm: setSearchTerm, |
219 }; | 222 }; |
220 }); | 223 }); |
OLD | NEW |