From abcf71af8bb0d5227b4d3b9582ddec44554fe868 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 27 Apr 2012 18:08:30 -0600 Subject: [PATCH] Focus the root view when canceling the move dialog. This is temporary, because we really want to focus the tree view, but less annoying for now than losing focus entirely. --- spec/extensions/tree-view-spec.coffee | 11 ++++++++++- src/app/keymaps/tree-view.coffee | 1 + src/extensions/tree-view.coffee | 9 ++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/spec/extensions/tree-view-spec.coffee b/spec/extensions/tree-view-spec.coffee index a3575e070..00727c863 100644 --- a/spec/extensions/tree-view-spec.coffee +++ b/spec/extensions/tree-view-spec.coffee @@ -338,11 +338,20 @@ describe "TreeView", -> dirView.expand() expect(dirView.entries.children().length).toBe 0 + describe "when 'tree-view:cancel' is triggered on the move dialog", -> + it "removes the dialog and focuses root view", -> + rootView.attachToDom() + moveDialog.trigger 'tree-view:cancel' + expect(moveDialog.parent()).not.toExist() + expect(rootView.activeEditor().isFocused).toBeTruthy() + describe "when the move dialog's editor loses focus", -> - it "removes the dialog", -> + it "removes the dialog and focuses root view", -> rootView.attachToDom() rootView.focus() expect(moveDialog.parent()).not.toExist() + expect(rootView.activeEditor().isFocused).toBeTruthy() + # expect(rootView).toMatchSelector(':focus') describe "file system events", -> temporaryFilePath = null diff --git a/src/app/keymaps/tree-view.coffee b/src/app/keymaps/tree-view.coffee index d1457ff21..459e4e3f1 100644 --- a/src/app/keymaps/tree-view.coffee +++ b/src/app/keymaps/tree-view.coffee @@ -6,3 +6,4 @@ window.keymap.bindKeys '.tree-view' window.keymap.bindKeys '.move-dialog .mini.editor' 'enter': 'tree-view:confirm' + 'escape': 'tree-view:cancel' diff --git a/src/extensions/tree-view.coffee b/src/extensions/tree-view.coffee index 31fd1c11b..8ec2da739 100644 --- a/src/extensions/tree-view.coffee +++ b/src/extensions/tree-view.coffee @@ -163,8 +163,9 @@ class MoveDialog extends View initialize: (@project, @path) -> @editor.focus() - @editor.on 'focusout', => @remove() @on 'tree-view:confirm', => @confirm() + @on 'tree-view:cancel', => @cancel() + @editor.on 'focusout', => @remove() relativePath = @project.relativize(@path) @editor.setText(relativePath) @@ -175,3 +176,9 @@ class MoveDialog extends View confirm: -> fs.move(@path, @project.resolve(@editor.getText())) @remove() + $('#root-view').focus() + + cancel: -> + @remove() + $('#root-view').focus() +