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

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

Issue 2741393002: MD Bookmarks: Implement item selection in new data flow system (Closed)
Patch Set: Review comments Created 3 years, 9 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/browser/resources/md_bookmarks/item.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 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 /** @return {!Action} */ 75 /** @return {!Action} */
76 function clearSearch() { 76 function clearSearch() {
77 return { 77 return {
78 name: 'clear-search', 78 name: 'clear-search',
79 }; 79 };
80 } 80 }
81 81
82 /** 82 /**
83 * @param {string} id
84 * @param {boolean} add
85 * @param {boolean} range
86 * @param {BookmarksPageState} state
87 * @return {!Action}
88 */
89 function selectItem(id, add, range, state) {
90 var anchor = state.selection.anchor;
91 var toSelect = [];
92
93 // TODO(tsergeant): Make it possible to deselect items by ctrl-clicking them
94 // again.
95 if (range && anchor) {
96 var displayedList = bookmarks.util.getDisplayedList(state);
97 var selectedIndex = displayedList.indexOf(id);
98 assert(selectedIndex != -1);
99 var anchorIndex = displayedList.indexOf(anchor);
100 if (anchorIndex == -1)
101 anchorIndex = selectedIndex;
102
103 var startIndex = Math.min(anchorIndex, selectedIndex);
104 var endIndex = Math.max(anchorIndex, selectedIndex);
105
106 for (var i = startIndex; i <= endIndex; i++)
107 toSelect.push(displayedList[i]);
108 } else {
109 toSelect.push(id);
110 }
111
112 return {
113 name: 'select-items',
114 add: add,
115 anchor: id,
116 items: toSelect,
117 };
118 }
119
120 /**
83 * @param {string} term 121 * @param {string} term
84 * @return {!Action} 122 * @return {!Action}
85 */ 123 */
86 function setSearchTerm(term) { 124 function setSearchTerm(term) {
87 if (!term) 125 if (!term)
88 return clearSearch(); 126 return clearSearch();
89 127
90 return { 128 return {
91 name: 'start-search', 129 name: 'start-search',
92 term: term, 130 term: term,
(...skipping 11 matching lines...) Expand all
104 }; 142 };
105 } 143 }
106 144
107 return { 145 return {
108 changeFolderOpen: changeFolderOpen, 146 changeFolderOpen: changeFolderOpen,
109 clearSearch: clearSearch, 147 clearSearch: clearSearch,
110 editBookmark: editBookmark, 148 editBookmark: editBookmark,
111 refreshNodes: refreshNodes, 149 refreshNodes: refreshNodes,
112 removeBookmark: removeBookmark, 150 removeBookmark: removeBookmark,
113 selectFolder: selectFolder, 151 selectFolder: selectFolder,
152 selectItem: selectItem,
114 setSearchResults: setSearchResults, 153 setSearchResults: setSearchResults,
115 setSearchTerm: setSearchTerm, 154 setSearchTerm: setSearchTerm,
116 }; 155 };
117 }); 156 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_bookmarks/item.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698