Intelligently activate new items when the active item is closed

If the active item was the pane's first item, the second item (which is
the new first item) is activated. Otherwise, the item to the left of the
closed item is activated.
This commit is contained in:
Brandon Tilley
2014-01-20 14:19:54 -08:00
parent 7be0f6dd3b
commit 8bba4d8add
3 changed files with 23 additions and 7 deletions

View File

@@ -111,7 +111,7 @@ describe "Pane", ->
pane = new Pane(items: [new Item("A"), new Item("B"), new Item("C")])
[item1, item2, item3] = pane.items
it "removes the item from the items list and activates the next item if it was the active item", ->
it "removes the item from the items list", ->
expect(pane.activeItem).toBe item1
pane.destroyItem(item2)
expect(item2 in pane.items).toBe false
@@ -119,7 +119,21 @@ describe "Pane", ->
pane.destroyItem(item1)
expect(item1 in pane.items).toBe false
expect(pane.activeItem).toBe item3
describe "when the destroyed item is the active item and is the first item", ->
it "activates the next item", ->
expect(pane.activeItem).toBe item1
pane.destroyItem(item1)
expect(pane.activeItem).toBe item2
describe "when the destroyed item is the active item and is not the first item", ->
beforeEach ->
pane.activateItem(item2)
it "activates the previous item", ->
expect(pane.activeItem).toBe item2
pane.destroyItem(item2)
expect(pane.activeItem).toBe item1
it "emits 'item-removed' with the item, its index, and true indicating the item is being destroyed", ->
pane.on 'item-removed', itemRemovedHandler = jasmine.createSpy("itemRemovedHandler")

View File

@@ -429,23 +429,23 @@ describe "WorkspaceView", ->
expect(workspace.getActivePaneItem().getUri()).not.toBeUndefined()
# destroy all items
expect(workspace.getActivePaneItem().getUri()).toBe 'a'
expect(workspace.getActivePaneItem().getUri()).toBe 'file1'
pane.destroyActiveItem()
expect(workspace.getActivePaneItem().getUri()).toBe 'b'
pane.destroyActiveItem()
expect(workspace.getActivePaneItem().getUri()).toBe 'file1'
expect(workspace.getActivePaneItem().getUri()).toBe 'a'
pane.destroyActiveItem()
# reopens items with uris
expect(workspace.getActivePaneItem()).toBeUndefined()
workspace.reopenItemSync()
expect(workspace.getActivePaneItem().getUri()).toBe 'file1'
expect(workspace.getActivePaneItem().getUri()).toBe 'a'
# does not reopen items that are already open
workspace.openSync('b')
expect(workspace.getActivePaneItem().getUri()).toBe 'b'
workspace.reopenItemSync()
expect(workspace.getActivePaneItem().getUri()).toBe 'a'
expect(workspace.getActivePaneItem().getUri()).toBe 'file1'
describe "core:close", ->
it "closes the active pane item until all that remains is a single empty pane", ->