as-authored rule editing
tromey opened this issue · 0 comments
tromey commented
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 anauthoredStyles
trait to indicate ifaddNewRule
accepts theeditAuthored
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 newcanSetRuleText
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 anauthoredText
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 textmodifySelector2
now takes a new optionaleditAuthored
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
emitsstylesheet-updated
when the style sheet has been edited- StyleRuleActor
emits
location-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.