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

Unified Diff: third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js

Issue 1803813002: [DevTools] Added keyboard search while in sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review input implemented/fixed Created 4 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/treeoutline.css ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js
diff --git a/third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js b/third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js
index 7755b1cdc7fc565c0af853c00ba39addfbd23400..391a77d1767449d75b27305e1c679fa257bf3f63 100644
--- a/third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js
+++ b/third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js
@@ -46,6 +46,15 @@ function TreeOutline(nonFocusable)
this.setFocusable(!nonFocusable);
this.element = this._contentElement;
+
+ this._contentElement.addEventListener("keypress", this._handleKeyPressForHighlighting.bind(this), true);
+ this.element.addEventListener("blur", this._clearFilter.bind(this), true);
+ this.element.addEventListener("click", this._clearFilter.bind(this), true);
+
+ this._currentSelectionFilterString = "";
+ this._interactiveFilterEnabled = false;
+ /** @type {!Array.<!TreeElement>} */
+ this._highlightChangedNodes = []
}
TreeOutline.Events = {
@@ -75,6 +84,118 @@ TreeOutline.prototype = {
},
/**
+ * @param {boolean} enable
+ */
+ setInteractiveFilterable: function (enable)
+ {
+ this._interactiveFilterEnabled = enable;
pfeldman 2016/03/22 00:00:33 Should disabling perform the cleanup?
+ },
+
+ /**
+ * @param {string} filterString
+ */
+ _setCurrentSelectionFilterString: function (filterString)
+ {
+ this._currentSelectionFilterString = filterString;
+ this._refreshHighlighting();
+ },
+
+ /**
+ * @param {string} filterString
+ * @return {!RegExp}
+ */
+ _makeFilterRegExpFromString: function (filterString)
+ {
+ return new RegExp(["(", filterString.escapeForRegExp(), ")"].join(""), "gi")
pfeldman 2016/03/22 00:00:34 Do you need the () group?
+ },
+
+ _refreshHighlighting: function ()
+ {
+ if (!this._rootElement)
+ return;
+
+ var filterRegExp = this._makeFilterRegExpFromString(this._currentSelectionFilterString);
+
+ for (var changedNode of this._highlightChangedNodes)
+ changedNode._revertHighlightChanges();
+
+ this._highlightChanges = [];
+
+ if (this._currentSelectionFilterString === "")
pfeldman 2016/03/22 00:00:33 if (!this._currentSelectionFilterString)
+ return;
+
+ if (this.selectedTreeElement && !this.selectedTreeElement.selectable)
+ this.selectNext() || this.selectPrevious();
pfeldman 2016/03/22 00:00:34 statement per line please. if (!selectNext) se
+
+ var node = this._rootElement.firstChild();
+ do {
+ var textContent = node._listItemNode.textContent;
+ var match = filterRegExp.exec(textContent);
+ var ranges = [];
+ var changes = [];
+ while (true) {
+ if (match === null)
+ break;
+ ranges.push(new WebInspector.SourceRange(match.index, match[0].length));
+ match = filterRegExp.exec(textContent);
+ }
+ if (ranges.length > 0)
pfeldman 2016/03/22 00:00:34 if (ranges.length)
+ WebInspector.highlightRangesWithStyleClass(node._listItemNode, ranges, "tree-text-interactive-highlight", changes);
+
+ if (changes.length) {
+ node._setHighlightChanges(changes);
+ this._highlightChangedNodes.push(node);
pfeldman 2016/03/22 00:00:33 Can't there only be one highlighted node?
+ }
+
+ node = node.traverseNextTreeElement(true, null, true);
+ } while(node);
+ },
+
+ /**
+ * @param {!TreeElement} treeElement
+ * @return {boolean}
+ */
+ _checkFilter: function (treeElement)
+ {
+ return this._currentSelectionFilterString !== "" ? this._makeFilterRegExpFromString(this._currentSelectionFilterString).test(treeElement._titleElement.textContent) : true;
pfeldman 2016/03/22 00:00:33 this._currentSelectionFilterString ? ...
+ },
+
+ _clearFilter: function ()
+ {
+ if (this._interactiveFilterEnabled)
+ this._setCurrentSelectionFilterString("");
+ },
+
+ /**
+ * @param {!Event} event
+ */
+ _handleKeyPressForHighlighting: function (event)
+ {
+ if (!this._interactiveFilterEnabled)
+ return;
+
+ if (event.target !== this._contentElement)
+ return;
+
+ if (!this.selectedTreeElement || event.shiftKey || event.metaKey || event.ctrlKey)
+ return;
+
+ var currentFilterString = this._currentSelectionFilterString;
+
+ switch (event.data) {
+ case "\r":
+ case "\n":
+ break;
+ case " ":
+ if (currentFilterString.length === 0) {
pfeldman 2016/03/22 00:00:34 !length
+ break;
+ }
+ default:
+ this._setCurrentSelectionFilterString(currentFilterString + event.data);
+ }
+ },
+
+ /**
* @return {?TreeElement}
*/
firstChild: function()
@@ -229,30 +350,38 @@ TreeOutline.prototype = {
if (!this.selectedTreeElement || event.shiftKey || event.metaKey || event.ctrlKey)
return;
+ var currentFilterString = this._currentSelectionFilterString;
var handled = false;
+ var key = event.keyCode;
var nextSelectedElement;
- if (event.keyIdentifier === "Up" && !event.altKey) {
- handled = this.selectPrevious();
- } else if (event.keyIdentifier === "Down" && !event.altKey) {
- handled = this.selectNext();
- } else if (event.keyIdentifier === "Left") {
- if (this.selectedTreeElement.expanded) {
- if (event.altKey)
- this.selectedTreeElement.collapseRecursively();
- else
- this.selectedTreeElement.collapse();
+
+ switch (key) {
+ case WebInspector.KeyboardShortcut.Keys.Esc.code:
+ if (this._interactiveFilterEnabled) {
+ if (currentFilterString.length)
+ // Consider the item handled if the filter string is already set (this will keep the console from triggering)
+ handled = true;
+ this._clearFilter();
+ }
+ break;
+ case WebInspector.KeyboardShortcut.Keys.Delete.code:
+ if (this._interactiveFilterEnabled && currentFilterString.length) {
handled = true;
- } else if (this.selectedTreeElement.parent && !this.selectedTreeElement.parent.root) {
+ this._clearFilter();
+ } else
+ handled = this.selectedTreeElement.ondelete();
+ break;
+ case WebInspector.KeyboardShortcut.Keys.Backspace.code:
+ if (this._interactiveFilterEnabled && currentFilterString.length) {
handled = true;
- if (this.selectedTreeElement.parent.selectable) {
- nextSelectedElement = this.selectedTreeElement.parent;
- while (nextSelectedElement && !nextSelectedElement.selectable)
- nextSelectedElement = nextSelectedElement.parent;
- handled = nextSelectedElement ? true : false;
- } else if (this.selectedTreeElement.parent)
- this.selectedTreeElement.parent.collapse();
- }
- } else if (event.keyIdentifier === "Right") {
+ this._setCurrentSelectionFilterString(currentFilterString.substr(0, currentFilterString.length - 1));
+ } else
+ handled = this.selectedTreeElement.ondelete();
+ break;
+ case WebInspector.KeyboardShortcut.Keys.Right.code:
+ if (this._interactiveFilterEnabled)
+ this._clearFilter();
+
if (!this.selectedTreeElement.revealed()) {
this.selectedTreeElement.reveal();
handled = true;
@@ -270,12 +399,49 @@ TreeOutline.prototype = {
this.selectedTreeElement.expand();
}
}
- } else if (event.keyCode === 8 /* Backspace */ || event.keyCode === 46 /* Delete */)
- handled = this.selectedTreeElement.ondelete();
- else if (isEnterKey(event))
- handled = this.selectedTreeElement.onenter();
- else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Space.code)
- handled = this.selectedTreeElement.onspace();
+ break;
+ case WebInspector.KeyboardShortcut.Keys.Left.code:
+ if (this._interactiveFilterEnabled)
+ this._clearFilter();
+
+ if (this.selectedTreeElement.expanded) {
+ if (event.altKey)
+ this.selectedTreeElement.collapseRecursively();
+ else
+ this.selectedTreeElement.collapse();
+ handled = true;
+ } else if (this.selectedTreeElement.parent && !this.selectedTreeElement.parent.root) {
+ handled = true;
+ if (this.selectedTreeElement.parent.selectable) {
+ nextSelectedElement = this.selectedTreeElement.parent;
+ while (nextSelectedElement && !nextSelectedElement.selectable)
+ nextSelectedElement = nextSelectedElement.parent;
+ handled = nextSelectedElement ? true : false;
+ } else if (this.selectedTreeElement.parent)
+ this.selectedTreeElement.parent.collapse();
+ }
+ break;
+ case WebInspector.KeyboardShortcut.Keys.Down.code:
+ if (!event.altKey)
+ handled = this.selectNext();
+ break;
+ case WebInspector.KeyboardShortcut.Keys.Up.code:
+ if (!event.altKey)
+ handled = this.selectPrevious();
+ break;
+ case WebInspector.KeyboardShortcut.Keys.Space.code:
+ // Do not send space key event if the search filter has stuff in buffer
+ if (!currentFilterString.length)
+ handled = this.selectedTreeElement.onspace();
+ break;
+ default:
+ if (isEnterKey(event)) {
+ if (this._interactiveFilterEnabled)
+ this._clearFilter();
+
+ handled = this.selectedTreeElement.onenter();
+ }
+ }
if (nextSelectedElement) {
nextSelectedElement.reveal();
@@ -360,6 +526,7 @@ function TreeElement(title, expandable)
this._listItemNode = createElement("li");
this._listItemNode.treeElement = this;
+
if (title)
this.title = title;
this._listItemNode.addEventListener("mousedown", this._handleMouseDown.bind(this), false);
@@ -377,6 +544,9 @@ function TreeElement(title, expandable)
this.selected = false;
this.setExpandable(expandable || false);
this._collapsible = true;
+
+ /** @type {!Array.<!Object>} */
+ this._highlightChanges = [];
}
/** @const */
@@ -384,6 +554,20 @@ TreeElement._ArrowToggleWidth = 10;
TreeElement.prototype = {
/**
+ * @param {!Array.<!Object>} changes
+ */
+ _setHighlightChanges: function (changes)
+ {
+ this._highlightChanges = changes;
+ },
+
+ _revertHighlightChanges: function ()
+ {
+ WebInspector.revertDomChanges(this._highlightChanges);
+ this._highlightChanges = [];
+ },
+
+ /**
* @param {?TreeElement} ancestor
* @return {boolean}
*/
@@ -603,7 +787,7 @@ TreeElement.prototype = {
get selectable()
{
- if (this._hidden)
+ if (this._hidden || !this.treeOutline._checkFilter(this))
return false;
return this._selectable;
},
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/treeoutline.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698