diff --git a/spec/extensions/tree-view-spec.coffee b/spec/extensions/tree-view-spec.coffee index 0d5b8d780..7ae13d532 100644 --- a/spec/extensions/tree-view-spec.coffee +++ b/spec/extensions/tree-view-spec.coffee @@ -60,6 +60,19 @@ describe "TreeView", -> expect(newTreeView.selectedEntry()).toMatchSelector(".file:contains(sample.js)") expect(newTreeView.find(".directory:contains(zed)")).toHaveClass("expanded") + it "restores the focus state of the tree view", -> + treeView.attachToDom() + treeView.focus() + expect(treeView).toMatchSelector ':focus' + + newRootView = RootView.deserialize(rootView.serialize()) + rootView.remove() + newRootView.attachToDom() + newRootView.activateExtension(TreeView) + + newTreeView = newRootView.find(".tree-view").view() + expect(newTreeView).toMatchSelector ':focus' + describe "when a directory's disclosure arrow is clicked", -> it "expands / collapses the associated directory", -> subdir = treeView.root.find('.entries > li:contains(dir/)').view() diff --git a/src/extensions/tree-view/tree-view.coffee b/src/extensions/tree-view/tree-view.coffee index 6c5cb3602..2e7a4dd05 100644 --- a/src/extensions/tree-view/tree-view.coffee +++ b/src/extensions/tree-view/tree-view.coffee @@ -30,9 +30,11 @@ class TreeView extends View treeView = new TreeView(rootView) treeView.root.deserializeEntryExpansionStates(state.directoryExpansionStates) treeView.selectEntryForPath(state.selectedPath) + treeView.focusAfterAttach = state.hasFocus treeView root: null + focusAfterAttach: false initialize: (@rootView) -> @on 'click', '.entry', (e) => @@ -54,9 +56,13 @@ class TreeView extends View @on 'tree-view:unfocus', => @rootView.activeEditor()?.focus() @rootView.on 'tree-view:focus', => this.focus() + afterAttach: (onDom) -> + @focus() if @focusAfterAttach + serialize: -> directoryExpansionStates: @root.serializeEntryExpansionStates() selectedPath: @selectedEntry()?.getPath() + hasFocus: @is(':focus') deactivate: -> @root.unwatchEntries()