diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 39406fd29..b8e5c524b 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -16,6 +16,7 @@ describe "Editor", -> editor.autoIndent = false editor.enableKeymap() editor.setBuffer(buffer) + editor.isFocused = true describe "text rendering", -> it "creates a line element for each line in the buffer with the html-escaped text of the line", -> @@ -769,6 +770,11 @@ describe "Editor", -> expect(editor.getCursorScreenPosition()).toEqual(row: 1, column: 7) expect(editor.lines.find('.line:eq(1)')).toHaveText editor.getCurrentBufferLine() + it "does not update the cursor position if the editor is not focused", -> + editor.isFocused = false + editor.buffer.insert([5, 0], 'blah') + expect(editor.getCursorScreenPosition()).toEqual [0, 0] + describe "when there is a selection", -> it "replaces the selected text with the typed text", -> editor.selection.setBufferRange(new Range([1, 6], [2, 4])) @@ -925,6 +931,16 @@ describe "Editor", -> expect(editor).not.toMatchSelector ':focus' expect(editor.hiddenInput).toMatchSelector ':focus' + describe "when the hidden input is focused / unfocused", -> + it "assigns the isFocused flag on the editor", -> + editor.attachToDom() + editor.isFocused = false + editor.hiddenInput.focus() + expect(editor.isFocused).toBeTruthy() + + editor.hiddenInput.focusout() + expect(editor.isFocused).toBeFalsy() + describe "construction", -> it "assigns an empty buffer and correctly handles text input (regression coverage)", -> editor = new Editor diff --git a/spec/atom/root-view-spec.coffee b/spec/atom/root-view-spec.coffee index 4f47f64d5..ab06f7d75 100644 --- a/spec/atom/root-view-spec.coffee +++ b/spec/atom/root-view-spec.coffee @@ -35,7 +35,7 @@ describe "RootView", -> describe "split editor panes", -> describe "when split-right is triggered on the editor", -> - fit "places the a new editor to the right of the current editor in a .horizontal div, and focuses the new editor", -> + it "places the a new editor to the right of the current editor in a .horizontal div, and focuses the new editor", -> rootView.attachToDom() expect(rootView.find('.horizontal')).not.toExist() diff --git a/spec/atom/selection-spec.coffee b/spec/atom/selection-spec.coffee index 8d5d80887..dc001aef5 100644 --- a/spec/atom/selection-spec.coffee +++ b/spec/atom/selection-spec.coffee @@ -10,6 +10,7 @@ describe "Selection", -> editor = new Editor editor.enableKeymap() editor.setBuffer(buffer) + editor.isFocused = true selection = editor.selection describe ".setBufferRange(range)", -> diff --git a/spec/atom/vim-mode-spec.coffee b/spec/atom/vim-mode-spec.coffee index 2399bd937..a064fb801 100644 --- a/spec/atom/vim-mode-spec.coffee +++ b/spec/atom/vim-mode-spec.coffee @@ -7,6 +7,7 @@ describe "VimMode", -> beforeEach -> editor = new Editor editor.enableKeymap() + editor.isFocused = true vimMode = new VimMode(editor) describe "initialize", -> diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index c5a5ab3a0..51243f244 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -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)