diff --git a/spec/app/file-finder-spec.coffee b/spec/app/file-finder-spec.coffee index 9f06aeb9c..3ffbb42a3 100644 --- a/spec/app/file-finder-spec.coffee +++ b/spec/app/file-finder-spec.coffee @@ -94,23 +94,3 @@ describe 'FileFinder', -> it "returns paths sorted by score of match against the given query", -> expect(finder.findMatches('ap')).toEqual ["app.coffee", "atom/app.coffee"] expect(finder.findMatches('a/ap')).toEqual ["atom/app.coffee"] - - describe "when it is removed", -> - input = null - - beforeEach -> - input = $$ -> @input value : "this has focus" - input.attachToDom() - input.focus() - expect(document.activeElement).toBe input[0] - - finder = new FileFinder(paths: []) - finder.attachToDom() - expect(document.activeElement).not.toBe input[0] - - afterEach -> - input.remove() - - it "returns focus to previous active element", -> - finder.remove() - expect(document.activeElement).toBe input[0] diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index 0bc567a48..264f0c6ca 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -44,6 +44,7 @@ describe "RootView", -> delete atom.windowStatesByWindowNumber[$windowNumber] it "stores its window state on the atom object by window number, then reassigns it next time the root view is constructed", -> + rootView.activeEditor().splitLeft() expectedWindowState = rootView.getWindowState() # simulate unload @@ -52,7 +53,9 @@ describe "RootView", -> # simulate reload newRootView = new RootView + expect(newRootView.getWindowState()).toEqual expectedWindowState + expect(newRootView.editors.length).toBe 2 describe "focus", -> it "can receive focus if there is no active editor, but otherwise hands off focus to the active editor", -> @@ -81,6 +84,8 @@ describe "RootView", -> editor3.setCursorScreenPosition([2, 3]) editor4.setBuffer(new Buffer(require.resolve 'fixtures/sample.txt')) editor4.setCursorScreenPosition([0, 2]) + rootView.attachToDom() + editor2.focus() panesHtml = rootView.panes.html() it "can reconstruct the split pane arrangement from the window state hash returned by getWindowState", -> @@ -112,6 +117,12 @@ describe "RootView", -> expect(editor3.width()).toBeGreaterThan 0 expect(editor4.width()).toBeGreaterThan 0 + # ensure correct editor is focused again + expect(editor2.isFocused).toBeTruthy() + expect(editor1.isFocused).toBeFalsy() + expect(editor3.isFocused).toBeFalsy() + expect(editor4.isFocused).toBeFalsy() + describe "split editor panes", -> editor1 = null diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 5292d567f..b50abd3e3 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -168,7 +168,7 @@ class Editor extends View @calculateDimensions() @hiddenInput.width(@charWidth) @setMaxLineLength() if @softWrap - @focus() + @focus() if @isFocused rootView: -> @parents('#root-view').view() @@ -227,12 +227,14 @@ class Editor extends View buffer = editorState.buffer ? new Buffer @editorStatesByBufferId[buffer.id] = editorState @setBuffer(buffer) + @isFocused = editorState.isFocused getEditorState: -> buffer: @buffer cursorScreenPosition: @getCursorScreenPosition().copy() scrollTop: @scroller.scrollTop() scrollLeft: @scroller.scrollLeft() + isFocused: @isFocused saveEditorStateForCurrentBuffer: -> @editorStatesByBufferId[@buffer.id] = @getEditorState() diff --git a/src/app/file-finder.coffee b/src/app/file-finder.coffee index a1cf9c165..c7f006bd7 100644 --- a/src/app/file-finder.coffee +++ b/src/app/file-finder.coffee @@ -16,7 +16,6 @@ class FileFinder extends View initialize: ({@paths, @selected}) -> requireStylesheet 'file-finder.css' @maxResults = 10 - @previousFocusedElement = $(document.activeElement) @populatePathList() @@ -44,10 +43,6 @@ class FileFinder extends View @selected(filePath) if filePath and @selected @remove() - remove: -> - super() - @previousFocusedElement.focus() - moveUp: -> @findSelectedLi() .filter(':not(:first-child)') diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index aacbd959b..1b9b10db2 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -192,3 +192,4 @@ class RootView extends View paths: relativePaths selected: (relativePath) => @open(relativePath) @append @fileFinder + @fileFinder.editor.focus()