Bug 170184 - Web Inspector: tabbing in Styles sidebar is broken when additional ":" and ";" are in the property value
Summary: Web Inspector: tabbing in Styles sidebar is broken when additional ":" and ";...
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: Devin Rousso
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-28 10:44 PDT by Devin Rousso
Modified: 2017-04-09 22:26 PDT (History)
3 users (show)

See Also:


Attachments
Patch (5.88 KB, patch)
2017-03-28 11:48 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (14.25 KB, patch)
2017-04-07 19:04 PDT, Devin Rousso
mattbaker: review+
Details | Formatted Diff | Diff
Patch (13.96 KB, patch)
2017-04-09 21:44 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2017-03-28 10:44:53 PDT
If you add `background-image: url(https://webkit.org/wp-content/themes/webkit/images/webkit.svg);` to any style and try tabbing, the highlight will get stuck on "url(https".  This is most likely because the way it searches for ":" and ";" is very dumb, simply finding the first instance in the remaining text.
Comment 1 Devin Rousso 2017-03-28 11:48:54 PDT
Created attachment 305618 [details]
Patch
Comment 2 Matt Baker 2017-03-29 10:49:10 PDT
Comment on attachment 305618 [details]
Patch

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

Since we have so many editing issues in the styles sidebar, I think we should break out the range matching into a utility method (that handles plain text, not CodeMirror) so we can write tests.

> Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js:408
> +    _rangeForNextNameOrValue(codeMirror, cursor, text) {

Style: put open brace on newline.
Comment 3 Matt Baker 2017-03-29 10:49:35 PDT
Comment on attachment 305618 [details]
Patch

r- until we have tests
Comment 4 Devin Rousso 2017-04-07 19:04:08 PDT
Created attachment 306562 [details]
Patch
Comment 5 Matt Baker 2017-04-09 09:29:46 PDT
Comment on attachment 306562 [details]
Patch

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

r=me, nice tests!

> Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js:408
> +    _rangeForNextNameOrValue(codeMirror, cursor, text) {

Nit: put open brace on its own line.

> LayoutTests/inspector/unit-tests/text-utilities-expected.txt:21
> +PASS: Next highlight range of "foo: url(http://baz);" starting at index 5 is [5, 20]

A couple thoughts on the test output:

1) Highlight is a higher-level UI concept, and doesn't appear in the name of the utility method. It's confusing unless you know how this is going to be used in the UI. Maybe use name/value instead.
2) It is hard to tell from the resulting range bounds alone where an error occurred. What do you think about including the resulting substring in the output? Something like:

        Next name/value token in "foo: url(http://baz);" starting at index 5 is "url(http://baz)" (5, 20)

> LayoutTests/inspector/unit-tests/text-utilities.html:14
> +                InspectorTest.expectShallowEqual(WebInspector.rangeForNextCSSNameOrValue(text, index), expected, `Next highlight range of "${text}" starting at index ${index} is [${expected.from}, ${expected.to}]`);

Style: I think this would read a little better as:

function testValid(text, index, expected) {
    let actual = WebInspector.rangeForNextCSSNameOrValue(text, index);
    InspectorTest.expectShallowEqual(actual, expected, ...);
}
Comment 6 Devin Rousso 2017-04-09 21:44:01 PDT
Created attachment 306647 [details]
Patch
Comment 7 WebKit Commit Bot 2017-04-09 22:26:48 PDT
Comment on attachment 306647 [details]
Patch

Clearing flags on attachment: 306647

Committed r215170: <http://trac.webkit.org/changeset/215170>
Comment 8 WebKit Commit Bot 2017-04-09 22:26:49 PDT
All reviewed patches have been landed.  Closing bug.