Bug 111036 - Web Inspector: Empty attribute name/value pair added in Elements panel should be removed
Summary: Web Inspector: Empty attribute name/value pair added in Elements panel should...
Status: RESOLVED MOVED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Vivek Galatage
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-27 21:16 PST by Vivek Galatage
Modified: 2014-12-13 10:40 PST (History)
9 users (show)

See Also:


Attachments
Patch (3.46 KB, patch)
2013-02-27 21:19 PST, Vivek Galatage
no flags Details | Formatted Diff | Diff
Patch (1.65 KB, patch)
2013-03-01 02:33 PST, Vivek Galatage
no flags Details | Formatted Diff | Diff
Patch (1.92 KB, patch)
2013-03-01 02:56 PST, Vivek Galatage
no flags Details | Formatted Diff | Diff
Patch (2.04 KB, patch)
2013-03-01 03:08 PST, Vivek Galatage
apavlov: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vivek Galatage 2013-02-27 21:16:44 PST
Steps:
1. Open the Elements panel
2. Try adding a new attribute using either way i.e. context menu, pressing tab key etc.
3. See that an editor is presented for editing the attribute name, value pair
4. Without any text change, simply commit the change by pressing either enter key or focus out event.
5. Repeat this for 4-5 times.

Acutal outcome:
The tree outline is shown with the empty spaces.

Expected outcome:
If the attribute name/value pair contents are empty, the list item in the elements tree outline shouldn't be shown with white spaces.

Patch follows.
Comment 1 Vivek Galatage 2013-02-27 21:19:34 PST
Created attachment 190646 [details]
Patch
Comment 2 Pavel Feldman 2013-03-01 01:14:01 PST
Comment on attachment 190646 [details]
Patch

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

> Source/WebCore/inspector/front-end/ElementsTreeOutline.js:-1057
> -        

I try to not mix changes to semantics with formatting changes.

> Source/WebCore/inspector/front-end/ElementsTreeOutline.js:1551
> +        if (attributeName.trim().length === 0 && newText.trim().length === 0)

You should move this check to above the representedObject.setAttribute call to further emphasize you don't call setAttribute in that case. Also, moveToNextAttribute should be the last line of this method since it is a completion callback.
Comment 3 Vivek Galatage 2013-03-01 01:21:13 PST
Comment on attachment 190646 [details]
Patch

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

Thank you Pavel.

>> Source/WebCore/inspector/front-end/ElementsTreeOutline.js:-1057
>> -        
> 
> I try to not mix changes to semantics with formatting changes.

Its my Sublime settings to auto trim the trailing spaces which caused these changes. Sure I will disable them.

>> Source/WebCore/inspector/front-end/ElementsTreeOutline.js:1551
>> +        if (attributeName.trim().length === 0 && newText.trim().length === 0)
> 
> You should move this check to above the representedObject.setAttribute call to further emphasize you don't call setAttribute in that case. Also, moveToNextAttribute should be the last line of this method since it is a completion callback.

Sure.
Comment 4 Vivek Galatage 2013-03-01 02:33:08 PST
Created attachment 190914 [details]
Patch
Comment 5 Pavel Feldman 2013-03-01 02:45:13 PST
Comment on attachment 190914 [details]
Patch

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

> Source/WebCore/inspector/front-end/ElementsTreeOutline.js:1588
> +        if (attributeName.trim().length === 0 && newText.trim().length === 0)

it'd be great if it was showing that setAttribute is not called:

if (!attributeName.trim() && !newText.trim()) {
    element.removeSelf();
    moveToNextAttributeIfNeeded.call(this);
    return;
}

if (oldText !== newText) {
    this.representedObject.setAttribute(attributeName, newText, moveToNextAttributeIfNeeded.bind(this));
    return;
}

moveToNextAttributeIfNeeded.call(this);
Comment 6 Vivek Galatage 2013-03-01 02:56:59 PST
Created attachment 190917 [details]
Patch
Comment 7 Vivek Galatage 2013-03-01 02:59:00 PST
Comment on attachment 190917 [details]
Patch

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

> Source/WebCore/inspector/front-end/ElementsTreeOutline.js:1590
> +        if (!emptyNameValuePair && (oldText !== newText))

I understand, we use the early bailout, but I thought this is mostly the first block which would be hit most of the times. Hence added the '!' case first.
Comment 8 Pavel Feldman 2013-03-01 03:06:21 PST
Comment on attachment 190917 [details]
Patch

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

>> Source/WebCore/inspector/front-end/ElementsTreeOutline.js:1590
>> +        if (!emptyNameValuePair && (oldText !== newText))
> 
> I understand, we use the early bailout, but I thought this is mostly the first block which would be hit most of the times. Hence added the '!' case first.

To my taste, these nested conditions referring to the emptyNameValuePair are the opposite of readability. The three guards that I was suggesting are way more user-friendly.
Comment 9 Vivek Galatage 2013-03-01 03:08:58 PST
Created attachment 190919 [details]
Patch
Comment 10 Vivek Galatage 2013-03-01 03:09:53 PST
(In reply to comment #8)

> To my taste, these nested conditions referring to the emptyNameValuePair are the opposite of readability. The three guards that I was suggesting are way more user-friendly.

Agreed. I realized it after submitting the patch. Sorry for these many versions :)
Comment 11 Alexander Pavlov (apavlov) 2013-03-04 05:32:04 PST
Comment on attachment 190919 [details]
Patch

Please add a test, as agreed upon over IRC.
Comment 12 Vivek Galatage 2013-04-07 21:28:34 PDT
(In reply to comment #11)
> (From update of attachment 190919 [details])
> Please add a test, as agreed upon over IRC.

I was not able to draft a test case correctly for the above case. Can we land this change without the test case as its only a UI related minor feature?
Comment 13 Brian Burg 2014-12-13 10:40:09 PST
Re-filed over here:

https://bugs.webkit.org/show_bug.cgi?id=139623

The bug does not occur for multiple spaces any more.