mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Merge pull request #14134 from atom/fb-mdt-dont-store-default-locations
Don't store default locations
This commit is contained in:
commit
a74d561f3c
@ -7,13 +7,22 @@ describe("StateStore", () => {
|
||||
let databaseName = `test-database-${Date.now()}`
|
||||
let version = 1
|
||||
|
||||
it("can save and load states", () => {
|
||||
it("can save, load, and delete states", () => {
|
||||
const store = new StateStore(databaseName, version)
|
||||
return store.save('key', {foo:'bar'})
|
||||
.then(() => store.load('key'))
|
||||
.then((state) => {
|
||||
expect(state).toEqual({foo:'bar'})
|
||||
})
|
||||
.then(() => store.delete('key'))
|
||||
.then(() => store.load('key'))
|
||||
.then((value) => {
|
||||
expect(value).toBeNull()
|
||||
})
|
||||
.then(() => store.count())
|
||||
.then((count) => {
|
||||
expect(count).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
it("resolves with null when a non-existent key is loaded", () => {
|
||||
|
@ -266,14 +266,13 @@ describe('Workspace', () => {
|
||||
const ITEM_URI = 'atom://test'
|
||||
const item = {
|
||||
getURI: () => ITEM_URI,
|
||||
getDefaultLocation: jasmine.createSpy().andReturn('left'),
|
||||
getDefaultLocation: () => 'left',
|
||||
getElement: () => document.createElement('div')
|
||||
}
|
||||
dock.getActivePane().addItem(item)
|
||||
expect(dock.getPaneItems()).toHaveLength(1)
|
||||
waitsForPromise(() => atom.workspace.open(ITEM_URI, {searchAllPanes: true}))
|
||||
runs(() => {
|
||||
expect(item.getDefaultLocation).not.toHaveBeenCalled()
|
||||
expect(atom.workspace.getPaneItems()).toHaveLength(1)
|
||||
expect(dock.getPaneItems()).toHaveLength(1)
|
||||
expect(dock.getPaneItems()[0]).toBe(item)
|
||||
@ -330,7 +329,7 @@ describe('Workspace', () => {
|
||||
const ITEM_URI = 'atom://test'
|
||||
const item = {
|
||||
getURI: () => ITEM_URI,
|
||||
getDefaultLocation: jasmine.createSpy().andReturn('left'),
|
||||
getDefaultLocation: () => 'left',
|
||||
getElement: () => document.createElement('div')
|
||||
}
|
||||
const opener = uri => uri === ITEM_URI ? item : null
|
||||
@ -344,7 +343,6 @@ describe('Workspace', () => {
|
||||
runs(() => {
|
||||
expect(dock.getPaneItems()).toHaveLength(1)
|
||||
expect(dock.getPaneItems()[0]).toBe(item)
|
||||
expect(item.getDefaultLocation).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -2328,11 +2326,11 @@ i = /test/; #FIXME\
|
||||
})
|
||||
|
||||
describe('when an item is moved', () => {
|
||||
it('stores the new location', () => {
|
||||
it("stores the new location if it's not the default", () => {
|
||||
const ITEM_URI = 'atom://test'
|
||||
const item = {
|
||||
getURI: () => ITEM_URI,
|
||||
getDefaultLocation: jasmine.createSpy().andReturn('left'),
|
||||
getDefaultLocation: () => 'left',
|
||||
getElement: () => document.createElement('div')
|
||||
}
|
||||
const centerPane = workspace.getActivePane()
|
||||
@ -2342,6 +2340,23 @@ i = /test/; #FIXME\
|
||||
centerPane.moveItemToPane(item, dockPane)
|
||||
expect(workspace.itemLocationStore.save).toHaveBeenCalledWith(ITEM_URI, 'right')
|
||||
})
|
||||
|
||||
it("clears the location if it's the default", () => {
|
||||
const ITEM_URI = 'atom://test'
|
||||
const item = {
|
||||
getURI: () => ITEM_URI,
|
||||
getDefaultLocation: () => 'right',
|
||||
getElement: () => document.createElement('div')
|
||||
}
|
||||
const centerPane = workspace.getActivePane()
|
||||
centerPane.addItem(item)
|
||||
const dockPane = atom.workspace.getRightDock().getActivePane()
|
||||
spyOn(workspace.itemLocationStore, 'save')
|
||||
spyOn(workspace.itemLocationStore, 'delete')
|
||||
centerPane.moveItemToPane(item, dockPane)
|
||||
expect(workspace.itemLocationStore.delete).toHaveBeenCalledWith(ITEM_URI)
|
||||
expect(workspace.itemLocationStore.save).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -77,6 +77,21 @@ class StateStore {
|
||||
})
|
||||
}
|
||||
|
||||
delete (key) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.dbPromise.then((db) => {
|
||||
if (db == null) return resolve()
|
||||
|
||||
var request = db.transaction(['states'], 'readwrite')
|
||||
.objectStore('states')
|
||||
.delete(key)
|
||||
|
||||
request.onsuccess = resolve
|
||||
request.onerror = reject
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
clear () {
|
||||
return this.dbPromise.then((db) => {
|
||||
if (!db) return
|
||||
|
@ -301,7 +301,17 @@ module.exports = class Workspace extends Model {
|
||||
if (typeof item.getURI === 'function') {
|
||||
const uri = item.getURI()
|
||||
if (uri != null) {
|
||||
this.itemLocationStore.save(item.getURI(), paneContainer.getLocation())
|
||||
const location = paneContainer.getLocation()
|
||||
let defaultLocation
|
||||
if (typeof item.getDefaultLocation === 'function') {
|
||||
defaultLocation = item.getDefaultLocation()
|
||||
}
|
||||
defaultLocation = defaultLocation || 'center'
|
||||
if (location === defaultLocation) {
|
||||
this.itemLocationStore.delete(item.getURI())
|
||||
} else {
|
||||
this.itemLocationStore.save(item.getURI(), location)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user