Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Tim van der Lippe | aabc830 | 2019-12-10 15:34:45 | [diff] [blame] | 4 | import {ElementsPanel} from './ElementsPanel.js'; |
| 5 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 6 | /** |
| 7 | * @unrestricted |
| 8 | */ |
Tim van der Lippe | aabc830 | 2019-12-10 15:34:45 | [diff] [blame] | 9 | export class ClassesPaneWidget extends UI.Widget { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 10 | constructor() { |
| 11 | super(true); |
| 12 | this.registerRequiredCSS('elements/classesPaneWidget.css'); |
| 13 | this.contentElement.className = 'styles-element-classes-pane'; |
| 14 | const container = this.contentElement.createChild('div', 'title-container'); |
| 15 | this._input = container.createChild('div', 'new-class-input monospace'); |
| 16 | this.setDefaultFocusedElement(this._input); |
| 17 | this._classesContainer = this.contentElement.createChild('div', 'source-code'); |
| 18 | this._classesContainer.classList.add('styles-element-classes-container'); |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 19 | this._prompt = new ClassNamePrompt(this._nodeClasses.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 20 | this._prompt.setAutocompletionTimeout(0); |
| 21 | this._prompt.renderAsBlock(); |
| 22 | |
| 23 | const proxyElement = this._prompt.attach(this._input); |
| 24 | this._prompt.setPlaceholder(Common.UIString('Add new class')); |
| 25 | this._prompt.addEventListener(UI.TextPrompt.Events.TextChanged, this._onTextChanged, this); |
| 26 | proxyElement.addEventListener('keydown', this._onKeyDown.bind(this), false); |
| 27 | |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 28 | self.SDK.targetManager.addModelListener(SDK.DOMModel, SDK.DOMModel.Events.DOMMutated, this._onDOMMutated, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 29 | /** @type {!Set<!SDK.DOMNode>} */ |
| 30 | this._mutatingNodes = new Set(); |
| 31 | /** @type {!Map<!SDK.DOMNode, string>} */ |
| 32 | this._pendingNodeClasses = new Map(); |
| 33 | this._updateNodeThrottler = new Common.Throttler(0); |
| 34 | /** @type {?SDK.DOMNode} */ |
| 35 | this._previousTarget = null; |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 36 | self.UI.context.addFlavorChangeListener(SDK.DOMNode, this._onSelectedNodeChanged, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param {string} text |
| 41 | * @return {!Array.<string>} |
| 42 | */ |
| 43 | _splitTextIntoClasses(text) { |
| 44 | return text.split(/[.,\s]/) |
| 45 | .map(className => className.trim()) |
| 46 | .filter(className => className.length); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @param {!Event} event |
| 51 | */ |
| 52 | _onKeyDown(event) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 53 | if (!isEnterKey(event) && !isEscKey(event)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 54 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 55 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 56 | |
| 57 | if (isEnterKey(event)) { |
| 58 | event.consume(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 59 | if (this._prompt.acceptAutoComplete()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 60 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 61 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | let text = event.target.textContent; |
| 65 | if (isEscKey(event)) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 66 | if (!text.isWhitespace()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 67 | event.consume(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 68 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 69 | text = ''; |
| 70 | } |
| 71 | |
| 72 | this._prompt.clearAutocomplete(); |
| 73 | event.target.textContent = ''; |
| 74 | |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 75 | const node = self.UI.context.flavor(SDK.DOMNode); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 76 | if (!node) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 77 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 78 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 79 | |
| 80 | const classNames = this._splitTextIntoClasses(text); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 81 | for (const className of classNames) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 82 | this._toggleClass(node, className, true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 83 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 84 | this._installNodeClasses(node); |
| 85 | this._update(); |
| 86 | } |
| 87 | |
| 88 | _onTextChanged() { |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 89 | const node = self.UI.context.flavor(SDK.DOMNode); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 90 | if (!node) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 91 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 92 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 93 | this._installNodeClasses(node); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @param {!Common.Event} event |
| 98 | */ |
| 99 | _onDOMMutated(event) { |
| 100 | const node = /** @type {!SDK.DOMNode} */ (event.data); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 101 | if (this._mutatingNodes.has(node)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 102 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 103 | } |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 104 | delete node[ClassesPaneWidget._classesSymbol]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 105 | this._update(); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @param {!Common.Event} event |
| 110 | */ |
| 111 | _onSelectedNodeChanged(event) { |
| 112 | if (this._previousTarget && this._prompt.text()) { |
| 113 | this._input.textContent = ''; |
| 114 | this._installNodeClasses(this._previousTarget); |
| 115 | } |
| 116 | this._previousTarget = /** @type {?SDK.DOMNode} */ (event.data); |
| 117 | this._update(); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @override |
| 122 | */ |
| 123 | wasShown() { |
| 124 | this._update(); |
| 125 | } |
| 126 | |
| 127 | _update() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 128 | if (!this.isShowing()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 129 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 130 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 131 | |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 132 | let node = self.UI.context.flavor(SDK.DOMNode); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 133 | if (node) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 134 | node = node.enclosingElementOrSelf(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 135 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 136 | |
| 137 | this._classesContainer.removeChildren(); |
| 138 | this._input.disabled = !node; |
| 139 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 140 | if (!node) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 141 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 142 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 143 | |
| 144 | const classes = this._nodeClasses(node); |
Simon Zünd | f27be3d | 2020-02-11 14:46:27 | [diff] [blame] | 145 | const keys = [...classes.keys()]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 146 | keys.sort(String.caseInsensetiveComparator); |
| 147 | for (let i = 0; i < keys.length; ++i) { |
| 148 | const className = keys[i]; |
| 149 | const label = UI.CheckboxLabel.create(className, classes.get(className)); |
| 150 | label.classList.add('monospace'); |
| 151 | label.checkboxElement.addEventListener('click', this._onClick.bind(this, className), false); |
| 152 | this._classesContainer.appendChild(label); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @param {string} className |
| 158 | * @param {!Event} event |
| 159 | */ |
| 160 | _onClick(className, event) { |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 161 | const node = self.UI.context.flavor(SDK.DOMNode); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 162 | if (!node) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 163 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 164 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 165 | const enabled = event.target.checked; |
| 166 | this._toggleClass(node, className, enabled); |
| 167 | this._installNodeClasses(node); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @param {!SDK.DOMNode} node |
| 172 | * @return {!Map<string, boolean>} |
| 173 | */ |
| 174 | _nodeClasses(node) { |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 175 | let result = node[ClassesPaneWidget._classesSymbol]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 176 | if (!result) { |
| 177 | const classAttribute = node.getAttribute('class') || ''; |
| 178 | const classes = classAttribute.split(/\s/); |
| 179 | result = new Map(); |
| 180 | for (let i = 0; i < classes.length; ++i) { |
| 181 | const className = classes[i].trim(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 182 | if (!className.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 183 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 184 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 185 | result.set(className, true); |
| 186 | } |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 187 | node[ClassesPaneWidget._classesSymbol] = result; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 188 | } |
| 189 | return result; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * @param {!SDK.DOMNode} node |
| 194 | * @param {string} className |
| 195 | * @param {boolean} enabled |
| 196 | */ |
| 197 | _toggleClass(node, className, enabled) { |
| 198 | const classes = this._nodeClasses(node); |
| 199 | classes.set(className, enabled); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * @param {!SDK.DOMNode} node |
| 204 | */ |
| 205 | _installNodeClasses(node) { |
| 206 | const classes = this._nodeClasses(node); |
| 207 | const activeClasses = new Set(); |
| 208 | for (const className of classes.keys()) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 209 | if (classes.get(className)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 210 | activeClasses.add(className); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 211 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | const additionalClasses = this._splitTextIntoClasses(this._prompt.textWithCurrentSuggestion()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 215 | for (const className of additionalClasses) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 216 | activeClasses.add(className); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 217 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 218 | |
Simon Zünd | a0d4062 | 2020-02-12 13:16:42 | [diff] [blame^] | 219 | const newClasses = [...activeClasses.values()].sort(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 220 | |
| 221 | this._pendingNodeClasses.set(node, newClasses.join(' ')); |
| 222 | this._updateNodeThrottler.schedule(this._flushPendingClasses.bind(this)); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * @return {!Promise} |
| 227 | */ |
| 228 | _flushPendingClasses() { |
| 229 | const promises = []; |
| 230 | for (const node of this._pendingNodeClasses.keys()) { |
| 231 | this._mutatingNodes.add(node); |
| 232 | const promise = node.setAttributeValuePromise('class', this._pendingNodeClasses.get(node)) |
| 233 | .then(onClassValueUpdated.bind(this, node)); |
| 234 | promises.push(promise); |
| 235 | } |
| 236 | this._pendingNodeClasses.clear(); |
| 237 | return Promise.all(promises); |
| 238 | |
| 239 | /** |
| 240 | * @param {!SDK.DOMNode} node |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 241 | * @this {ClassesPaneWidget} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 242 | */ |
| 243 | function onClassValueUpdated(node) { |
| 244 | this._mutatingNodes.delete(node); |
| 245 | } |
| 246 | } |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 247 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 248 | |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 249 | ClassesPaneWidget._classesSymbol = Symbol('ClassesPaneWidget._classesSymbol'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 250 | |
| 251 | /** |
| 252 | * @implements {UI.ToolbarItem.Provider} |
| 253 | * @unrestricted |
| 254 | */ |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 255 | export class ButtonProvider { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 256 | constructor() { |
| 257 | this._button = new UI.ToolbarToggle(Common.UIString('Element Classes'), ''); |
| 258 | this._button.setText('.cls'); |
| 259 | this._button.element.classList.add('monospace'); |
| 260 | this._button.addEventListener(UI.ToolbarButton.Events.Click, this._clicked, this); |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 261 | this._view = new ClassesPaneWidget(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | _clicked() { |
Tim van der Lippe | aabc830 | 2019-12-10 15:34:45 | [diff] [blame] | 265 | ElementsPanel.instance().showToolbarPane(!this._view.isShowing() ? this._view : null, this._button); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /** |
| 269 | * @override |
| 270 | * @return {!UI.ToolbarItem} |
| 271 | */ |
| 272 | item() { |
| 273 | return this._button; |
| 274 | } |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 275 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * @unrestricted |
| 279 | */ |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 280 | export class ClassNamePrompt extends UI.TextPrompt { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 281 | /** |
| 282 | * @param {function(!SDK.DOMNode):!Map<string, boolean>} nodeClasses |
| 283 | */ |
| 284 | constructor(nodeClasses) { |
| 285 | super(); |
| 286 | this._nodeClasses = nodeClasses; |
| 287 | this.initialize(this._buildClassNameCompletions.bind(this), ' '); |
| 288 | this.disableDefaultSuggestionForEmptyInput(); |
| 289 | this._selectedFrameId = ''; |
| 290 | this._classNamesPromise = null; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * @param {!SDK.DOMNode} selectedNode |
| 295 | * @return {!Promise.<!Array.<string>>} |
| 296 | */ |
| 297 | _getClassNames(selectedNode) { |
| 298 | const promises = []; |
| 299 | const completions = new Set(); |
| 300 | this._selectedFrameId = selectedNode.frameId(); |
| 301 | |
| 302 | const cssModel = selectedNode.domModel().cssModel(); |
| 303 | const allStyleSheets = cssModel.allStyleSheets(); |
| 304 | for (const stylesheet of allStyleSheets) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 305 | if (stylesheet.frameId !== this._selectedFrameId) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 306 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 307 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 308 | const cssPromise = cssModel.classNamesPromise(stylesheet.id).then(classes => completions.addAll(classes)); |
| 309 | promises.push(cssPromise); |
| 310 | } |
| 311 | |
| 312 | const domPromise = selectedNode.domModel() |
| 313 | .classNamesPromise(selectedNode.ownerDocument.id) |
| 314 | .then(classes => completions.addAll(classes)); |
| 315 | promises.push(domPromise); |
Simon Zünd | a0d4062 | 2020-02-12 13:16:42 | [diff] [blame^] | 316 | return Promise.all(promises).then(() => [...completions]); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /** |
| 320 | * @param {string} expression |
| 321 | * @param {string} prefix |
| 322 | * @param {boolean=} force |
| 323 | * @return {!Promise<!UI.SuggestBox.Suggestions>} |
| 324 | */ |
| 325 | _buildClassNameCompletions(expression, prefix, force) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 326 | if (!prefix || force) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 327 | this._classNamesPromise = null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 328 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 329 | |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 330 | const selectedNode = self.UI.context.flavor(SDK.DOMNode); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 331 | if (!selectedNode || (!prefix && !force && !expression.trim())) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 332 | return Promise.resolve([]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 333 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 334 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 335 | if (!this._classNamesPromise || this._selectedFrameId !== selectedNode.frameId()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 336 | this._classNamesPromise = this._getClassNames(selectedNode); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 337 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 338 | |
| 339 | return this._classNamesPromise.then(completions => { |
| 340 | const classesMap = this._nodeClasses(/** @type {!SDK.DOMNode} */ (selectedNode)); |
| 341 | completions = completions.filter(value => !classesMap.get(value)); |
| 342 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 343 | if (prefix[0] === '.') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 344 | completions = completions.map(value => '.' + value); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 345 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 346 | return completions.filter(value => value.startsWith(prefix)).sort().map(completion => ({text: completion})); |
| 347 | }); |
| 348 | } |
Tim van der Lippe | 13f71fb | 2019-11-29 11:17:39 | [diff] [blame] | 349 | } |