From 1437858241c5993d75c08f73dd0bc5947bc2010f Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 19 Mar 2012 09:22:13 -0600 Subject: [PATCH] Implement split-left --- spec/atom/root-view-spec.coffee | 27 +++++++++++++++++++++++++++ src/atom/editor.coffee | 13 ++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/spec/atom/root-view-spec.coffee b/spec/atom/root-view-spec.coffee index ab06f7d75..e1fb742b9 100644 --- a/spec/atom/root-view-spec.coffee +++ b/spec/atom/root-view-spec.coffee @@ -62,6 +62,33 @@ describe "RootView", -> expect(editor1.lines.find('.line:first').text()).toContain 'ABC' expect(editor2.lines.find('.line:first').text()).toContain 'ABC' + describe "when split-left is triggered on the editor", -> + it "places the a new editor to the left of the current editor in a .horizontal div, and focuses the new editor", -> + rootView.attachToDom() + + expect(rootView.find('.horizontal')).not.toExist() + + editor1 = rootView.find('.editor').view() + editor1.setBuffer(new Buffer(require.resolve 'fixtures/sample.js')) + editor1.setCursorScreenPosition([3, 2]) + editor1.trigger 'split-left' + + expect(rootView.find('.horizontal')).toExist() + expect(rootView.find('.horizontal .editor').length).toBe 2 + expect(rootView.find('.horizontal .editor:eq(1)').view()).toBe editor1 + editor2 = rootView.find('.horizontal .editor:eq(0)').view() + expect(editor2.buffer).toBe editor1.buffer + expect(editor2.getCursorScreenPosition()).toEqual [3, 2] + expect(editor1).toHaveClass 'split' + expect(editor2).toHaveClass 'split' + + expect(editor1.has(':focus')).not.toExist() + expect(editor2.has(':focus')).toExist() + + # insertion reflected in both buffers + editor1.buffer.insert([0, 0], 'ABC') + expect(editor1.lines.find('.line:first').text()).toContain 'ABC' + expect(editor2.lines.find('.line:first').text()).toContain 'ABC' describe ".addPane(view)", -> it "adds the given view to the rootView (at the bottom by default)", -> diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 51243f244..cdfe83472 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -72,6 +72,7 @@ class Editor extends View 'alt-meta-w': 'toggle-soft-wrap' 'alt-meta-f': 'fold-selection' 'alt-meta-right': 'split-right' + 'alt-meta-left': 'split-left' @on 'save', => @save() @on 'move-right', => @moveCursorRight() @@ -93,6 +94,7 @@ class Editor extends View @on 'toggle-soft-wrap', => @toggleSoftWrap() @on 'fold-selection', => @foldSelection() @on 'split-right', => @splitRight() + @on 'split-left', => @splitLeft() buildCursorAndSelection: -> @cursor = new Cursor(this) @@ -407,13 +409,22 @@ class Editor extends View @renderer.logLines() splitRight: -> + @splitVertically(true) + + splitLeft: -> + @splitVertically(false) + + splitVertically: (right) -> unless @parent().is('.horizontal') horizontal = $$ -> @div class: 'horizontal' horizontal.insertBefore(this).append(this.detach()) editor = new Editor({@buffer}) editor.setCursorScreenPosition(@getCursorScreenPosition()) - @after(editor) + if right + @after(editor) + else + @before(editor) @addClass 'split' editor.addClass('split')