From 48d20ff1ecbed0b3a4f5cddec2da6707522eac9c Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 8 Jul 2014 11:45:24 -0600 Subject: [PATCH] Only remeasure char widths on stylesheet changes if editor is visible Fixes #2856 --- spec/editor-component-spec.coffee | 20 ++++++++++++++++++++ src/editor-component.coffee | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index bfbfd7895..5421f1f8f 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -1837,6 +1837,26 @@ describe "EditorComponent", -> line0Right = node.querySelector('.line > span:last-child').getBoundingClientRect().right expect(cursorLeft).toBe line0Right + describe "when stylesheets change while the editor is hidden", -> + it "does not re-measure character widths until the editor is shown again", -> + atom.config.set('editor.fontFamily', 'sans-serif') + + wrapperView.hide() + atom.themes.applyStylesheet 'test', """ + .function.js { + font-weight: bold; + } + """ + runSetImmediateCallbacks() + + wrapperView.show() + editor.setCursorBufferPosition([0, Infinity]) + runSetImmediateCallbacks() + + cursorLeft = node.querySelector('.cursor').getBoundingClientRect().left + line0Right = node.querySelector('.line > span:last-child').getBoundingClientRect().right + expect(cursorLeft).toBe line0Right + describe "when lines are changed while the editor is hidden", -> it "does not measure new characters until the editor is shown again", -> editor.setText('') diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 7a92e7024..7fd3c8fbb 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -801,7 +801,10 @@ EditorComponent = React.createClass @characterWidthRemeasurementRequested = true setImmediate => @characterWidthRemeasurementRequested = false - @remeasureCharacterWidths() + if @state.visible + @remeasureCharacterWidths() + else + @remeasureCharacterWidthsWhenShown = true remeasureCharacterWidths: -> @remeasureCharacterWidthsWhenShown = false