Bug 133997

Summary: Web Inspector: Hexadecimal color values in all CSS editors are purple when they should be blue
Product: WebKit Reporter: Jonathan Wells <jonowells>
Component: Web InspectorAssignee: Jonathan Wells <jonowells>
Status: RESOLVED FIXED    
Severity: Normal CC: bunhere, cdumez, commit-queue, graouts, gyuyoung.kim, joepeck, sergio, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
[PATCH] Attempted fix.
none
[PATCH] Attempted fix with cleanup.
joepeck: review+, joepeck: commit-queue-
[PATCH] Reviewed fix with small edits. none

Description Jonathan Wells 2014-06-17 13:48:43 PDT
CodeMirror 4 regression.
Comment 1 Radar WebKit Bug Importer 2014-06-17 13:49:18 PDT
<rdar://problem/17348008>
Comment 2 Jonathan Wells 2014-07-01 15:36:39 PDT
Created attachment 234206 [details]
[PATCH] Attempted fix.
Comment 3 Joseph Pecoraro 2014-07-01 15:51:38 PDT
Comment on attachment 234206 [details]
[PATCH] Attempted fix.

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

> Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js:185
> +        const hexColorRegex = /(#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3})/g;

I would suggest:

    /#(?:[0-9a-fA-F){6}|[0-9a-fA-F){3})/g

Changes:

  1. Share the "#" because it is common
  2. Use a non-captured group (?:...) instead of (...) because you don't reference the group

> Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js:203
> -            if (style === "atom" && stream.current() === "url") {
> +            if (style === "atom" && hexColorRegex.test(stream.current()))
> +                style = style + " hex-color";
> +            else if (style === "atom" && stream.current() === "url") {
>                  // If the current text is "url" then we should expect the next string token to be a link.
>                  state._expectLink = true;
>              } else if (state._expectLink && style === "atom") {

Nit: There are a lot of style === "atom" checks here. Can we pull that out into a bool above the if/else chain?

Also, it looks like you add style "hex-color" but the CSS below checks for .cm-hex-color. Does the ".cm-" prefix automatically get added somewhere?
Comment 4 Joseph Pecoraro 2014-07-01 15:58:20 PDT
(In reply to comment #3)
> (From update of attachment 234206 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=234206&action=review
> 
> > Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js:185
> > +        const hexColorRegex = /(#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3})/g;
> 
> I would suggest:
> 
>     /#(?:[0-9a-fA-F){6}|[0-9a-fA-F){3})/g


In person discussion, we may want to gracefully handle something like:

    #12345678

So we might want to throw a \b on the end of the regex and not match this.
Comment 5 Jonathan Wells 2014-07-01 16:07:38 PDT
I agree.
Comment 6 Jonathan Wells 2014-07-01 16:12:50 PDT
Created attachment 234210 [details]
[PATCH] Attempted fix with cleanup.

Cleaned up the logic and saved the regexp test for later to lower the number of calls to the RegExp API.
Comment 7 Joseph Pecoraro 2014-07-01 16:17:32 PDT
Comment on attachment 234210 [details]
[PATCH] Attempted fix with cleanup.

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

Awesome! r=me

> Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js:185
> +        const hexColorRegex = /(#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3})\b/g;

Nit: I think we still want at least the (?:...) non-capture group. As that can be a performance win with Regexs.
Comment 8 Jonathan Wells 2014-07-01 16:32:45 PDT
Created attachment 234215 [details]
[PATCH] Reviewed fix with small edits.
Comment 9 WebKit Commit Bot 2014-07-01 17:13:48 PDT
Comment on attachment 234215 [details]
[PATCH] Reviewed fix with small edits.

Clearing flags on attachment: 234215

Committed r170681: <http://trac.webkit.org/changeset/170681>
Comment 10 WebKit Commit Bot 2014-07-01 17:13:52 PDT
All reviewed patches have been landed.  Closing bug.