diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index e9c68d638..5a6e4df1f 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -633,7 +633,7 @@ describe "Editor", -> expect(editor.renderedLines.find(".line").length).toBeGreaterThan originalLineCount describe "when the editor is detached", -> - it "updates the font-size correctly and recalculates the dimensions by placing the rendered lines on the DOM", -> + it "redraws the editor according to the new font size when it is reattached", -> rootView.attachToDom() rootView.height(200) rootView.width(200) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 48690aab6..2fd0086ce 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -55,6 +55,7 @@ class Editor extends View pendingChanges: null newCursors: null newSelections: null + redrawOnReattach: false @deserialize: (state, rootView) -> editor = new Editor(mini: state.mini, deserializing: true) @@ -447,7 +448,9 @@ class Editor extends View @syncCursorAnimations() afterAttach: (onDom) -> - return if @attached or not onDom + return unless onDom + @redraw() if @redrawOnReattach + return if @attached @attached = true @calculateDimensions() @hiddenInput.width(@charWidth) @@ -726,7 +729,12 @@ class Editor extends View headTag.append styleTag styleTag.text(".editor {font-size: #{fontSize}px}") - @redraw() + + if @isOnDom() + @redraw() + else + @redrawOnReattach = true + getFontSize: -> parseInt(@css("font-size")) @@ -745,7 +753,9 @@ class Editor extends View getFontFamily: -> @css("font-family") redraw: -> + return unless @hasParent() return unless @attached + @redrawOnReattach = false @calculateDimensions() @updatePaddingOfRenderedLines() @updateLayerDimensions() @@ -842,10 +852,6 @@ class Editor extends View @overlayer.append(view) calculateDimensions: -> - if not @isOnDom() - detachedEditorParent = _.last(@parents()) ? this - $(document.body).append(detachedEditorParent) - fragment = $('