mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Enhance pane split methods. Spec them in pane-spec.
When a pane is split, it attempts to make a copy of its current item if no items are passed to the split method. When splitting, multiple items can also be passed to the constructor of the new pane.
This commit is contained in:
committed by
probablycorey
parent
45eec6a8ff
commit
0c2a5f273c
@@ -3,14 +3,16 @@ Pane = require 'pane'
|
||||
{$$} = require 'space-pen'
|
||||
|
||||
describe "Pane", ->
|
||||
[view1, view2, editSession1, editSession2, pane] = []
|
||||
[container, view1, view2, editSession1, editSession2, pane] = []
|
||||
|
||||
beforeEach ->
|
||||
container = $$ -> @div id: 'panes'
|
||||
view1 = $$ -> @div id: 'view-1', 'View 1'
|
||||
view2 = $$ -> @div id: 'view-2', 'View 2'
|
||||
editSession1 = project.buildEditSession('sample.js')
|
||||
editSession2 = project.buildEditSession('sample.txt')
|
||||
pane = new Pane(view1, editSession1, view2, editSession2)
|
||||
container.append(pane)
|
||||
|
||||
describe ".initialize(items...)", ->
|
||||
it "displays the first item in the pane", ->
|
||||
@@ -109,6 +111,61 @@ describe "Pane", ->
|
||||
pane.focus()
|
||||
expect(focusHandler).toHaveBeenCalled()
|
||||
|
||||
describe "split methods", ->
|
||||
[view3, view4] = []
|
||||
beforeEach ->
|
||||
pane.showItem(editSession1)
|
||||
view3 = $$ -> @div id: 'view-3', 'View 3'
|
||||
view4 = $$ -> @div id: 'view-4', 'View 4'
|
||||
|
||||
describe "splitRight(items...)", ->
|
||||
it "builds a row if needed, then appends a new pane after itself", ->
|
||||
# creates the new pane with a copy of the current item if none are given
|
||||
pane2 = pane.splitRight()
|
||||
expect(container.find('.row .pane').toArray()).toEqual [pane[0], pane2[0]]
|
||||
expect(pane2.items).toEqual [editSession1]
|
||||
expect(pane2.currentItem).not.toBe editSession1 # it's a copy
|
||||
|
||||
pane3 = pane2.splitRight(view3, view4)
|
||||
expect(pane3.getItems()).toEqual [view3, view4]
|
||||
expect(container.find('.row .pane').toArray()).toEqual [pane[0], pane2[0], pane3[0]]
|
||||
|
||||
describe "splitRight(items...)", ->
|
||||
it "builds a row if needed, then appends a new pane before itself", ->
|
||||
# creates the new pane with a copy of the current item if none are given
|
||||
pane2 = pane.splitLeft()
|
||||
expect(container.find('.row .pane').toArray()).toEqual [pane2[0], pane[0]]
|
||||
expect(pane2.items).toEqual [editSession1]
|
||||
expect(pane2.currentItem).not.toBe editSession1 # it's a copy
|
||||
|
||||
pane3 = pane2.splitLeft(view3, view4)
|
||||
expect(pane3.getItems()).toEqual [view3, view4]
|
||||
expect(container.find('.row .pane').toArray()).toEqual [pane3[0], pane2[0], pane[0]]
|
||||
|
||||
describe "splitDown(items...)", ->
|
||||
it "builds a column if needed, then appends a new pane after itself", ->
|
||||
# creates the new pane with a copy of the current item if none are given
|
||||
pane2 = pane.splitDown()
|
||||
expect(container.find('.column .pane').toArray()).toEqual [pane[0], pane2[0]]
|
||||
expect(pane2.items).toEqual [editSession1]
|
||||
expect(pane2.currentItem).not.toBe editSession1 # it's a copy
|
||||
|
||||
pane3 = pane2.splitDown(view3, view4)
|
||||
expect(pane3.getItems()).toEqual [view3, view4]
|
||||
expect(container.find('.column .pane').toArray()).toEqual [pane[0], pane2[0], pane3[0]]
|
||||
|
||||
describe "splitUp(items...)", ->
|
||||
it "builds a column if needed, then appends a new pane before itself", ->
|
||||
# creates the new pane with a copy of the current item if none are given
|
||||
pane2 = pane.splitUp()
|
||||
expect(container.find('.column .pane').toArray()).toEqual [pane2[0], pane[0]]
|
||||
expect(pane2.items).toEqual [editSession1]
|
||||
expect(pane2.currentItem).not.toBe editSession1 # it's a copy
|
||||
|
||||
pane3 = pane2.splitUp(view3, view4)
|
||||
expect(pane3.getItems()).toEqual [view3, view4]
|
||||
expect(container.find('.column .pane').toArray()).toEqual [pane3[0], pane2[0], pane[0]]
|
||||
|
||||
describe ".itemForPath(path)", ->
|
||||
it "returns the item for which a call to .getPath() returns the given path", ->
|
||||
expect(pane.itemForPath(editSession1.getPath())).toBe editSession1
|
||||
|
||||
@@ -104,30 +104,34 @@ class Pane extends View
|
||||
|
||||
verticalGridUnits: -> 1
|
||||
|
||||
splitUp: (view) ->
|
||||
@split(view, 'column', 'before')
|
||||
splitUp: (items...) ->
|
||||
@split(items, 'column', 'before')
|
||||
|
||||
splitDown: (view) ->
|
||||
@split(view, 'column', 'after')
|
||||
splitDown: (items...) ->
|
||||
@split(items, 'column', 'after')
|
||||
|
||||
splitLeft: (view) ->
|
||||
@split(view, 'row', 'before')
|
||||
splitLeft: (items...) ->
|
||||
@split(items, 'row', 'before')
|
||||
|
||||
splitRight: (view) ->
|
||||
@split(view, 'row', 'after')
|
||||
splitRight: (items...) ->
|
||||
@split(items, 'row', 'after')
|
||||
|
||||
split: (view, axis, side) ->
|
||||
split: (items, axis, side) ->
|
||||
unless @parent().hasClass(axis)
|
||||
@buildPaneAxis(axis)
|
||||
.insertBefore(this)
|
||||
.append(@detach())
|
||||
|
||||
pane = new Pane(view)
|
||||
items = [@copyCurrentItem()] unless items.length
|
||||
pane = new Pane(items...)
|
||||
this[side](pane)
|
||||
rootView?.adjustPaneDimensions()
|
||||
pane.focus()
|
||||
pane
|
||||
|
||||
copyCurrentItem: ->
|
||||
deserialize(@currentItem.serialize())
|
||||
|
||||
remove: (selector, keepData) ->
|
||||
return super if keepData
|
||||
# find parent elements before removing from dom
|
||||
|
||||
Reference in New Issue
Block a user