Implement split-left

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-03-19 09:22:13 -06:00
parent 9bd6751a46
commit 1437858241
2 changed files with 39 additions and 1 deletions

View File

@@ -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)", ->

View File

@@ -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')