mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 16:08:24 +03:00
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.
This commit is contained in:
parent
81145eb35f
commit
405a918280
@ -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)
|
||||
|
@ -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 = $('<pre class="line" style="position: absolute; visibility: hidden;"><span>x</span></div>')
|
||||
@renderedLines.append(fragment)
|
||||
|
||||
@ -857,8 +863,6 @@ class Editor extends View
|
||||
@height(@lineHeight) if @mini
|
||||
fragment.remove()
|
||||
|
||||
$(detachedEditorParent).detach()
|
||||
|
||||
updateLayerDimensions: ->
|
||||
@gutter.calculateWidth()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user