Commit bdcfd1d3 authored by tsergeant's avatar tsergeant Committed by Commit Bot

MD Bookmarks: Deselect items when they are moved to a new folder

This fixes an issue where the multi-select toolbar would still appear
after the selected items had been moved to a different folder.

BUG=697706
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2946883002
Cr-Commit-Position: refs/heads/master@{#481749}
parent 2be84dd0
...@@ -55,7 +55,7 @@ cr.define('bookmarks', function() { ...@@ -55,7 +55,7 @@ cr.define('bookmarks', function() {
* @param {!Set<string>} deleted * @param {!Set<string>} deleted
* @return SelectionState * @return SelectionState
*/ */
SelectionState.deselectDeletedItems = function(selectionState, deleted) { SelectionState.deselectItems = function(selectionState, deleted) {
return /** @type {SelectionState} */ Object.assign({}, selectionState, { return /** @type {SelectionState} */ Object.assign({}, selectionState, {
items: bookmarks.util.removeIdsFromSet(selectionState.items, deleted), items: bookmarks.util.removeIdsFromSet(selectionState.items, deleted),
anchor: !selectionState.anchor || deleted.has(selectionState.anchor) ? anchor: !selectionState.anchor || deleted.has(selectionState.anchor) ?
...@@ -90,8 +90,16 @@ cr.define('bookmarks', function() { ...@@ -90,8 +90,16 @@ cr.define('bookmarks', function() {
case 'select-items': case 'select-items':
return SelectionState.selectItems(selection, action); return SelectionState.selectItems(selection, action);
case 'remove-bookmark': case 'remove-bookmark':
return SelectionState.deselectDeletedItems( return SelectionState.deselectItems(selection, action.descendants);
selection, action.descendants); case 'move-bookmark':
// Deselect items when they are moved to another folder, since they will
// no longer be visible on screen (for simplicity, ignores items visible
// in search results).
if (action.parentId != action.oldParentId &&
selection.items.has(action.id)) {
return SelectionState.deselectItems(selection, new Set([action.id]));
}
return selection;
case 'update-anchor': case 'update-anchor':
return SelectionState.updateAnchor(selection, action); return SelectionState.updateAnchor(selection, action);
default: default:
......
...@@ -106,16 +106,16 @@ suite('selection state', function() { ...@@ -106,16 +106,16 @@ suite('selection state', function() {
}); });
test('deselects items when they are deleted', function() { test('deselects items when they are deleted', function() {
var nodeMap = testTree(createFolder('0', [ var nodeMap = testTree(
createFolder( createFolder(
'1', '1',
[ [
createItem('2'), createItem('2'),
createItem('3'), createItem('3'),
createItem('4'), createItem('4'),
]), ]),
createItem('5'), createItem('5'),
])); );
action = select(['2', '4', '5'], '4', true, false); action = select(['2', '4', '5'], '4', true, false);
selection = bookmarks.SelectionState.updateSelection(selection, action); selection = bookmarks.SelectionState.updateSelection(selection, action);
...@@ -126,6 +126,24 @@ suite('selection state', function() { ...@@ -126,6 +126,24 @@ suite('selection state', function() {
assertDeepEquals(['5'], normalizeSet(selection.items)); assertDeepEquals(['5'], normalizeSet(selection.items));
assertEquals(null, selection.anchor); assertEquals(null, selection.anchor);
}); });
test('deselects items when they are moved to a different folder', function() {
var nodeMap = testTree(
createFolder('1', []),
createItem('2'),
createItem('3'),
);
action = select(['2', '3'], '2', true, false);
selection = bookmarks.SelectionState.updateSelection(selection, action);
// Move item '2' from the 1st item in '0' to the 0th item in '1'.
action = bookmarks.actions.moveBookmark('2', '1', 0, '0', 1);
selection = bookmarks.SelectionState.updateSelection(selection, action);
assertDeepEquals(['3'], normalizeSet(selection.items));
assertEquals(null, selection.anchor);
});
}); });
suite('closed folder state', function() { suite('closed folder state', function() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment