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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js

Issue 2637593002: DevTools: Autocomplete CSS variables in StylesSidebar (Closed)
Patch Set: merge Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 2335 matching lines...) Expand 10 before | Expand all | Expand 10 after
2346 2346
2347 var applyItemCallback = !isEditingName ? this._applyFreeFlowStyleTextEdit.bi nd(this) : undefined; 2347 var applyItemCallback = !isEditingName ? this._applyFreeFlowStyleTextEdit.bi nd(this) : undefined;
2348 var cssCompletions = []; 2348 var cssCompletions = [];
2349 if (isEditingName) { 2349 if (isEditingName) {
2350 cssCompletions = SDK.cssMetadata().allProperties(); 2350 cssCompletions = SDK.cssMetadata().allProperties();
2351 cssCompletions = 2351 cssCompletions =
2352 cssCompletions.filter(property => SDK.cssMetadata().isSVGProperty(prop erty) === this.node().isSVGNode()); 2352 cssCompletions.filter(property => SDK.cssMetadata().isSVGProperty(prop erty) === this.node().isSVGNode());
2353 } else { 2353 } else {
2354 cssCompletions = SDK.cssMetadata().propertyValues(this.nameElement.textCon tent); 2354 cssCompletions = SDK.cssMetadata().propertyValues(this.nameElement.textCon tent);
2355 } 2355 }
2356 var cssVariables = this._matchedStyles.cssVariables().sort(String.naturalOrd erComparator);
2356 2357
2357 this._prompt = new Elements.StylesSidebarPane.CSSPropertyPrompt(cssCompletio ns, this, isEditingName); 2358 this._prompt = new Elements.StylesSidebarPane.CSSPropertyPrompt(cssCompletio ns, cssVariables, this, isEditingName);
2358 this._prompt.setAutocompletionTimeout(0); 2359 this._prompt.setAutocompletionTimeout(0);
2359 if (applyItemCallback) { 2360 if (applyItemCallback) {
2360 this._prompt.addEventListener(UI.TextPrompt.Events.ItemApplied, applyItemC allback, this); 2361 this._prompt.addEventListener(UI.TextPrompt.Events.ItemApplied, applyItemC allback, this);
2361 this._prompt.addEventListener(UI.TextPrompt.Events.ItemAccepted, applyItem Callback, this); 2362 this._prompt.addEventListener(UI.TextPrompt.Events.ItemAccepted, applyItem Callback, this);
2362 } 2363 }
2363 var proxyElement = this._prompt.attachAndStartEditing(selectElement, blurLis tener.bind(this, context)); 2364 var proxyElement = this._prompt.attachAndStartEditing(selectElement, blurLis tener.bind(this, context));
2364 this._navigateToSource(selectElement, true); 2365 this._navigateToSource(selectElement, true);
2365 2366
2366 proxyElement.addEventListener('keydown', this._editingNameValueKeyDown.bind( this, context), false); 2367 proxyElement.addEventListener('keydown', this._editingNameValueKeyDown.bind( this, context), false);
2367 proxyElement.addEventListener('keypress', this._editingNameValueKeyPress.bin d(this, context), false); 2368 proxyElement.addEventListener('keypress', this._editingNameValueKeyPress.bin d(this, context), false);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2753 2754
2754 /** @typedef {{expanded: boolean, hasChildren: boolean, isEditingName: boolean, previousContent: string}} */ 2755 /** @typedef {{expanded: boolean, hasChildren: boolean, isEditingName: boolean, previousContent: string}} */
2755 Elements.StylePropertyTreeElement.Context; 2756 Elements.StylePropertyTreeElement.Context;
2756 2757
2757 /** 2758 /**
2758 * @unrestricted 2759 * @unrestricted
2759 */ 2760 */
2760 Elements.StylesSidebarPane.CSSPropertyPrompt = class extends UI.TextPrompt { 2761 Elements.StylesSidebarPane.CSSPropertyPrompt = class extends UI.TextPrompt {
2761 /** 2762 /**
2762 * @param {!Array<string>} cssCompletions 2763 * @param {!Array<string>} cssCompletions
2764 * @param {!Array<string>} cssVariables
2763 * @param {!Elements.StylePropertyTreeElement} treeElement 2765 * @param {!Elements.StylePropertyTreeElement} treeElement
2764 * @param {boolean} isEditingName 2766 * @param {boolean} isEditingName
2765 */ 2767 */
2766 constructor(cssCompletions, treeElement, isEditingName) { 2768 constructor(cssCompletions, cssVariables, treeElement, isEditingName) {
2767 // Use the same callback both for applyItemCallback and acceptItemCallback. 2769 // Use the same callback both for applyItemCallback and acceptItemCallback.
2768 super(); 2770 super();
2769 this.initialize(this._buildPropertyCompletions.bind(this), UI.StyleValueDeli miters); 2771 this.initialize(this._buildPropertyCompletions.bind(this), UI.StyleValueDeli miters);
2770 this._cssCompletions = cssCompletions; 2772 this._cssCompletions = cssCompletions;
2773 this._cssVariables = cssVariables;
2771 this._treeElement = treeElement; 2774 this._treeElement = treeElement;
2772 this._isEditingName = isEditingName; 2775 this._isEditingName = isEditingName;
2773 2776
2774 if (!isEditingName) { 2777 if (!isEditingName) {
2775 this.disableDefaultSuggestionForEmptyInput(); 2778 this.disableDefaultSuggestionForEmptyInput();
2776 2779
2777 // If a CSS value is being edited that has a numeric or hex substring, hin t that precision modifier shortcuts are available. 2780 // If a CSS value is being edited that has a numeric or hex substring, hin t that precision modifier shortcuts are available.
2778 if (treeElement && treeElement.valueElement) { 2781 if (treeElement && treeElement.valueElement) {
2779 var cssValueText = treeElement.valueElement.textContent; 2782 var cssValueText = treeElement.valueElement.textContent;
2780 if (cssValueText.match(/#[\da-f]{3,6}$/i)) { 2783 if (cssValueText.match(/#[\da-f]{3,6}$/i)) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 } 2883 }
2881 2884
2882 /** 2885 /**
2883 * @param {string} word 2886 * @param {string} word
2884 * @return {boolean} 2887 * @return {boolean}
2885 */ 2888 */
2886 _isValueSuggestion(word) { 2889 _isValueSuggestion(word) {
2887 if (!word) 2890 if (!word)
2888 return false; 2891 return false;
2889 word = word.toLowerCase(); 2892 word = word.toLowerCase();
2890 return this._cssCompletions.indexOf(word) !== -1; 2893 return this._cssCompletions.indexOf(word) !== -1 || word.startsWith('--');
2891 } 2894 }
2892 2895
2893 /** 2896 /**
2894 * @param {string} expression 2897 * @param {string} expression
2895 * @param {string} query 2898 * @param {string} query
2896 * @param {boolean=} force 2899 * @param {boolean=} force
2897 * @return {!Promise<!UI.SuggestBox.Suggestions>} 2900 * @return {!Promise<!UI.SuggestBox.Suggestions>}
2898 */ 2901 */
2899 _buildPropertyCompletions(expression, query, force) { 2902 _buildPropertyCompletions(expression, query, force) {
2900 var lowerQuery = query.toLowerCase(); 2903 var lowerQuery = query.toLowerCase();
2901 if (!query && !force && (this._isEditingName || expression)) 2904 var editingVariable = !this._isEditingName && expression.trim().endsWith('va r(');
2905 if (!query && !force && !editingVariable && (this._isEditingName || expressi on))
2902 return Promise.resolve([]); 2906 return Promise.resolve([]);
2903 2907
2904 var prefixResults = []; 2908 var prefixResults = [];
2905 var anywhereResults = []; 2909 var anywhereResults = [];
2906 this._cssCompletions.forEach(filterCompletions.bind(this)); 2910 if (!editingVariable)
2911 this._cssCompletions.forEach(filterCompletions.bind(this));
2912 if (this._isEditingName || editingVariable)
2913 this._cssVariables.forEach(filterCompletions.bind(this));
2914
2907 var results = prefixResults.concat(anywhereResults); 2915 var results = prefixResults.concat(anywhereResults);
2908
2909 if (!this._isEditingName && !results.length && query.length > 1 && '!importa nt'.startsWith(lowerQuery)) 2916 if (!this._isEditingName && !results.length && query.length > 1 && '!importa nt'.startsWith(lowerQuery))
2910 results.push({text: '!important'}); 2917 results.push({text: '!important'});
2911 var userEnteredText = query.replace('-', ''); 2918 var userEnteredText = query.replace('-', '');
2912 if (userEnteredText && (userEnteredText === userEnteredText.toUpperCase())) { 2919 if (userEnteredText && (userEnteredText === userEnteredText.toUpperCase())) {
2913 for (var i = 0; i < results.length; ++i) 2920 for (var i = 0; i < results.length; ++i) {
2914 results[i].text = results[i].text.toUpperCase(); 2921 if (!results[i].text.startsWith('--'))
2922 results[i].text = results[i].text.toUpperCase();
2923 }
2915 } 2924 }
2925 if (editingVariable)
2926 results.forEach(result => result.text += ')');
2916 return Promise.resolve(results); 2927 return Promise.resolve(results);
2917 2928
2918 /** 2929 /**
2919 * @param {string} completion 2930 * @param {string} completion
2920 * @this {Elements.StylesSidebarPane.CSSPropertyPrompt} 2931 * @this {Elements.StylesSidebarPane.CSSPropertyPrompt}
2921 */ 2932 */
2922 function filterCompletions(completion) { 2933 function filterCompletions(completion) {
2923 var index = completion.indexOf(lowerQuery); 2934 var index = completion.toLowerCase().indexOf(lowerQuery);
2924 if (index === 0) { 2935 if (index === 0) {
2925 var priority = this._isEditingName ? SDK.cssMetadata().propertyUsageWeig ht(completion) : 1; 2936 var priority = this._isEditingName ? SDK.cssMetadata().propertyUsageWeig ht(completion) : 1;
2926 prefixResults.push({text: completion, priority: priority}); 2937 prefixResults.push({text: completion, priority: priority});
2927 } else if (index > -1) { 2938 } else if (index > -1) {
2928 anywhereResults.push({text: completion}); 2939 anywhereResults.push({text: completion});
2929 } 2940 }
2930 } 2941 }
2931 } 2942 }
2932 }; 2943 };
2933 2944
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
3080 } 3091 }
3081 3092
3082 /** 3093 /**
3083 * @override 3094 * @override
3084 * @return {!UI.ToolbarItem} 3095 * @return {!UI.ToolbarItem}
3085 */ 3096 */
3086 item() { 3097 item() {
3087 return this._button; 3098 return this._button;
3088 } 3099 }
3089 }; 3100 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698