Bug 1500947 - (Part 3) Update indices of tracked declarations when one is removed; r=pbro

Depends on D11209

We need to take care when deleting a declaration. This means shifting the indexes of declarations which follow it in the CSS rule. To do this, we iterate over all tracked added/removed declarations and make sure to decrement their index if it is larger than the index of the deleted one.

The Rule view and specialized editors do not support inserting declarations at any other position other than at the end of the existing declarations list. For now, it is safe to assume all newly added declarations will not shift any tracked indexes. But we will need to handle this for other use cases, like the Style Editor or manual editing of element style attributes.

MozReview-Commit-ID: InrNbsNsqz6

Differential Revision: https://phabricator.services.mozilla.com/D11318
This commit is contained in:
Razvan Caliman
2018-11-13 09:00:48 +00:00
parent c1eaf987dc
commit be2b453167
6 changed files with 90 additions and 5 deletions

View File

@@ -921,7 +921,7 @@ RuleRewriter.prototype = {
if (isEnabled) {
this.modifications.push({ type: "set", index, name, value: decl.value, priority });
} else {
this.modifications.push({ type: "remove", index, name, priority });
this.modifications.push({ type: "disable", index, name });
}
},