mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Destroy any existing pending pane item when adding a pending item
This commit is contained in:
parent
4fce3668b6
commit
44a648a9ea
@ -132,6 +132,16 @@ describe "Pane", ->
|
||||
expect(-> pane.addItem('foo')).toThrow()
|
||||
expect(-> pane.addItem(1)).toThrow()
|
||||
|
||||
it "destroys any existing pending item if the new item is pending", ->
|
||||
pane = new Pane(paneParams(items: []))
|
||||
itemA = new Item("A")
|
||||
itemB = new Item("B")
|
||||
itemA.pending = true
|
||||
itemB.pending = true
|
||||
pane.addItem(itemA)
|
||||
pane.addItem(itemB)
|
||||
expect(itemA.isDestroyed()).toBe true
|
||||
|
||||
describe "::activateItem(item)", ->
|
||||
pane = null
|
||||
|
||||
@ -155,7 +165,7 @@ describe "Pane", ->
|
||||
pane.activateItem(pane.itemAtIndex(1))
|
||||
expect(observed).toEqual [pane.itemAtIndex(1)]
|
||||
|
||||
describe "activating pending items", ->
|
||||
describe "when the item being activated is pending", ->
|
||||
itemC = null
|
||||
itemD = null
|
||||
|
||||
@ -164,24 +174,18 @@ describe "Pane", ->
|
||||
itemD = new Item("D")
|
||||
itemC.pending = true
|
||||
itemD.pending = true
|
||||
|
||||
it "replaces the active item if it is pending", ->
|
||||
pane.activateItem(itemC)
|
||||
|
||||
it "opens pending item", ->
|
||||
expect(pane.getItems().length).toBe 3
|
||||
expect(pane.getActiveItem()).toBe pane.itemAtIndex(1)
|
||||
|
||||
it "replaces original pending item when activating another pending item", ->
|
||||
expect(pane.getItems().map (item) -> item.name).toEqual ['A', 'C', 'B']
|
||||
pane.activateItem(itemD)
|
||||
expect(pane.getItems().map (item) -> item.name).toEqual ['A', 'D', 'B']
|
||||
|
||||
expect(pane.getItems().length).toBe 3
|
||||
expect(pane.getActiveItem()).toBe itemD
|
||||
expect(pane.getActiveItem()).toBe pane.itemAtIndex(1)
|
||||
|
||||
it "keeps pending item when non-pending item is activated", ->
|
||||
pane.activateItem(pane.itemAtIndex(0))
|
||||
|
||||
expect(pane.getItems().length).toBe 3
|
||||
expect(pane.getActiveItem()).toBe pane.itemAtIndex(0)
|
||||
it "adds the item after the active item if it is not pending", ->
|
||||
pane.activateItem(itemC)
|
||||
pane.activateItemAtIndex(2)
|
||||
pane.activateItem(itemD)
|
||||
expect(pane.getItems().map (item) -> item.name).toEqual ['A', 'B', 'D']
|
||||
|
||||
describe "::activateNextItem() and ::activatePreviousItem()", ->
|
||||
it "sets the active item to the next/previous item, looping around at either end", ->
|
||||
|
@ -365,6 +365,12 @@ class Pane extends Model
|
||||
|
||||
return if item in @items
|
||||
|
||||
if item.isPending?()
|
||||
for existingItem, i in @items
|
||||
if existingItem.isPending?()
|
||||
@destroyItem(existingItem)
|
||||
break
|
||||
|
||||
if typeof item.onDidDestroy is 'function'
|
||||
@itemSubscriptions.set item, item.onDidDestroy => @removeItem(item, false)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user