mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge pull request #16455 from fordhurley/fix-unique-editor-ids
Ensure that new editors get unique ids
This commit is contained in:
@@ -20,6 +20,17 @@ describe('TextEditor', () => {
|
||||
await atom.packages.activatePackage('language-javascript')
|
||||
})
|
||||
|
||||
it('generates unique ids for each editor', async () => {
|
||||
// Deserialized editors are initialized with the serialized id. We can
|
||||
// initialize an editor with what we expect to be the next id:
|
||||
const deserialized = new TextEditor({id: editor.id+1})
|
||||
expect(deserialized.id).toEqual(editor.id+1)
|
||||
|
||||
// The id generator should skip the id used up by the deserialized one:
|
||||
const fresh = new TextEditor()
|
||||
expect(fresh.id).toNotEqual(deserialized.id)
|
||||
})
|
||||
|
||||
describe('when the editor is deserialized', () => {
|
||||
it('restores selections and folds based on markers in the buffer', async () => {
|
||||
editor.setSelectedBufferRange([[1, 2], [3, 4]])
|
||||
|
||||
@@ -119,6 +119,10 @@ class TextEditor {
|
||||
}
|
||||
|
||||
this.id = params.id != null ? params.id : nextId++
|
||||
if (this.id >= nextId) {
|
||||
// Ensure that new editors get unique ids:
|
||||
nextId = this.id + 1
|
||||
}
|
||||
this.initialScrollTopRow = params.initialScrollTopRow
|
||||
this.initialScrollLeftColumn = params.initialScrollLeftColumn
|
||||
this.decorationManager = params.decorationManager
|
||||
|
||||
Reference in New Issue
Block a user