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

Unified Diff: third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js

Issue 2428823002: DevTools: properly restore selected DOMNode in Elements panel. (Closed)
Patch Set: test Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js b/third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js
index 3686992e756f08f1dacd49923786a4e897233559..72dde7ec6ee865e92c9747e62bf6e1720fdbccb5 100644
--- a/third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js
+++ b/third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js
@@ -329,9 +329,6 @@ WebInspector.ElementsPanel.prototype = {
this._treeOutlines[i].selectDOMNode(null);
}
- if (!selectedNode && this._lastValidSelectedNode)
- this._selectedPathOnReset = this._lastValidSelectedNode.path();
-
this._breadcrumbs.setSelectedNode(selectedNode);
WebInspector.context.setFlavor(WebInspector.DOMNode, selectedNode);
@@ -339,7 +336,10 @@ WebInspector.ElementsPanel.prototype = {
if (!selectedNode)
return;
selectedNode.setAsInspectedNode();
- this._lastValidSelectedNode = selectedNode;
+ if (!this._isSettingDefaultSelection) {
+ this._selectedNodeOnReset = selectedNode;
+ this._hasNonDefaultSelectedNode = true;
+ }
var executionContexts = selectedNode.target().runtimeModel.executionContexts();
var nodeFrameId = selectedNode.frameId();
@@ -382,53 +382,65 @@ WebInspector.ElementsPanel.prototype = {
return;
}
+ this._hasNonDefaultSelectedNode = false;
WebInspector.domBreakpointsSidebarPane.restoreBreakpoints(inspectedRootDocument);
- /**
- * @this {WebInspector.ElementsPanel}
- * @param {?WebInspector.DOMNode} candidateFocusNode
- */
- function selectNode(candidateFocusNode)
- {
- if (!candidateFocusNode)
- candidateFocusNode = inspectedRootDocument.body || inspectedRootDocument.documentElement;
-
- if (!candidateFocusNode)
- return;
+ var defaultSelection = inspectedRootDocument.body || inspectedRootDocument.documentElement;
+ if (this._omitDefaultSelection || !defaultSelection)
+ return;
- if (!this._pendingNodeReveal) {
- this.selectDOMNode(candidateFocusNode);
- if (treeOutline.selectedTreeElement)
- treeOutline.selectedTreeElement.expand();
- }
- }
+ this._restoreNode(domModel, this._selectedNodeOnReset)
+ .then(onNodeRestored.bind(this, this._selectedNodeOnReset))
dgozman 2016/10/19 01:10:38 missing semicolon
lushnikov 2016/10/19 20:52:11 Done.
/**
- * @param {?DOMAgent.NodeId} nodeId
+ * @param {?WebInspector.DOMNode} staleNode
+ * @param {?WebInspector.DOMNode} restoredNode
* @this {WebInspector.ElementsPanel}
*/
- function selectLastSelectedNode(nodeId)
+ function onNodeRestored(staleNode, restoredNode)
{
- if (this.selectedDOMNode()) {
- // Focused node has been explicitly set while reaching out for the last selected node.
+ if (staleNode !== this._selectedNodeOnReset)
return;
+ if (restoredNode) {
+ this._preselectNode(restoredNode);
+ this._lastSelectedNodeSelectedForTest();
+ } else {
+ this._preselectNode(defaultSelection);
dgozman 2016/10/19 01:10:38 Should recalc default selection.
lushnikov 2016/10/19 20:52:11 Done.
}
- var node = nodeId ? domModel.nodeForId(nodeId) : null;
- selectNode.call(this, node);
- this._lastSelectedNodeSelectedForTest();
}
+ },
- if (this._omitDefaultSelection)
- return;
+ _lastSelectedNodeSelectedForTest: function() { },
- if (this._selectedPathOnReset)
- domModel.pushNodeByPathToFrontend(this._selectedPathOnReset, selectLastSelectedNode.bind(this));
- else
- selectNode.call(this, null);
- delete this._selectedPathOnReset;
+ /**
+ * @param {!WebInspector.DOMNode} node
+ */
+ _preselectNode: function(node)
dgozman 2016/10/19 01:10:38 _setDefaultSelectedNode
dgozman 2016/10/19 01:10:38 Let's make this one responsible for default select
lushnikov 2016/10/19 20:52:11 The default selection seems to fit better in the o
lushnikov 2016/10/19 20:52:11 Done.
+ {
+ if (this._hasNonDefaultSelectedNode || this._pendingNodeReveal)
+ return;
+ var treeOutline = WebInspector.ElementsTreeOutline.forDOMModel(node.domModel());
+ if (!treeOutline)
+ return;
+ this._isSettingDefaultSelection = true;
dgozman 2016/10/19 01:10:38 nit: _isSettingDefaultSelectedNode
lushnikov 2016/10/19 20:52:11 Done.
+ this.selectDOMNode(node);
+ this._isSettingDefaultSelection = false;
+ if (treeOutline.selectedTreeElement)
+ treeOutline.selectedTreeElement.expand();
},
- _lastSelectedNodeSelectedForTest: function() { },
+ /**
+ * @param {!WebInspector.DOMModel} domModel
+ * @param {?WebInspector.DOMNode} staleNode
+ * @return {!Promise<?WebInspector.DOMNode>}
+ */
+ _restoreNode: function(domModel, staleNode)
dgozman 2016/10/19 01:10:38 Let's make this inner function of _documentUpdated
lushnikov 2016/10/19 20:52:11 Done.
+ {
+ var nodePath = staleNode ? staleNode.path() : null;
+ if (!nodePath)
+ return Promise.resolve(/** @type {?WebInspector.DOMNode} */(null));
+ return domModel.pushNodeByPathToFrontendPromise(nodePath);
dgozman 2016/10/19 01:10:38 Let's maybe use callback version?
lushnikov 2016/10/19 20:52:11 Done.
+ },
/**
* @override
@@ -719,7 +731,7 @@ WebInspector.ElementsPanel.prototype = {
var treeOutline = null;
for (var i = 0; i < this._treeOutlines.length; ++i) {
- if (this._treeOutlines[i].selectedDOMNode() === this._lastValidSelectedNode)
+ if (this._treeOutlines[i].selectedDOMNode())
treeOutline = this._treeOutlines[i];
}
if (!treeOutline)

Powered by Google App Engine
This is Rietveld 408576698