diff --git a/packages/editor/src/lib/editor/Editor.ts b/packages/editor/src/lib/editor/Editor.ts index 26b1170d6..0c1ddff9d 100644 --- a/packages/editor/src/lib/editor/Editor.ts +++ b/packages/editor/src/lib/editor/Editor.ts @@ -3596,6 +3596,8 @@ export class Editor extends EventEmitter { } this.stopFollowingUser() + // finish off any in-progress interactions + this.complete() return this.batch( () => this.store.put([{ ...this.getInstanceState(), currentPageId: pageId }]), diff --git a/packages/tldraw/src/test/commands/setCurrentPage.test.ts b/packages/tldraw/src/test/commands/setCurrentPage.test.ts index 3ecd170c7..4814fe774 100644 --- a/packages/tldraw/src/test/commands/setCurrentPage.test.ts +++ b/packages/tldraw/src/test/commands/setCurrentPage.test.ts @@ -85,4 +85,22 @@ describe('setCurrentPage', () => { expect(console.error).toHaveBeenCalled() expect(editor.getCurrentPageId()).toBe(initialPageId) }) + + it('cancels any in-progress actions', () => { + const page1Id = editor.getPages()[0].id + const page2Id = PageRecordType.createId('page2') + + editor.createPage({ name: 'New Page 2', id: page2Id }) + expect(editor.getCurrentPageId()).toBe(page1Id) + + const geoId = createShapeId() + editor.createShape({ type: 'geo', id: geoId, props: { w: 100, h: 100 } }) + editor.select(geoId) + editor.keyUp('Enter') + + expect(editor.isIn('select.editing_shape')).toBe(true) + + editor.setCurrentPage(page2Id) + expect(editor.isIn('select.idle')).toBe(true) + }) })