Bug 170184

Summary: Web Inspector: tabbing in Styles sidebar is broken when additional ":" and ";" are in the property value
Product: WebKit Reporter: Devin Rousso <hi>
Component: Web InspectorAssignee: Devin Rousso <hi>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, inspector-bugzilla-changes, mattbaker
Priority: P2    
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch
mattbaker: review+
Patch none

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.