Index: chrome/browser/resources/options/inline_editable_list.js |
diff --git a/chrome/browser/resources/options/inline_editable_list.js b/chrome/browser/resources/options/inline_editable_list.js |
index 05c63eac45d43b8571cd33228386b05ebea4be12..3c744bfeaf8c054eed41066d92b87e71ba0bd3b7 100644 |
--- a/chrome/browser/resources/options/inline_editable_list.js |
+++ b/chrome/browser/resources/options/inline_editable_list.js |
@@ -85,7 +85,8 @@ cr.define('options', function() { |
/** @override */ |
selectionChanged: function() { |
- this.updateEditState(); |
+ if (!this.parentNode.changeEventsDisabled_) |
James Hawkins
2015/01/15 16:10:44
An object should not be accessing private data of
Dan Beam
2015/01/21 18:18:07
[closure's] @private is file-level
|
+ this.updateEditState(); |
}, |
/** |
@@ -578,6 +579,15 @@ cr.define('options', function() { |
__proto__: DeletableItemList.prototype, |
/** |
+ * Whether list change events are disabled. |
+ * Used to modify the list without processing selection change and lead |
+ * change events. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ changeEventsDisabled_: false, |
+ |
+ /** |
* Focuses the input element of the placeholder if true. |
* @type {boolean} |
* @private |
@@ -626,6 +636,9 @@ cr.define('options', function() { |
/** @override */ |
handleLeadChange: function(e) { |
Dan Beam
2015/01/21 18:18:07
where is this subscribed? can we just turn off no
|
+ if (this.changeEventsDisabled_) |
+ return; |
+ |
DeletableItemList.prototype.handleLeadChange.call(this, e); |
var focusedColumnIndex = -1; |
@@ -665,6 +678,53 @@ cr.define('options', function() { |
}, |
/** |
+ * Execute |callback| with list change events disabled. Selection change and |
+ * lead change events will not be processed. |
+ * @param {!Function} callback The function to execute. |
+ * @protected |
+ */ |
+ executeWithChangeEventsDisabled: function(callback) { |
+ this.changeEventsDisabled_ = true; |
+ callback(); |
+ this.changeEventsDisabled_ = false; |
+ }, |
+ |
+ /** |
+ * Set the selected index without changing the focused element on the page. |
+ * Used to change the selected index when the list doesn't have focus (and |
+ * doesn't want to take focus). |
+ * @param {number} index The index to select. |
+ */ |
+ setSelectedIndexWithoutFocusing: function(index) { |
+ // Remove focusability from old item. |
+ var oldItem = this.getListItemByIndex(this.selectionModel.leadIndex) || |
+ this.getInitialFocusableItem(); |
+ if (oldItem) { |
+ oldItem.setEditableValuesFocusable(false); |
+ oldItem.setStaticValuesFocusable(false); |
+ oldItem.setCloseButtonFocusable(false); |
+ oldItem.lead = false; |
+ } |
+ |
+ // Select the new item. |
+ this.executeWithChangeEventsDisabled(function() { |
+ this.selectionModel.selectedIndex = index; |
+ }.bind(this)); |
+ |
+ // Add focusability to new item. |
+ var newItem = this.getListItemByIndex(index); |
+ if (newItem) { |
+ if (newItem.isPlaceholder) |
+ newItem.setEditableValuesFocusable(true); |
+ else |
+ newItem.setStaticValuesFocusable(true); |
+ |
+ newItem.setCloseButtonFocusable(true); |
+ newItem.lead = true; |
+ } |
+ }, |
+ |
+ /** |
* Focus the placeholder's first input field. |
* Should only be called immediately after the list has been repopulated. |
*/ |