🐛 Fix observation of moved items

`PaneContainer::onDidAddPaneItem` isn't triggered on moves.
This commit is contained in:
Matthew Dapena-Tretter 2017-03-31 16:37:32 -07:00
parent 22807a1aa3
commit 4ed53578ce
2 changed files with 25 additions and 6 deletions

View File

@ -2314,6 +2314,23 @@ i = /test/; #FIXME\
})
})
})
describe('when an item is moved', () => {
it('stores the new location', () => {
const ITEM_URI = 'atom://test'
const item = {
getURI: () => ITEM_URI,
getDefaultLocation: jasmine.createSpy().andReturn('left'),
getElement: () => document.createElement('div')
}
const centerPane = workspace.getActivePane()
centerPane.addItem(item)
const dockPane = atom.workspace.getRightDock().getActivePane()
spyOn(workspace.itemLocationStore, 'save')
centerPane.moveItemToPane(item, dockPane)
expect(workspace.itemLocationStore.save).toHaveBeenCalledWith(ITEM_URI, 'right')
})
})
})
const escapeStringRegex = str => str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')

View File

@ -296,13 +296,15 @@ module.exports = class Workspace extends Model {
subscribeToMovedItems () {
for (const paneContainer of this.getPaneContainers()) {
paneContainer.onDidAddPaneItem(({item}) => {
if (typeof item.getURI === 'function') {
const uri = item.getURI()
if (uri != null) {
this.itemLocationStore.save(item.getURI(), paneContainer.getLocation())
paneContainer.observePanes(pane => {
pane.onDidAddItem(({item}) => {
if (typeof item.getURI === 'function') {
const uri = item.getURI()
if (uri != null) {
this.itemLocationStore.save(item.getURI(), paneContainer.getLocation())
}
}
}
})
})
}
}