Bug 178176 - Web Inspector: Styles Redesign: apply syntax highlighting to property values
Summary: Web Inspector: Styles Redesign: apply syntax highlighting to property values
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nikita Vasilyev
URL:
Keywords: InRadar
Depends on:
Blocks: 124779
  Show dependency treegraph
 
Reported: 2017-10-11 11:24 PDT by Nikita Vasilyev
Modified: 2017-10-16 19:25 PDT (History)
4 users (show)

See Also:


Attachments
Patch (6.94 KB, patch)
2017-10-11 19:45 PDT, Nikita Vasilyev
no flags Details | Formatted Diff | Diff
[Image] With patch applied (56.21 KB, image/png)
2017-10-11 19:46 PDT, Nikita Vasilyev
no flags Details
Patch (6.91 KB, patch)
2017-10-12 18:06 PDT, Nikita Vasilyev
no flags Details | Formatted Diff | Diff
Patch (8.96 KB, patch)
2017-10-14 14:28 PDT, Nikita Vasilyev
no flags Details | Formatted Diff | Diff
[Image] Long URI truncated (34.66 KB, image/png)
2017-10-14 14:29 PDT, Nikita Vasilyev
no flags Details
Patch (8.90 KB, patch)
2017-10-16 18:45 PDT, Nikita Vasilyev
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Vasilyev 2017-10-11 11:24:32 PDT
Chrome DevTools only highlight URLs:
  - url(foo.png)
  - url('foo.png')
  - url("foo.png")

At the very least we should do the same, but it would be also nice to highlight:

Strings:
  - content: 'blah'
  - font-family: "Myriad Set Pro", "Helvetica Neue", sans-serif;

Variables (highlight the --my-var part):
  - var(--my-var)

Non matching pair characters:
  - content: 'blah
  - font-family: "Myriad Set Pro, "Helvetica Neue", sans-serif;
  - calc(var(--my-var + 5)

---

It's possible to feed CodeMirror a CSS string and get a list of tokens back. There's no need to write our own parser.

https://codemirror.net/doc/manual.html#modeapi

<rdar://problem/33526532>
Comment 1 Nikita Vasilyev 2017-10-11 19:45:53 PDT
Created attachment 323508 [details]
Patch

This patch highlights links and CSS strings. I think it's a good start.
Comment 2 Nikita Vasilyev 2017-10-11 19:46:30 PDT
Created attachment 323509 [details]
[Image] With patch applied
Comment 3 Nikita Vasilyev 2017-10-12 18:06:55 PDT
Created attachment 323615 [details]
Patch
Comment 4 Nikita Vasilyev 2017-10-14 14:28:26 PDT
Created attachment 323820 [details]
Patch
Comment 5 Nikita Vasilyev 2017-10-14 14:29:49 PDT
Created attachment 323821 [details]
[Image] Long URI truncated

I addressed Bug 124779 - Web Inspector: Styles: Truncate long URLs (e.g. base64)
in this patch since it was pretty straightforward to do once we detect URL tokens.

Reduction page: http://nv.github.io/webkit-inspector-bugs/styles-redesign/tests/base64.html

I truncated URLs over 150 characters. This is the same length as in Chrome DevTools.

I've learned that there's no pure-CSS way to truncate an inline element :(
Comment 6 Matt Baker 2017-10-16 18:15:50 PDT
Comment on attachment 323820 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=323820&action=review

Looking good, just a minor correction and some nits.

> Source/WebInspectorUI/ChangeLog:26
> +        Highlight links and CSS strings in values when isn't editing.

Type: when not editing.

> Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js:686
> +    let cssRule = `*{X:${cssValue}}`;

I was going to suggest a different label for the fake property name, to make ita little more obvious, but then the ignore column index would need to change, and it just gets harder to figure out (and more regression prone).

How about just replacing the magic number 4 with a const, which can be defined after the definition of `cssRule`. Then the meaning of each will be reinforced.

> Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js:695
> +            // Ignore '*{X:'

This comment could move to be inline with the definition of the const mentioned above.

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:244
> +                let maxLength = 150;

Just to make it stand out, I'd move this to the top of the function:

_renderValue(value)
{
    const maxValueLength = 150;

    ...
}

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:247
> +            } else

You can remove the else, since both branches return.

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js:82
> +        if (this._delegate && typeof this._delegate.spreadsheetTextFieldWillStartEditing)

=== "function"
Comment 7 Nikita Vasilyev 2017-10-16 18:25:37 PDT
Comment on attachment 323820 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=323820&action=review

>> Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js:686
>> +    let cssRule = `*{X:${cssValue}}`;
> 
> I was going to suggest a different label for the fake property name, to make ita little more obvious, but then the ignore column index would need to change, and it just gets harder to figure out (and more regression prone).
> 
> How about just replacing the magic number 4 with a const, which can be defined after the definition of `cssRule`. Then the meaning of each will be reinforced.

What about:

    const prefix = "*{X:";
    let cssRule = prefix + cssValue + "}";

>> Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js:695
>> +            // Ignore '*{X:'
> 
> This comment could move to be inline with the definition of the const mentioned above.

...and

    if (column < prefix.length)

?

>> Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js:82
>> +        if (this._delegate && typeof this._delegate.spreadsheetTextFieldWillStartEditing)
> 
> === "function"

Whoops!
Comment 8 Nikita Vasilyev 2017-10-16 18:45:27 PDT
Created attachment 323968 [details]
Patch
Comment 9 Matt Baker 2017-10-16 18:58:18 PDT
Comment on attachment 323968 [details]
Patch

r=me
Comment 10 WebKit Commit Bot 2017-10-16 19:25:19 PDT
Comment on attachment 323968 [details]
Patch

Clearing flags on attachment: 323968

Committed r223453: <https://trac.webkit.org/changeset/223453>
Comment 11 WebKit Commit Bot 2017-10-16 19:25:20 PDT
All reviewed patches have been landed.  Closing bug.