Open Bug 1225591 Opened 9 years ago Updated 2 years ago

[markup-view] Attributes order when adding multiple attributes

Categories

(DevTools :: Inspector, defect, P3)

defect

Tracking

(Not tracked)

People

(Reporter: grisha, Unassigned)

References

Details

(Whiteboard: [btpp-backlog])

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0
Build ID: 20151110004043

Steps to reproduce:

After adding multiple attributes in editable attribute, they are ordered in a strange way.
Discussed in bug 1093593 comment 11 and in bug 1093593 comment 16.

Example:
> <div a b c>
Editing "a" attribute:
> <div [d a b] b c>
Will be:
> <div a d c b>
But we need ordering like in NamedNodeMap:
> <div a b c d>

This example shows 2 cases:
1. Attributes before editable are added next to it.
    New attribute "d" was added after editable attribute "a". Same behavior if "d" already exists.
2. Attributes after editable goes to the end. 
    Already existed attribute "b" was added to the end.

Position oddities comes from _applyAttributes with aAttrNode argument:
https://dxr.mozilla.org/mozilla-central/source/devtools/client/markupview/markup-view.js#2836
For case #1 aAttrNode.nextSibling moves attributes after editable attribute.
For case #2 aAttrNode.nextSibling is undefined, because editable attribute was recreated. Attributes goes to the end.

At first sight I think we can manage position for created / updated attributes in _createAttribute with simple logic:
1. If attribute exists, update it without position change.
2. Otherwise add attribute to the end.
3. Do not forget about "id" and "class'. They goes first.
It is how NamedNodeMap works, with exception for "id" and "class".

And we have quite unexpected NamedNodeMap for the first example (listed right after "|"):
> <div a b c> | a, b c
Editing "a" attribute:
> <div [d a b] b c>
Will be:
> <div a d c b> | b, c, d, a (while a, b, c, d is expected)

After committing changes, attribute which was edited is removed:
https://dxr.mozilla.org/mozilla-central/source/devtools/client/markupview/markup-view.js#2767
It's good and simple solution, but with this we have different NamedNodeMap behavior.
Component: Untriaged → Developer Tools: Inspector
Status: UNCONFIRMED → NEW
Depends on: 1093593
Ever confirmed: true
Triaging (filter on CLIMBING SHOES).
Priority: -- → P3
Whiteboard: [btpp-backlog]
Product: Firefox → DevTools
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.