Bug 1466816 - Ensure rule models are available to the font editor even if the Rule view is not visible. r=gl
MozReview-Commit-ID: 2OHQp3cfk08
--- a/devtools/client/inspector/fonts/fonts.js
+++ b/devtools/client/inspector/fonts/fonts.js
@@ -54,17 +54,18 @@ const REGISTERED_AXES_TO_FONT_PROPERTIES
const REGISTERED_AXES = Object.keys(REGISTERED_AXES_TO_FONT_PROPERTIES);
class FontInspector {
constructor(inspector, window) {
this.document = window.document;
this.inspector = inspector;
this.nodeComputedStyle = {};
this.pageStyle = this.inspector.pageStyle;
- this.ruleView = this.inspector.getPanel("ruleview").view;
+ this.ruleViewTool = this.inspector.getPanel("ruleview");
+ this.ruleView = this.ruleViewTool.view;
this.selectedRule = null;
this.store = this.inspector.store;
// Map CSS property names and variable font axis names to methods that write their
// corresponding values to the appropriate TextProperty from the Rule view.
// Values of variable font registered axes may be written to CSS font properties under
// certain cascade circumstances and platform support. @see `getWriterForAxis(axis)`
this.writers = new Map();
@@ -658,16 +659,24 @@ class FontInspector {
if (!this.nodeComputedStyle) {
this.store.dispatch(resetFontEditor());
return;
}
// Clear any references to writer methods and CSS declarations because the node's
// styles may have changed since the last font editor refresh.
this.writers.clear();
+
+ // If the Rule panel is not visible, the selected element's rule models may not have
+ // been created yet. For example, in 2-pane mode when Fonts is opened as the default
+ // panel. Select the current node to force the Rule view to create the rule models.
+ if (!this.ruleViewTool.isSidebarActive()) {
+ await this.ruleView.selectElement(node, false);
+ }
+
// Select the node's inline style as the rule where to write property value changes.
this.selectedRule =
this.ruleView.rules.find(rule => rule.domRule.type === ELEMENT_STYLE);
const properties = this.getFontProperties();
const familiesDeclared =
properties["font-family"].split(",")
.map(font => font.replace(/["']+/g, "").trim());