Bug 40522 - Web Inspector: up/down keys are not treating hex numbers properly while editing styles.
Summary: Web Inspector: up/down keys are not treating hex numbers properly while editi...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Alexander Pavlov (apavlov)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-12 05:07 PDT by Pavel Feldman
Modified: 2011-04-01 06:17 PDT (History)
8 users (show)

See Also:


Attachments
[PATCH] Suggested solution (11.70 KB, patch)
2011-04-01 05:22 PDT, Alexander Pavlov (apavlov)
yurys: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Feldman 2010-06-12 05:07:47 PDT
What steps will reproduce the problem?
1. Open any page
2. Find a colored element (such as a link)
3. Hit "inspect element"
4. Click the hex css color field and use arrow up/arrow down. 

What is the expected result?
Good question, but something different.

What happens instead?
A value of 00C for example on crbug.com will increment to 0.1C ... 100C and over. It can also go 
negative with -0.1C ... -100C and so on. 
Either way, it shouldnt give invalid hex values.
Comment 1 Alexander Pavlov (apavlov) 2011-04-01 05:22:04 PDT
Created attachment 87845 [details]
[PATCH] Suggested solution

The color editing works as follows:
- Up/Down -> change the first (least significant) digit
- PageUp/PageDown -> change the second digit

Shift results in the change of the second or the third digit, respectively (which completely covers the #RGB case).
Comment 2 Yury Semikhatsky 2011-04-01 05:54:50 PDT
Comment on attachment 87845 [details]
[PATCH] Suggested solution

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

> LayoutTests/inspector/styles/up-down-numerics-and-colors.html:6
> +    color: #FF2;

Can you use #FAF or something that will overflow on increment?

> LayoutTests/inspector/styles/up-down-numerics-and-colors.html:25
> +            section = WebInspector.panels.elements.sidebarPanes.styles.sections[0][2];

Missing "var" before section declaration. Also could we get the section in a more reliable way?

> Source/WebCore/inspector/front-end/StylesSidebarPane.js:1650
> +        matches = /(.*?#)([\da-fA-F]+)(.*)/.exec(wordString);

.*?# - > .*#

> Source/WebCore/inspector/front-end/StylesSidebarPane.js:1658
> +            matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString);

.*? - > .*

> Source/WebCore/inspector/front-end/StylesSidebarPane.js:1740
> +        var arrowKeyPressed = (event.keyIdentifier === "Up" || event.keyIdentifier === "Down");

These shortcuts look overcomplicated too me, could we use a simpler scheme?
Comment 3 Alexander Pavlov (apavlov) 2011-04-01 06:11:44 PDT
(In reply to comment #2)
> (From update of attachment 87845 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=87845&action=review
> 
> > LayoutTests/inspector/styles/up-down-numerics-and-colors.html:6
> > +    color: #FF2;
> 
> Can you use #FAF or something that will overflow on increment?

Done. Tested for the most significant 'F' increment.

> > LayoutTests/inspector/styles/up-down-numerics-and-colors.html:25
> > +            section = WebInspector.panels.elements.sidebarPanes.styles.sections[0][2];
> 
> Missing "var" before section declaration. Also could we get the section in a more reliable way?

Fixed "var". I also don't know a better way to get sections, and we use this approach elsewhere.

> > Source/WebCore/inspector/front-end/StylesSidebarPane.js:1650
> > +        matches = /(.*?#)([\da-fA-F]+)(.*)/.exec(wordString);
> 
> .*?# - > .*#

Fixed.

> > Source/WebCore/inspector/front-end/StylesSidebarPane.js:1658
> > +            matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString);
> 
> .*? - > .*

Alas, this results in a greedy match (i.e. 188 will be parsed as (18)(8)).

> > Source/WebCore/inspector/front-end/StylesSidebarPane.js:1740
> > +        var arrowKeyPressed = (event.keyIdentifier === "Up" || event.keyIdentifier === "Down");
> 
> These shortcuts look overcomplicated too me, could we use a simpler scheme?

We've agreed that this is consistent with the current numeric property value inc/dec's.
Comment 4 Alexander Pavlov (apavlov) 2011-04-01 06:17:52 PDT
Committing to http://svn.webkit.org/repository/webkit/trunk ...
        M       LayoutTests/ChangeLog
        M       LayoutTests/http/tests/inspector/inspector-test.js
        A       LayoutTests/inspector/styles/up-down-numerics-and-colors-expected.txt
        A       LayoutTests/inspector/styles/up-down-numerics-and-colors.html
        M       Source/WebCore/ChangeLog
        M       Source/WebCore/inspector/front-end/StylesSidebarPane.js
Committed r82674