Squashed commit of the following:

commit 82f7ddfa33
Author: Steve Ruiz <steveruizok@gmail.com>
Date:   Wed Apr 3 15:44:18 2024 +0100

    fix weird editor case
fix-tests
Steve Ruiz 2024-04-03 15:46:23 +01:00
rodzic 4ef1fb3c70
commit 7294f532d4
2 zmienionych plików z 25 dodań i 27 usunięć

Wyświetl plik

@ -8229,7 +8229,6 @@ export class Editor extends EventEmitter<TLEventMap> {
*/
cancel(): this {
this.dispatch({ type: 'misc', name: 'cancel' })
this._tickManager.tick()
return this
}
@ -8245,7 +8244,6 @@ export class Editor extends EventEmitter<TLEventMap> {
*/
interrupt(): this {
this.dispatch({ type: 'misc', name: 'interrupt' })
this._tickManager.tick()
return this
}
@ -8367,6 +8365,9 @@ export class Editor extends EventEmitter<TLEventMap> {
*/
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<TLEventMap> {
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)
}
})
}

Wyświetl plik

@ -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])