Don't move the cursor on buffer change unless the editor is focused

Add a boolean isFocused flag to editor that is assigned when the hidden input gains / loses focus. This makes it easier in specs because we can treat the editor as if its focused without having to add it to the DOM. It's also a bit more abstract.
This commit is contained in:
Corey Johnson & Nathan Sobo
2012-03-19 09:04:39 -06:00
parent 2903126047
commit 9bd6751a46
5 changed files with 27 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ class Editor extends View
renderer: null
autoIndent: null
lineCache: null
isFocused: false
initialize: ({buffer}) ->
requireStylesheet 'editor.css'
@@ -105,6 +106,9 @@ class Editor extends View
@hiddenInput.focus()
false
@hiddenInput.on 'focus', => @isFocused = true
@hiddenInput.on 'focusout', => @isFocused = false
@on 'mousedown', '.fold-placeholder', (e) =>
@destroyFold($(e.currentTarget).attr('foldId'))
false
@@ -178,7 +182,7 @@ class Editor extends View
@loadEditSessionForBuffer(@buffer)
@buffer.on "change.editor#{@id}", (e) => @cursor.bufferChanged(e)
@buffer.on "change.editor#{@id}", (e) => @handleBufferChange(e)
@renderer.on 'change', (e) => @handleRendererChange(e)
loadEditSessionForBuffer: (buffer) ->
@@ -192,6 +196,9 @@ class Editor extends View
@editSession.scrollTop = @scrollTop()
@editSession.scrollLeft = @horizontalScroller.scrollLeft()
handleBufferChange: (e) ->
@cursor.bufferChanged(e) if @isFocused
handleRendererChange: (e) ->
{ oldRange, newRange } = e
unless newRange.isSingleLine() and newRange.coversSameRows(oldRange)