From 7294f532d425b61a13358d37cebf95c26e393f06 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Wed, 3 Apr 2024 15:46:23 +0100 Subject: [PATCH] Squashed commit of the following: commit 82f7ddfa33b01ea45e6791dc44c3c5e484cf0059 Author: Steve Ruiz Date: Wed Apr 3 15:44:18 2024 +0100 fix weird editor case --- packages/editor/src/lib/editor/Editor.ts | 11 +++-- .../src/lib/shapes/shared/useEditableText.ts | 41 ++++++++----------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/packages/editor/src/lib/editor/Editor.ts b/packages/editor/src/lib/editor/Editor.ts index 6e3fdbea2..d44f2c75e 100644 --- a/packages/editor/src/lib/editor/Editor.ts +++ b/packages/editor/src/lib/editor/Editor.ts @@ -8229,7 +8229,6 @@ export class Editor extends EventEmitter { */ cancel(): this { this.dispatch({ type: 'misc', name: 'cancel' }) - this._tickManager.tick() return this } @@ -8245,7 +8244,6 @@ export class Editor extends EventEmitter { */ interrupt(): this { this.dispatch({ type: 'misc', name: 'interrupt' }) - this._tickManager.tick() return this } @@ -8367,6 +8365,9 @@ export class Editor extends EventEmitter { */ dispatch = (info: TLEventInfo): this => { this._pendingEventsForNextTick.push(info) + if (!(info.type === 'pointer' || info.type === 'wheel' || info.type === 'pinch')) { + this._flushEventsForTick(0) + } return this } @@ -8381,8 +8382,10 @@ export class Editor extends EventEmitter { this._flushEventForTick(info) } } - this.root.handleEvent({ type: 'misc', name: 'tick', elapsed }) - this.scribbles.tick(elapsed) + if (elapsed > 0) { + this.root.handleEvent({ type: 'misc', name: 'tick', elapsed }) + this.scribbles.tick(elapsed) + } }) } diff --git a/packages/tldraw/src/lib/shapes/shared/useEditableText.ts b/packages/tldraw/src/lib/shapes/shared/useEditableText.ts index b577d7b98..95439fef8 100644 --- a/packages/tldraw/src/lib/shapes/shared/useEditableText.ts +++ b/packages/tldraw/src/lib/shapes/shared/useEditableText.ts @@ -74,32 +74,27 @@ export function useEditableText(id: TLShapeId, type: string, text: string) { const elm = rInput.current const editingShapeId = editor.getEditingShapeId() // Did we move to a different shape? - if (editingShapeId) { - // important! these ^v are two different things - // is that shape OUR shape? - if (elm && editingShapeId === id) { - if (ranges) { - if (!ranges.length) { - // If we don't have any ranges, restore selection - // and select all of the text - elm.focus() - } else { - // Otherwise, skip the select-all-on-focus behavior - // and restore the selection - rSkipSelectOnFocus.current = true - elm.focus() - const selection = window.getSelection() - if (selection) { - ranges.forEach((range) => selection.addRange(range)) - } - } - } else { + // important! these ^v are two different things + // is that shape OUR shape? + if (elm && editingShapeId === id) { + if (ranges) { + if (!ranges.length) { + // If we don't have any ranges, restore selection + // and select all of the text elm.focus() + } else { + // Otherwise, skip the select-all-on-focus behavior + // and restore the selection + rSkipSelectOnFocus.current = true + elm.focus() + const selection = window.getSelection() + if (selection) { + ranges.forEach((range) => selection.addRange(range)) + } } + } else { + elm.focus() } - } else { - window.getSelection()?.removeAllRanges() - editor.complete() } }) }, [editor, id])