diff options
3 files changed, 25 insertions, 14 deletions
diff --git a/chrome/browser/resources/options/autofill_options.js b/chrome/browser/resources/options/autofill_options.js index bdc4ab7..2e129bb 100644 --- a/chrome/browser/resources/options/autofill_options.js +++ b/chrome/browser/resources/options/autofill_options.js @@ -5,7 +5,6 @@ cr.define('options', function() { const OptionsPage = options.OptionsPage; const ArrayDataModel = cr.ui.ArrayDataModel; - const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; ///////////////////////////////////////////////////////////////////////////// // AutoFillOptions class: @@ -65,7 +64,6 @@ cr.define('options', function() { createAddressList_: function() { this.addressList_ = $('address-list'); options.autoFillOptions.AutoFillAddressList.decorate(this.addressList_); - this.addressList_.selectionModel = new ListSingleSelectionModel; this.addressList_.autoExpands = true; }, @@ -77,7 +75,6 @@ cr.define('options', function() { this.creditCardList_ = $('creditcard-list'); options.autoFillOptions.AutoFillCreditCardList.decorate( this.creditCardList_); - this.creditCardList_.selectionModel = new ListSingleSelectionModel; this.creditCardList_.autoExpands = true; }, diff --git a/chrome/browser/resources/options/deletable_item_list.js b/chrome/browser/resources/options/deletable_item_list.js index 6781c50..5d5b35b 100644 --- a/chrome/browser/resources/options/deletable_item_list.js +++ b/chrome/browser/resources/options/deletable_item_list.js @@ -61,7 +61,9 @@ cr.define('options', function() { this.closeButtonElement_ = this.ownerDocument.createElement('button'); this.closeButtonElement_.className = 'close-button'; this.closeButtonElement_.addEventListener('mousedown', - this.handleMouseDownOnClose_); + this.handleMouseDownUpOnClose_); + this.closeButtonElement_.addEventListener('mouseup', + this.handleMouseDownUpOnClose_); this.appendChild(this.closeButtonElement_); }, @@ -86,11 +88,11 @@ cr.define('options', function() { /** * Don't let the list have a crack at the event. We don't want clicking the - * close button to select the list. - * @param {Event} e The mouse down event object. + * close button to change the selection of the list. + * @param {Event} e The mouse down/up event object. * @private */ - handleMouseDownOnClose_: function(e) { + handleMouseDownUpOnClose_: function(e) { if (!e.target.disabled) e.stopPropagation(); }, @@ -119,8 +121,20 @@ cr.define('options', function() { var target = e.target; if (target.className == 'close-button') { var listItem = this.getListItemAncestor(target); - if (listItem) - this.deleteItemAtIndex(this.getIndexOfListItem(listItem)); + var selected = this.selectionModel.selectedIndexes; + + // Check if the list item that contains the close button being clicked + // is not in the list of selected items. Only delete this item in that + // case. + var idx = this.getIndexOfListItem(listItem); + if (selected.indexOf(idx) == -1) { + this.deleteItemAtIndex(idx); + } else { + // Reverse through the list of selected indexes to maintain the + // correct index values after deletion. + for (var j = selected.length - 1; j >= 0; j--) + this.deleteItemAtIndex(selected[j]); + } } }, diff --git a/chrome/browser/resources/shared/js/cr/ui/list_selection_controller.js b/chrome/browser/resources/shared/js/cr/ui/list_selection_controller.js index 72aada6..fa1f3c2 100644 --- a/chrome/browser/resources/shared/js/cr/ui/list_selection_controller.js +++ b/chrome/browser/resources/shared/js/cr/ui/list_selection_controller.js @@ -141,13 +141,13 @@ cr.define('cr.ui', function() { (e.ctrlKey && !e.shiftKey))) { // Selection is handled at mouseUp on windows/linux, mouseDown on mac. if (cr.isMac? isDown : !isDown) { - // toggle the current one and make it anchor index + // Toggle the current one and make it anchor index. sm.setIndexSelected(index, !sm.getIndexSelected(index)); sm.leadIndex = index; sm.anchorIndex = index; } } else if (e.shiftKey && anchorIndex != -1 && anchorIndex != index) { - // Shift is done in mousedown + // Shift is done in mousedown. if (isDown) { sm.unselectAll(); sm.leadIndex = index; @@ -157,7 +157,7 @@ cr.define('cr.ui', function() { sm.setIndexSelected(index, true); } } else { - // Right click for a context menu need to not clear the selection. + // Right click for a context menu needs to not clear the selection. var isRightClick = e.button == 2; // If the index is selected this is handled in mouseup. @@ -176,7 +176,7 @@ cr.define('cr.ui', function() { }, /** - * Called by the view when it recieves a keydown event. + * Called by the view when it receives a keydown event. * @param {Event} e The keydown event. */ handleKeyDown: function(e) { @@ -246,7 +246,7 @@ cr.define('cr.ui', function() { sm.selectRange(anchorIndex, newIndex); } } else if (e.ctrlKey && !cr.isMac) { - // Setting the lead index is done above + // Setting the lead index is done above. // Mac does not allow you to change the lead. } else { if (sm.multiple) |