From 7d147dd2ce891aac35156b2d53168c5661e66150 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 21 Feb 2013 10:52:21 -0700 Subject: [PATCH] Make Pane handle split commands instead of Editor --- spec/app/editor-spec.coffee | 23 ----------------------- src/app/editor.coffee | 15 ++++----------- src/app/keymaps/atom.cson | 6 ++++++ src/app/keymaps/editor.cson | 4 ---- src/app/pane.coffee | 4 ++++ 5 files changed, 14 insertions(+), 38 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 1aa43f983..edcb4d13c 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -384,29 +384,6 @@ describe "Editor", -> editor.scrollTop(50) expect(editor.scrollTop()).toBe 50 - describe "split methods", -> - describe "when inside a pane", -> - fakePane = null - beforeEach -> - fakePane = { splitUp: jasmine.createSpy('splitUp').andReturn({}), remove: -> } - spyOn(editor, 'pane').andReturn(fakePane) - - it "calls the corresponding split method on the containing pane with a new editor containing a copy of the active edit session", -> - editor.edit project.buildEditSession("sample.txt") - editor.splitUp() - expect(fakePane.splitUp).toHaveBeenCalled() - [newEditor] = fakePane.splitUp.argsForCall[0] - expect(newEditor.editSessions.length).toEqual 1 - expect(newEditor.activeEditSession.buffer).toBe editor.activeEditSession.buffer - newEditor.remove() - - describe "when not inside a pane", -> - it "does not split the editor, but doesn't throw an exception", -> - editor.splitUp() - editor.splitDown() - editor.splitLeft() - editor.splitRight() - describe "editor:attached event", -> it 'only triggers an editor:attached event when it is first added to the DOM', -> openHandler = jasmine.createSpy('openHandler') diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 9187e8d8f..1bc4ed8db 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -172,10 +172,6 @@ class Editor extends View 'editor:fold-current-row': @foldCurrentRow 'editor:unfold-current-row': @unfoldCurrentRow 'editor:fold-selection': @foldSelection - 'editor:split-left': @splitLeft - 'editor:split-right': @splitRight - 'editor:split-up': @splitUp - 'editor:split-down': @splitDown 'editor:show-next-buffer': @loadNextEditSession 'editor:show-buffer-1': => @setActiveEditSessionIndex(0) if @editSessions[0] 'editor:show-buffer-2': => @setActiveEditSessionIndex(1) if @editSessions[1] @@ -789,20 +785,17 @@ class Editor extends View @updateLayerDimensions() @requestDisplayUpdate() - newSplitEditor: (editSession) -> - new Editor { editSession: editSession ? @activeEditSession.copy() } - splitLeft: (editSession) -> - @pane()?.splitLeft(@newSplitEditor(editSession)).currentItem + @pane()?.splitLeft() splitRight: (editSession) -> - @pane()?.splitRight(@newSplitEditor(editSession)).currentItem + @pane()?.splitRight() splitUp: (editSession) -> - @pane()?.splitUp(@newSplitEditor(editSession)).currentItem + @pane()?.splitUp() splitDown: (editSession) -> - @pane()?.splitDown(@newSplitEditor(editSession)).currentItem + @pane()?.splitDown() pane: -> @closest('.pane').view() diff --git a/src/app/keymaps/atom.cson b/src/app/keymaps/atom.cson index 680f25c17..d2a16ebff 100644 --- a/src/app/keymaps/atom.cson +++ b/src/app/keymaps/atom.cson @@ -30,6 +30,12 @@ 'ctrl-tab': 'window:focus-next-pane' 'ctrl-meta-f': 'window:toggle-full-screen' +'.pane': + 'ctrl-|': 'pane:split-right' + 'ctrl-w v': 'pane:split-right' + 'ctrl--': 'pane:split-down' + 'ctrl-w s': 'pane:split-down' + '.tool-panel': 'meta-escape': 'tool-panel:unfocus' 'escape': 'core:close' diff --git a/src/app/keymaps/editor.cson b/src/app/keymaps/editor.cson index 467119136..b072a462b 100644 --- a/src/app/keymaps/editor.cson +++ b/src/app/keymaps/editor.cson @@ -15,10 +15,6 @@ 'ctrl-{': 'editor:fold-all' 'ctrl-}': 'editor:unfold-all' 'alt-meta-ctrl-f': 'editor:fold-selection' - 'ctrl-|': 'editor:split-right' - 'ctrl-w v': 'editor:split-right' - 'ctrl--': 'editor:split-down' - 'ctrl-w s': 'editor:split-down' 'shift-tab': 'editor:outdent-selected-rows' 'meta-[': 'editor:outdent-selected-rows' 'meta-]': 'editor:indent-selected-rows' diff --git a/src/app/pane.coffee b/src/app/pane.coffee index ebad81482..2cf3f7ef5 100644 --- a/src/app/pane.coffee +++ b/src/app/pane.coffee @@ -22,6 +22,10 @@ class Pane extends View @command 'pane:show-next-item', @showNextItem @command 'pane:show-previous-item', @showPreviousItem + @command 'pane:split-left', => @splitLeft() + @command 'pane:split-right', => @splitRight() + @command 'pane:split-up', => @splitUp() + @command 'pane:split-down', => @splitDown() @on 'focus', => @viewForCurrentItem().focus() getItems: ->