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

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

Issue 2343773002: DevTools: Autocomplete class names in ClassesPaneWidget (Closed)
Patch Set: Rebased Created 4 years, 3 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 | « no previous file | third_party/WebKit/Source/devtools/front_end/elements/elementsPanel.css » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js b/third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js
index b0bada022b10ab39a9c8379afb97d078f1c7817a..723efb2be80b7aa4a70e03a6347794765c3ce8dd 100644
--- a/third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js
+++ b/third_party/WebKit/Source/devtools/front_end/elements/ClassesPaneWidget.js
@@ -11,12 +11,17 @@ WebInspector.ClassesPaneWidget = function()
WebInspector.Widget.call(this);
this.element.className = "styles-element-classes-pane";
var container = this.element.createChild("div", "title-container");
- this._input = container.createChild("input", "new-class-input monospace");
- this._input.placeholder = WebInspector.UIString("Add new class");
- this._input.addEventListener("keydown", this._onKeyDown.bind(this), false);
+ this._input = container.createChild("div", "new-class-input monospace");
+ this._input.setAttribute("placeholder", WebInspector.UIString("Add new class"));
this.setDefaultFocusedElement(this._input);
this._classesContainer = this.element.createChild("div", "source-code");
this._classesContainer.classList.add("styles-element-classes-container");
+ this._prompt = new WebInspector.ClassesPaneWidget.ClassNamePrompt();
+ this._prompt.setAutocompletionTimeout(0);
+ this._prompt.renderAsBlock();
+
+ var proxyElement = this._prompt.attach(this._input);
+ proxyElement.addEventListener("keydown", this._onKeyDown.bind(this), false);
WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspector.DOMModel.Events.DOMMutated, this._onDOMMutated, this);
/** @type {!Set<!WebInspector.DOMNode>} */
@@ -32,9 +37,9 @@ WebInspector.ClassesPaneWidget.prototype = {
*/
_onKeyDown: function(event)
{
- var text = event.target.value;
+ var text = event.target.textContent;
if (isEscKey(event)) {
- event.target.value = "";
+ event.target.textContent = "";
if (!text.isWhitespace())
event.consume(true);
return;
@@ -46,7 +51,8 @@ WebInspector.ClassesPaneWidget.prototype = {
if (!node)
return;
- event.target.value = "";
+ this._prompt.clearAutocomplete();
+ event.target.textContent = "";
var classNames = text.split(/[.,\s]/);
for (var className of classNames) {
var className = className.trim();
@@ -211,3 +217,74 @@ WebInspector.ClassesPaneWidget.ButtonProvider.prototype = {
return this._button;
}
}
+
+/**
+ * @constructor
+ * @extends {WebInspector.TextPrompt}
+ */
+WebInspector.ClassesPaneWidget.ClassNamePrompt = function()
+{
+ WebInspector.TextPrompt.call(this, this._buildClassNameCompletions.bind(this), " ");
+ this.setSuggestBoxEnabled(true);
+ this.disableDefaultSuggestionForEmptyInput();
+}
+
+WebInspector.ClassesPaneWidget.ClassNamePrompt.prototype = {
+ /**
+ * @override
+ * @param {!Event} event
+ */
+ onKeyDown: function(event)
lushnikov 2016/09/28 21:19:39 why do you need to override onKeyDown? Looks like
ahmetemirercin 2016/09/28 23:40:56 Done.
+ {
+ switch (event.key) {
+ case "Enter":
+ // Accept any available autocompletions and advance to the next field.
+ if (this.autoCompleteElement && this.autoCompleteElement.textContent.length) {
+ this.acceptAutoComplete();
+ return;
+ }
+ break;
+ }
+
+ WebInspector.TextPrompt.prototype.onKeyDown.call(this, event);
+ },
+
+ /**
+ * @param {!Element} proxyElement
+ * @param {!Range} wordRange
+ * @param {boolean} force
+ * @param {function(!Array.<string>, number=)} completionsReadyCallback
+ */
+ _buildClassNameCompletions: function(proxyElement, wordRange, force, completionsReadyCallback)
+ {
+ var prefix = wordRange.toString();
+ if (!prefix && !force && !proxyElement.textContent.length) {
+ completionsReadyCallback([]);
+ return;
+ }
+
+ var promises = [];
+ var allClasses = new Set();
+ var selectedNode = WebInspector.context.flavor(WebInspector.DOMNode);
lushnikov 2016/09/28 21:19:39 at times selectedNode is null - let's bail out in
ahmetemirercin 2016/09/28 23:40:56 Done.
+ var cssModel = WebInspector.CSSModel.fromTarget(selectedNode.target());
+ var allStyleSheets = cssModel.allStyleSheets();
+ var selectedFrameId = selectedNode.frameId() || WebInspector.ResourceTreeModel.fromTarget(selectedNode.target()).mainFrame.id;
+
+ for (var stylesheet of allStyleSheets) {
lushnikov 2016/09/28 21:19:40 this code runs for every keypress in ClassesPaneWi
ahmetemirercin 2016/09/28 23:40:56 I propose keeping old completions when user moving
lushnikov 2016/09/29 16:03:15 It's better, but as someone who explores completio
ahmetemirercin 2016/09/29 19:25:36 I was afraid that classnames can be ready when use
+ if (stylesheet.frameId !== selectedFrameId)
+ continue;
+ var cssPromise = cssModel.classNamesPromise(stylesheet.id).then(classes => allClasses.addAll(classes));
+ promises.push(cssPromise);
+ }
+
+ var domPromise = selectedNode.domModel().classNamesPromise(selectedNode.ownerDocument.id).then(classes => allClasses.addAll(classes));
+ promises.push(domPromise);
+
+ Promise.all(promises).then(() => {
+ var results = allClasses.valuesArray().filter((value) => value.startsWith(prefix));
+ completionsReadyCallback(results, 0);
+ });
+ },
+
+ __proto__: WebInspector.TextPrompt.prototype
+}
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/elements/elementsPanel.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698