Bug 1466816 - Ensure rule models are available to the font editor even if the Rule view is not visible. r=gl draft
authorRazvan Caliman <rcaliman@mozilla.com>
Wed, 27 Jun 2018 20:26:00 +0200
changeset 811534 e902ec7a3592a48dcbbf0160604666822ed89902
parent 811302 9c7bb8874337c2d40aef3d9945b10490a5115188
push id114331
push userbmo:rcaliman@mozilla.com
push dateWed, 27 Jun 2018 18:26:27 +0000
reviewersgl
bugs1466816
milestone63.0a1
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
devtools/client/inspector/fonts/fonts.js
--- 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());