From 17ba1732194a47648adf9aa63a13591e064c0122 Mon Sep 17 00:00:00 2001 From: abe33 Date: Mon, 15 Dec 2014 16:12:50 +0100 Subject: [PATCH] :bug: Fix dom reader failing to append the node outside render view --- lib/minimap-render-view.coffee | 6 ++++++ lib/mixins/dom-styles-reader.coffee | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/minimap-render-view.coffee b/lib/minimap-render-view.coffee index 2be2dd24..cbdc9e64 100644 --- a/lib/minimap-render-view.coffee +++ b/lib/minimap-render-view.coffee @@ -301,6 +301,12 @@ class MinimapRenderView extends ScrollView height: @getMinimapHeight() } + getDummyDOMRoot: (shadowRoot) -> + if shadowRoot + @minimapView.getEditorViewRoot() + else + @editorView + # Returns a pixel position corresponding to a character's screen # position. # diff --git a/lib/mixins/dom-styles-reader.coffee b/lib/mixins/dom-styles-reader.coffee index 1f5ee391..6d863c12 100644 --- a/lib/mixins/dom-styles-reader.coffee +++ b/lib/mixins/dom-styles-reader.coffee @@ -2,8 +2,6 @@ Mixin = require 'mixto' module.exports = class DOMStylesReader extends Mixin - @domStylesCache: {} - # Internal: This function insert a dummy element in the DOM to compute # its style, return the specified property, and remove the element # from the DOM. @@ -16,6 +14,8 @@ class DOMStylesReader extends Mixin # # Returns a {String} of the property value. retrieveStyleFromDom: (scopes, property, shadowRoot=true, cache=true) -> + @ensureCache() + key = scopes.join(' ') if cache and @constructor.domStylesCache[key]?[property]? @@ -45,10 +45,11 @@ class DOMStylesReader extends Mixin unless @dummyNode? @dummyNode = document.createElement('span') @dummyNode.style.visibility = 'hidden' - if shadowRoot - @minimapView.getEditorViewRoot().appendChild(@dummyNode) - else - @editorView.appendChild(@dummyNode) + + @getDummyDOMRoot(shadowRoot).appendChild(@dummyNode) + + ensureCache: -> + @constructor.domStylesCache ?= {} invalidateCache: -> @constructor.domStylesCache = {}