Merge pull request #14108 from atom/fb-mdt-remember-moved-item-positions

🐛 Fix observation of moved items
This commit is contained in:
Max Brunsfeld 2017-04-04 10:20:24 -07:00 committed by GitHub
commit 32ff2f37d9
2 changed files with 25 additions and 6 deletions

View File

@ -2326,6 +2326,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, '\\$&') const escapeStringRegex = str => str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')

View File

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