mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user