From 405a918280e982a0b01608de37c1dc86c0ac273a Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sat, 9 Feb 2013 16:41:31 -0700 Subject: [PATCH] Never redraw when the font size changes on a detached editor When the font size changes and the editor is detached, it schedules itself to be redrawn the next time we're reattached rather than updating the display in a detached state. Detached display updates worked in the past because we didn't need to be on the DOM to determine horizontal and vertical positions once we had calculated dimensions once. So it worked to temporarily attach the editor when calculating new dimensions, and then continue updates even when it was detached. That now breaks because we can't ask for pixel positions if we aren't on the DOM. --- spec/app/editor-spec.coffee | 2 +- src/app/editor.coffee | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) 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 = $('