OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 | 175 |
176 /** | 176 /** |
177 * @param {!WebInspector.ColorSwatch} swatch | 177 * @param {!WebInspector.ColorSwatch} swatch |
178 * @param {!WebInspector.CSSSourceFrame.ColorPosition} colorPosition | 178 * @param {!WebInspector.CSSSourceFrame.ColorPosition} colorPosition |
179 * @param {!Event} event | 179 * @param {!Event} event |
180 */ | 180 */ |
181 _showSpectrum: function(swatch, colorPosition, event) | 181 _showSpectrum: function(swatch, colorPosition, event) |
182 { | 182 { |
183 event.consume(true); | 183 event.consume(true); |
184 if (this._swatchPopoverHelper.isShowing()) { | 184 if (this._swatchPopoverHelper.isShowing()) { |
185 this._swatchPopoverHelper.hide(); | 185 this._swatchPopoverHelper.hide(true); |
186 return; | 186 return; |
187 } | 187 } |
188 this._currentSwatch = swatch; | 188 this._currentSwatch = swatch; |
189 this._currentColorPosition = colorPosition; | 189 this._currentColorPosition = colorPosition; |
190 this._originalColorText = colorPosition.color.asString(WebInspector.Colo r.Format.Original); | |
190 this._spectrum = new WebInspector.Spectrum(); | 191 this._spectrum = new WebInspector.Spectrum(); |
191 this._spectrum.setColor(swatch.color(), swatch.format()); | 192 this._spectrum.setColor(swatch.color(), swatch.format()); |
192 this._spectrum.addEventListener(WebInspector.Spectrum.Events.SizeChanged , this._spectrumResized, this); | 193 this._spectrum.addEventListener(WebInspector.Spectrum.Events.SizeChanged , this._spectrumResized, this); |
193 this._spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChange d, this._spectrumChanged, this); | 194 this._spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChange d, this._spectrumChanged, this); |
194 this._swatchPopoverHelper.show(this._spectrum, swatch.iconElement(), thi s._spectrumHidden.bind(this)); | 195 this._swatchPopoverHelper.show(this._spectrum, swatch.iconElement(), thi s._spectrumHidden.bind(this)); |
195 }, | 196 }, |
196 | 197 |
197 /** | 198 /** |
198 * @param {!WebInspector.Event} event | 199 * @param {!WebInspector.Event} event |
199 */ | 200 */ |
200 _spectrumResized: function(event) | 201 _spectrumResized: function(event) |
201 { | 202 { |
202 this._swatchPopoverHelper.reposition(); | 203 this._swatchPopoverHelper.reposition(); |
203 }, | 204 }, |
204 | 205 |
205 /** | 206 /** |
206 * @param {!WebInspector.Event} event | 207 * @param {!WebInspector.Event} event |
207 */ | 208 */ |
208 _spectrumChanged: function(event) | 209 _spectrumChanged: function(event) |
209 { | 210 { |
210 this._muteColorProcessing = true; | 211 this._muteColorProcessing = true; |
211 var colorString = /** @type {string} */ (event.data); | 212 var colorString = /** @type {string} */ (event.data); |
212 this._currentSwatch.setColorText(colorString); | 213 this._currentSwatch.setColorText(colorString); |
213 this._textEditor.editRange(this._currentColorPosition.textRange, colorSt ring); | 214 this._textEditor.editRange(this._currentColorPosition.textRange, colorSt ring); |
214 this._currentColorPosition.color = WebInspector.Color.parse(colorString) ; | 215 this._currentColorPosition.color = WebInspector.Color.parse(colorString) ; |
215 this._currentColorPosition.textRange.endColumn = this._currentColorPosit ion.textRange.startColumn + colorString.length; | 216 this._currentColorPosition.textRange.endColumn = this._currentColorPosit ion.textRange.startColumn + colorString.length; |
216 }, | 217 }, |
217 | 218 |
218 _spectrumHidden: function() | 219 /** |
220 * @param {boolean} commitEdit | |
221 */ | |
222 _spectrumHidden: function(commitEdit) | |
219 { | 223 { |
220 this._muteColorProcessing = false; | |
221 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.SizeChan ged, this._spectrumResized, this); | 224 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.SizeChan ged, this._spectrumResized, this); |
222 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.ColorCha nged, this._spectrumChanged, this); | 225 this._spectrum.removeEventListener(WebInspector.Spectrum.Events.ColorCha nged, this._spectrumChanged, this); |
226 if (!commitEdit) | |
227 this._textEditor.editRange(this._currentColorPosition.textRange, thi s._originalColorText); | |
lushnikov
2016/07/21 22:58:35
will the undo stack make sense in this case?
flandy
2016/07/22 00:17:10
Good catch. Just calling CM.undo works better and
| |
223 delete this._spectrum; | 228 delete this._spectrum; |
229 delete this._currentSwatch; | |
230 delete this._currentColorPosition; | |
231 delete this._originalColorText; | |
232 this._muteColorProcessing = false; | |
224 this._updateColorSwatches(); | 233 this._updateColorSwatches(); |
225 }, | 234 }, |
226 | 235 |
227 /** | 236 /** |
228 * @override | 237 * @override |
229 */ | 238 */ |
230 onTextEditorContentSet: function() | 239 onTextEditorContentSet: function() |
231 { | 240 { |
232 WebInspector.UISourceCodeFrame.prototype.onTextEditorContentSet.call(thi s); | 241 WebInspector.UISourceCodeFrame.prototype.onTextEditorContentSet.call(thi s); |
233 if (!this._muteColorProcessing && Runtime.experiments.isEnabled("sourceC olorPicker")) | 242 if (!this._muteColorProcessing && Runtime.experiments.isEnabled("sourceC olorPicker")) |
(...skipping 16 matching lines...) Expand all Loading... | |
250 }, | 259 }, |
251 | 260 |
252 /** | 261 /** |
253 * @override | 262 * @override |
254 * @param {number} lineNumber | 263 * @param {number} lineNumber |
255 */ | 264 */ |
256 scrollChanged: function(lineNumber) | 265 scrollChanged: function(lineNumber) |
257 { | 266 { |
258 WebInspector.UISourceCodeFrame.prototype.scrollChanged.call(this, lineNu mber); | 267 WebInspector.UISourceCodeFrame.prototype.scrollChanged.call(this, lineNu mber); |
259 if (this._swatchPopoverHelper.isShowing()) | 268 if (this._swatchPopoverHelper.isShowing()) |
260 this._swatchPopoverHelper.hide(); | 269 this._swatchPopoverHelper.hide(true); |
261 }, | 270 }, |
262 | 271 |
263 __proto__: WebInspector.UISourceCodeFrame.prototype | 272 __proto__: WebInspector.UISourceCodeFrame.prototype |
264 } | 273 } |
265 | 274 |
266 /** | 275 /** |
267 * @constructor | 276 * @constructor |
268 * @param {!WebInspector.Color} color | 277 * @param {!WebInspector.Color} color |
269 * @param {number} lineNumber | 278 * @param {number} lineNumber |
270 * @param {number} startColumn | 279 * @param {number} startColumn |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 var propertyToken = this._backtrackPropertyToken(editor, prefixRange.sta rtLine, prefixRange.startColumn - 1); | 373 var propertyToken = this._backtrackPropertyToken(editor, prefixRange.sta rtLine, prefixRange.startColumn - 1); |
365 if (!propertyToken) | 374 if (!propertyToken) |
366 return this._simpleDelegate.wordsWithPrefix(editor, prefixRange, sub stituteRange); | 375 return this._simpleDelegate.wordsWithPrefix(editor, prefixRange, sub stituteRange); |
367 | 376 |
368 var line = editor.line(prefixRange.startLine); | 377 var line = editor.line(prefixRange.startLine); |
369 var tokenContent = line.substring(propertyToken.startColumn, propertyTok en.endColumn); | 378 var tokenContent = line.substring(propertyToken.startColumn, propertyTok en.endColumn); |
370 var keywords = WebInspector.CSSMetadata.keywordsForProperty(tokenContent ); | 379 var keywords = WebInspector.CSSMetadata.keywordsForProperty(tokenContent ); |
371 return keywords.startsWith(prefix); | 380 return keywords.startsWith(prefix); |
372 }, | 381 }, |
373 } | 382 } |
OLD | NEW |