Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorTextMarkers.js (242601 => 242602)
--- trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorTextMarkers.js 2019-03-07 18:03:41 UTC (rev 242601)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorTextMarkers.js 2019-03-07 19:11:52 UTC (rev 242602)
@@ -23,7 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-function createCodeMirrorTextMarkers(type, pattern, matchFunction, codeMirror, range, callback)
+function createCodeMirrorTextMarkers({codeMirror, range, type, pattern, matchFunction, allowedTokens, callback})
{
var createdMarkers = [];
var start = range instanceof WI.TextRange ? range.startLine : 0;
@@ -56,7 +56,7 @@
// We're not interested if the value is not inside a keyword.
var tokenType = codeMirror.getTokenTypeAt(from);
- if (tokenType && !tokenType.includes("keyword")) {
+ if (tokenType && !tokenType.includes("keyword") && (!allowedTokens || !allowedTokens.test(tokenType))) {
match = pattern.exec(lineContent);
continue;
}
@@ -82,10 +82,10 @@
return createdMarkers;
}
-function createCodeMirrorColorTextMarkers(codeMirror, range, callback)
+function createCodeMirrorColorTextMarkers(codeMirror, range, options = {})
{
// Matches rgba(0, 0, 0, 0.5), rgb(0, 0, 0), hsl(), hsla(), #fff, #ffff, #ffffff, #ffffffff, white
- let colorRegex = /((?:rgb|hsl)a?\([^)]+\)|#[0-9a-fA-F]{8}|#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3,4}|\b\w+\b(?![-.]))/g;
+ const pattern = /((?:rgb|hsl)a?\([^)]+\)|#[0-9a-fA-F]{8}|#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3,4}|\b\w+\b(?![-.]))/g;
function matchFunction(lineContent, match) {
if (!lineContent || !lineContent.length)
return false;
@@ -118,10 +118,10 @@
return !(match.index > 0 && /[-.\"\']/.test(lineContent[match.index - 1]));
}
- return createCodeMirrorTextMarkers("Color", colorRegex, matchFunction, codeMirror, range, callback);
+ return createCodeMirrorTextMarkers({codeMirror, range, type: "Color", pattern, matchFunction, ...options});
}
-function createCodeMirrorGradientTextMarkers(codeMirror, range, callback)
+function createCodeMirrorGradientTextMarkers(codeMirror, range, options = {})
{
var createdMarkers = [];
@@ -181,7 +181,7 @@
createdMarkers.push(marker);
if (typeof callback === "function")
- callback(marker, gradient, gradientString);
+ options.callback(marker, gradient, gradientString);
match = gradientRegex.exec(lineContent);
}
@@ -190,14 +190,14 @@
return createdMarkers;
}
-function createCodeMirrorCubicBezierTextMarkers(codeMirror, range, callback)
+function createCodeMirrorCubicBezierTextMarkers(codeMirror, range, options = {})
{
- var cubicBezierRegex = /(cubic-bezier\([^)]+\)|\b\w+\b(?:-\b\w+\b){0,2})/g;
- return createCodeMirrorTextMarkers("CubicBezier", cubicBezierRegex, null, codeMirror, range, callback);
+ const pattern = /(cubic-bezier\([^)]+\)|\b\w+\b(?:-\b\w+\b){0,2})/g;
+ return createCodeMirrorTextMarkers({codeMirror, range, type: "CubicBezier", pattern, ...options});
}
-function createCodeMirrorSpringTextMarkers(codeMirror, range, callback)
+function createCodeMirrorSpringTextMarkers(codeMirror, range, options = {})
{
- const springRegex = /(spring\([^)]+\))/g;
- return createCodeMirrorTextMarkers("Spring", springRegex, null, codeMirror, range, callback);
+ const pattern = /(spring\([^)]+\))/g;
+ return createCodeMirrorTextMarkers({codeMirror, range, type: "Spring", pattern, ...options});
}
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js (242601 => 242602)
--- trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js 2019-03-07 18:03:41 UTC (rev 242601)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js 2019-03-07 19:11:52 UTC (rev 242602)
@@ -41,14 +41,12 @@
this._swatchElement.classList.add("inline-swatch", this._type.split("-").lastValue);
- this._boundSwatchElementClicked = null;
-
if (readOnly)
this._swatchElement.classList.add("read-only");
else {
switch (this._type) {
case WI.InlineSwatch.Type.Color:
- this._swatchElement.title = WI.UIString("Click to select a color. Shift-click to switch color formats.");
+ this._swatchElement.title = WI.UIString("Click to select a color\nShift-click to switch color formats");
break;
case WI.InlineSwatch.Type.Gradient:
this._swatchElement.title = WI.UIString("Edit custom gradient");
@@ -60,7 +58,7 @@
this._swatchElement.title = WI.UIString("Edit \u201Cspring\u201D function");
break;
case WI.InlineSwatch.Type.Variable:
- this._swatchElement.title = WI.UIString("View variable value");
+ this._swatchElement.title = WI.UIString("Click to view variable value\nShift-click to replace variable with value");
break;
case WI.InlineSwatch.Type.Image:
this._swatchElement.title = WI.UIString("View Image");
@@ -70,8 +68,7 @@
break;
}
- this._boundSwatchElementClicked = this._swatchElementClicked.bind(this);
- this._swatchElement.addEventListener("click", this._boundSwatchElementClicked);
+ this._swatchElement.addEventListener("click", this._swatchElementClicked.bind(this));
if (this._type === WI.InlineSwatch.Type.Color)
this._swatchElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this));
}
@@ -109,12 +106,14 @@
if (!this._valueEditor)
return;
- if (typeof this._valueEditor.removeListeners === "function")
+ if (this._valueEditor.removeListeners)
this._valueEditor.removeListeners();
- if (this._boundSwatchElementClicked)
- this._swatchElement.addEventListener("click", this._boundSwatchElementClicked);
+ if (this._valueEditor instanceof WI.Object)
+ this._valueEditor.removeEventListener(null, null, this);
+ this._valueEditor = null;
+
this.dispatchEventToListeners(WI.InlineSwatch.Event.Deactivated);
}
@@ -149,19 +148,30 @@
_swatchElementClicked(event)
{
- this.dispatchEventToListeners(WI.InlineSwatch.Event.BeforeClicked);
+ event.stop();
- if (this._type === WI.InlineSwatch.Type.Color && event.shiftKey && this._value) {
- let nextFormat = this._value.nextFormat();
- console.assert(nextFormat);
- if (!nextFormat)
+ if (event.shiftKey && this._value) {
+ if (this._type === WI.InlineSwatch.Type.Color) {
+ let nextFormat = this._value.nextFormat();
+ console.assert(nextFormat);
+ if (nextFormat) {
+ this._value.format = nextFormat;
+ this._updateSwatch();
+ }
return;
+ }
- this._value.format = nextFormat;
- this._updateSwatch();
- return;
+ if (this._type === WI.InlineSwatch.Type.Variable) {
+ // Force the swatch to replace the displayed text with the variable's value.
+ this._swatchElement.remove();
+ this._updateSwatch();
+ return;
+ }
}
+ if (this._valueEditor)
+ return;
+
let bounds = WI.Rect.rectFromClientRect(this._swatchElement.getBoundingClientRect());
let popover = new WI.Popover(this);
@@ -225,9 +235,6 @@
popover.content = this._valueEditor.element;
popover.present(bounds.pad(2), [WI.RectEdge.MIN_X]);
- if (this._boundSwatchElementClicked)
- this._swatchElement.removeEventListener("click", this._boundSwatchElementClicked);
-
this.dispatchEventToListeners(WI.InlineSwatch.Event.Activated);
let value = this._value || this._fallbackValue();
@@ -248,10 +255,27 @@
this._valueEditor.spring = value;
break;
- case WI.InlineSwatch.Type.Variable:
- this._valueEditor.codeMirror.setValue(value);
+ case WI.InlineSwatch.Type.Variable: {
+ let codeMirror = this._valueEditor.codeMirror;
+ codeMirror.setValue(value);
+
+ const range = null;
+ function optionsForType(type) {
+ return {
+ allowedTokens: /\btag\b/,
+ callback(marker, valueObject, valueString) {
+ let swatch = new WI.InlineSwatch(type, valueObject, true);
+ codeMirror.setUniqueBookmark({line: 0, ch: 0}, swatch.element);
+ }
+ };
+ }
+ createCodeMirrorColorTextMarkers(codeMirror, range, optionsForType(WI.InlineSwatch.Type.Color));
+ createCodeMirrorGradientTextMarkers(codeMirror, range, optionsForType(WI.InlineSwatch.Type.Gradient));
+ createCodeMirrorCubicBezierTextMarkers(codeMirror, range, optionsForType(WI.InlineSwatch.Type.Bezier));
+ createCodeMirrorSpringTextMarkers(codeMirror, range, optionsForType(WI.InlineSwatch.Type.Spring));
break;
}
+ }
}
_valueEditorValueDidChange(event)
@@ -378,7 +402,6 @@
};
WI.InlineSwatch.Event = {
- BeforeClicked: "inline-swatch-before-clicked",
ValueChanged: "inline-swatch-value-changed",
Activated: "inline-swatch-activated",
Deactivated: "inline-swatch-deactivated",
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js (242601 => 242602)
--- trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js 2019-03-07 18:03:41 UTC (rev 242601)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js 2019-03-07 19:11:52 UTC (rev 242602)
@@ -500,11 +500,13 @@
innerElement.textContent = value;
this._handleValueChange();
+
+ if (type === WI.InlineSwatch.Type.Variable)
+ this._renderValue(this._property.rawValue);
}, this);
if (this._delegate && typeof this._delegate.stylePropertyInlineSwatchActivated === "function") {
swatch.addEventListener(WI.InlineSwatch.Event.Activated, () => {
- this._swatchActive = true;
this._delegate.stylePropertyInlineSwatchActivated();
});
}
@@ -511,7 +513,6 @@
if (this._delegate && typeof this._delegate.stylePropertyInlineSwatchDeactivated === "function") {
swatch.addEventListener(WI.InlineSwatch.Event.Deactivated, () => {
- this._swatchActive = false;
this._delegate.stylePropertyInlineSwatchDeactivated();
});
}
@@ -518,12 +519,6 @@
tokenElement.append(swatch.element, innerElement);
- // Prevent the value from editing when clicking on the swatch.
- swatch.element.addEventListener("click", (event) => {
- if (this._swatchActive || event.shiftKey)
- event.stop();
- });
-
return tokenElement;
}