mozilla/valence

as-authored rule editing

tromey opened this issue · 0 comments

We added "as-authored" editing to the rule view in https://bugzilla.mozilla.org/show_bug.cgi?id=984880
A few changes were made server-side to support this. Here's a quick rundown. I looked through styles.js and stylesheets.js to remember the changes, but be warned that this isn't necessarily definitive.

  • PageStyleActor has an authoredStyles trait to indicate if addNewRule accepts the editAuthored argument.
  • addNewRule takes an additional argument that, when true, means that the edit should be done by editing the style sheet text.
  • StyleRuleActor has a new canSetRuleText trait that is used to indicate authored editing. Authored editing is not available for element styles, only styles coming from style sheets
  • The style rule actor's form now has an authoredText property that holds the rule's text. Note that comments in the text must be preserved.
  • setRuleText is a new method on the style rule actor that is used to rewrite the rule's text
  • modifySelector2 now takes a new optional editAuthored parameter, which indicates whether selector modifications should be done by modifying the style sheet text

I can't recall which events are new and which we had to add for as-authored:

  • PageStyleActor emits stylesheet-updated when the style sheet has been edited
  • StyleRuleActoremitslocation-changed` when a rule's location changes

Finally, we changed the stylesheet actor to preserve style sheets even when the toolbox is closed. We did this using a weak map that maps from the style sheet object to the saved text. I think everything should work ok if you skip this step, though.