Bug 180890 - Web Inspector: Can't add a new class by editing class attribute in DOM outline
Summary: Web Inspector: Can't add a new class by editing class attribute in DOM outline
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:
 
Reported: 2017-12-15 16:05 PST by Nikita Vasilyev
Modified: 2018-03-20 01:22 PDT (History)
4 users (show)

See Also:


Attachments
[Image] Bug (37.88 KB, image/png)
2017-12-15 16:06 PST, Nikita Vasilyev
no flags Details
Patch (1.53 KB, patch)
2018-03-16 16:34 PDT, Nikita Vasilyev
no flags Details | Formatted Diff | Diff
Patch (1.64 KB, patch)
2018-03-19 15:24 PDT, Nikita Vasilyev
rniwa: review+
Details | Formatted Diff | Diff
Patch (1.63 KB, patch)
2018-03-20 00:19 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-12-15 16:05:04 PST
Web Inspector automatically adds a non-breaking space when adding a CSS class (via double-click or enter).
Because this chains the class name, it removes any styles. Also, the ` ` isn't visible unless you're editing via "Edit as HTML."

Steps to Reproduce:
1. Open Web Inspector
2. Find an HTML element that has a value in the class attribute
3. Double-click the class attribute (or press Enter)
4. Add "hello" to the beginning of the attribute value
5. Right click and select "Edit as HTML"
6. Notice the ` `

Expected Results:
I could double-click / enter to quickly add a class and it wouldn't automatically add a non-breaking space.

Observed Results:
It adds a non-breaking space, making the quick edit functionality useless.

<rdar://problem/34144628>
Comment 1 Nikita Vasilyev 2017-12-15 16:06:23 PST
Created attachment 329534 [details]
[Image] Bug
Comment 2 Nikita Vasilyev 2017-12-15 16:25:33 PST
Devin, if you're looking for more bugs to fix, this's a good one! If not, feel free to set it back to unassigned.
Comment 3 Nikita Vasilyev 2018-03-16 15:34:50 PDT
This happens only on certain class names.

Steps:
1. Open http://nv.github.io/webkit-inspector-bugs/styles-redesign/tests/color.html
2. Double-click on `class="item-1"`
3. Type "my-class " before the existing class name, so it looks like `class="my-class item-1"`
4. Press Enter

It looks like DOMAgent.setAttributesAsText *sometimes* converts spaces to &nbsp;.
Comment 4 Nikita Vasilyev 2018-03-16 16:33:37 PDT
(In reply to Nikita Vasilyev from comment #3)
> It looks like DOMAgent.setAttributesAsText *sometimes* converts spaces to
> &nbsp;.

No, nbsp's are coming from contentEditable.
Comment 5 Nikita Vasilyev 2018-03-16 16:34:00 PDT
Created attachment 335982 [details]
Patch
Comment 6 Nikita Vasilyev 2018-03-16 16:44:17 PDT
"ContentEditable: &nbsp; is forced on SPACE between text nodes"
https://bugs.chromium.org/p/chromium/issues/detail?id=310149
Fixed in Chromium on July 27, 2016 but appears to be unresolved in WebKit.
This makes we concerned about other places where we use contentEditable, such as the styles editor.
Comment 7 Nikita Vasilyev 2018-03-16 17:01:34 PDT
(In reply to Nikita Vasilyev from comment #5)
> Created attachment 335982 [details]
> Patch

To clarify, this patch makes it impossible to commit non-breaking spaces in HTML attributes and I'm fine with that. When would you want to add a non-breaking space in Web Inspector? I can't think of any common cases.
Comment 8 Nikita Vasilyev 2018-03-19 15:24:29 PDT
Created attachment 336078 [details]
Patch
Comment 9 Ryosuke Niwa 2018-03-19 21:19:33 PDT
Comment on attachment 336078 [details]
Patch

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

> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js:1069
> +        let nbspRegex = /\xA0/g;

Why not const?
Comment 10 Matt Baker 2018-03-19 23:36:28 PDT
Comment on attachment 336078 [details]
Patch

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

>> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js:1069
>> +        let nbspRegex = /\xA0/g;
> 
> Why not const?

This should be const.

We haven't settled on a convention for applying const in the WebInspector frontend. I think more widespread usage would be a benefit, but my thoughts on const-correctness come from C++, and I don't know how much of that applies to JS.
Comment 11 Nikita Vasilyev 2018-03-20 00:19:34 PDT
Created attachment 336107 [details]
Patch
Comment 12 WebKit Commit Bot 2018-03-20 01:22:08 PDT
Comment on attachment 336107 [details]
Patch

Clearing flags on attachment: 336107

Committed r229744: <https://trac.webkit.org/changeset/229744>
Comment 13 WebKit Commit Bot 2018-03-20 01:22:09 PDT
All reviewed patches have been landed.  Closing bug.