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

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

Issue 2812493002: MD Bookmarks: Restore any previously selected folder when clearing search (Closed)
Patch Set: Fix comment Created 3 years, 8 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
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 of functions which produce a new page state in response 6 * @fileoverview Module of functions which produce a new page state in response
7 * to an action. Reducers (in the same sense as Array.prototype.reduce) must be 7 * to an action. Reducers (in the same sense as Array.prototype.reduce) must be
8 * pure functions: they must not modify existing state objects, or make any API 8 * pure functions: they must not modify existing state objects, or make any API
9 * calls. 9 * calls.
10 */ 10 */
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // Work upwards through the tree from child. 297 // Work upwards through the tree from child.
298 while (currentId) { 298 while (currentId) {
299 if (currentId == ancestorId) 299 if (currentId == ancestorId)
300 return true; 300 return true;
301 currentId = nodes[currentId].parentId; 301 currentId = nodes[currentId].parentId;
302 } 302 }
303 return false; 303 return false;
304 }; 304 };
305 305
306 /** 306 /**
307 * @param {?string} selectedFolder 307 * @param {string} selectedFolder
308 * @param {Action} action 308 * @param {Action} action
309 * @param {NodeList} nodes 309 * @param {NodeList} nodes
310 * @return {?string} 310 * @return {string}
311 */ 311 */
312 SelectedFolderState.updateSelectedFolder = function( 312 SelectedFolderState.updateSelectedFolder = function(
313 selectedFolder, action, nodes) { 313 selectedFolder, action, nodes) {
314 switch (action.name) { 314 switch (action.name) {
315 case 'select-folder': 315 case 'select-folder':
316 // TODO(tsergeant): It should not be possible to select a non-folder. 316 // TODO(tsergeant): It should not be possible to select a non-folder.
317 return action.id; 317 return action.id;
318 case 'change-folder-open': 318 case 'change-folder-open':
319 // When hiding the selected folder by closing its ancestor, select 319 // When hiding the selected folder by closing its ancestor, select
320 // that ancestor instead. 320 // that ancestor instead.
321 if (!action.open && selectedFolder && 321 if (!action.open && selectedFolder &&
322 SelectedFolderState.isAncestorOf( 322 SelectedFolderState.isAncestorOf(
323 nodes, action.id, selectedFolder)) { 323 nodes, action.id, selectedFolder)) {
324 return action.id; 324 return action.id;
325 } 325 }
326 return selectedFolder; 326 return selectedFolder;
327 case 'finish-search':
328 return null;
329 case 'clear-search':
330 // TODO(tsergeant): Return to the folder that was selected before the
331 // search.
332 return nodes[ROOT_NODE_ID].children[0];
333 case 'remove-bookmark': 327 case 'remove-bookmark':
334 // When deleting the selected folder (or its ancestor), select the 328 // When deleting the selected folder (or its ancestor), select the
335 // parent of the deleted node. 329 // parent of the deleted node.
336 if (selectedFolder && 330 if (selectedFolder &&
337 SelectedFolderState.isAncestorOf(nodes, action.id, selectedFolder)) 331 SelectedFolderState.isAncestorOf(nodes, action.id, selectedFolder))
338 return assert(nodes[action.id].parentId); 332 return assert(nodes[action.id].parentId);
339 return selectedFolder; 333 return selectedFolder;
340 default: 334 default:
341 return selectedFolder; 335 return selectedFolder;
342 } 336 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 423
430 return { 424 return {
431 reduceAction: reduceAction, 425 reduceAction: reduceAction,
432 ClosedFolderState: ClosedFolderState, 426 ClosedFolderState: ClosedFolderState,
433 NodeState: NodeState, 427 NodeState: NodeState,
434 SearchState: SearchState, 428 SearchState: SearchState,
435 SelectedFolderState: SelectedFolderState, 429 SelectedFolderState: SelectedFolderState,
436 SelectionState: SelectionState, 430 SelectionState: SelectionState,
437 }; 431 };
438 }); 432 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/folder_node.js ('k') | chrome/browser/resources/md_bookmarks/types.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698