From 2d4c4b39307eea0366201dafd432da096e27e860 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Jan 2013 12:51:29 -0800 Subject: [PATCH] Support opening a path into a new split editor --- src/app/editor.coffee | 20 ++++---- .../spec/fuzzy-finder-spec.coffee | 49 +++++++++++++++++++ .../fuzzy-finder/src/fuzzy-finder.coffee | 24 ++++++++- 3 files changed, 82 insertions(+), 11 deletions(-) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 3a45aab30..b4a88884f 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -649,20 +649,20 @@ class Editor extends View getFontSize: -> @fontSize - newSplitEditor: -> - new Editor { editSession: @activeEditSession.copy() } + newSplitEditor: (editSession) -> + new Editor { editSession: editSession ? @activeEditSession.copy() } - splitLeft: -> - @pane()?.splitLeft(@newSplitEditor()).wrappedView + splitLeft: (editSession) -> + @pane()?.splitLeft(@newSplitEditor(editSession)).wrappedView - splitRight: -> - @pane()?.splitRight(@newSplitEditor()).wrappedView + splitRight: (editSession) -> + @pane()?.splitRight(@newSplitEditor(editSession)).wrappedView - splitUp: -> - @pane()?.splitUp(@newSplitEditor()).wrappedView + splitUp: (editSession) -> + @pane()?.splitUp(@newSplitEditor(editSession)).wrappedView - splitDown: -> - @pane()?.splitDown(@newSplitEditor()).wrappedView + splitDown: (editSession) -> + @pane()?.splitDown(@newSplitEditor(editSession)).wrappedView pane: -> @parent('.pane').view() diff --git a/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee b/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee index 1306dcf1f..aba066a63 100644 --- a/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee +++ b/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee @@ -273,3 +273,52 @@ describe 'FuzzyFinder', -> runs -> expect(rootView.project.getFilePaths).toHaveBeenCalled() + + describe "opening a path into a split", -> + beforeEach -> + rootView.attachToDom() + + describe "when an editor is active", -> + it "opens the path by splitting the active editor left", -> + editor = rootView.getActiveEditor() + spyOn(editor, "splitLeft").andCallThrough() + expect(rootView.find('.editor').length).toBe 1 + rootView.trigger 'fuzzy-finder:toggle-buffer-finder' + finder.miniEditor.trigger 'editor:split-left' + expect(rootView.find('.editor').length).toBe 2 + expect(editor.splitLeft).toHaveBeenCalled() + expect(rootView.getActiveEditor()).not.toBe editor + expect(rootView.getActiveEditor().getPath()).toBe editor.getPath() + + it "opens the path by splitting the active editor right", -> + editor = rootView.getActiveEditor() + spyOn(editor, "splitRight").andCallThrough() + expect(rootView.find('.editor').length).toBe 1 + rootView.trigger 'fuzzy-finder:toggle-buffer-finder' + finder.miniEditor.trigger 'editor:split-right' + expect(rootView.find('.editor').length).toBe 2 + expect(editor.splitRight).toHaveBeenCalled() + expect(rootView.getActiveEditor()).not.toBe editor + expect(rootView.getActiveEditor().getPath()).toBe editor.getPath() + + it "opens the path by splitting the active editor down", -> + editor = rootView.getActiveEditor() + spyOn(editor, "splitDown").andCallThrough() + expect(rootView.find('.editor').length).toBe 1 + rootView.trigger 'fuzzy-finder:toggle-buffer-finder' + finder.miniEditor.trigger 'editor:split-down' + expect(rootView.find('.editor').length).toBe 2 + expect(editor.splitDown).toHaveBeenCalled() + expect(rootView.getActiveEditor()).not.toBe editor + expect(rootView.getActiveEditor().getPath()).toBe editor.getPath() + + it "opens the path by splitting the active editor up", -> + editor = rootView.getActiveEditor() + spyOn(editor, "splitUp").andCallThrough() + expect(rootView.find('.editor').length).toBe 1 + rootView.trigger 'fuzzy-finder:toggle-buffer-finder' + finder.miniEditor.trigger 'editor:split-up' + expect(rootView.find('.editor').length).toBe 2 + expect(editor.splitUp).toHaveBeenCalled() + expect(rootView.getActiveEditor()).not.toBe editor + expect(rootView.getActiveEditor().getPath()).toBe editor.getPath() diff --git a/src/packages/fuzzy-finder/src/fuzzy-finder.coffee b/src/packages/fuzzy-finder/src/fuzzy-finder.coffee index 1cc20c488..1e2566c15 100644 --- a/src/packages/fuzzy-finder/src/fuzzy-finder.coffee +++ b/src/packages/fuzzy-finder/src/fuzzy-finder.coffee @@ -24,6 +24,15 @@ class FuzzyFinder extends SelectList @observeConfig 'fuzzy-finder.ignoredNames', (ignoredNames) => @projectPaths = null + @miniEditor.command 'editor:split-left', => + @splitOpenPath (editor, session) -> editor.splitLeft(session) + @miniEditor.command 'editor:split-right', => + @splitOpenPath (editor, session) -> editor.splitRight(session) + @miniEditor.command 'editor:split-down', => + @splitOpenPath (editor, session) -> editor.splitDown(session) + @miniEditor.command 'editor:split-up', => + @splitOpenPath (editor, session) -> editor.splitUp(session) + itemForElement: (path) -> $$ -> @li => @@ -40,10 +49,23 @@ class FuzzyFinder extends SelectList if folder = fs.directory(path) @span "- #{folder}/", class: 'directory' + openPath: (path) -> + @rootView.open(path, {@allowActiveEditorChange}) if path + + splitOpenPath: (fn) -> + path = @getSelectedElement() + return unless path + + editor = @rootView.getActiveEditor() + if editor + fn(editor, @rootView.project.buildEditSessionForPath(path)) + else + @openPath(path) + confirmed : (path) -> return unless path.length @cancel() - @rootView.open(path, {@allowActiveEditorChange}) + @openPath(path) cancelled: -> @miniEditor.setText('')