Fix editing blurs (#1037)

This commit is contained in:
Steve Ruiz 2022-11-09 16:32:13 +00:00 committed by GitHub
parent 6e275f09ef
commit cde5f711a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View file

@ -2856,6 +2856,7 @@ export class TldrawApp extends StateManager<TDSnapshot> {
// We're currently creating a shape. Override the command's
// before state so that when we undo the command, we remove
// the shape we just created.
result.before = {
appState: {
...result.before.appState,

View file

@ -206,8 +206,11 @@ export class TextUtil extends TDShapeUtil<T, E> {
[isEditing]
)
const rWasEditing = React.useRef(isEditing)
React.useEffect(() => {
if (isEditing) {
rWasEditing.current = true
this.texts.set(shape.id, text)
requestAnimationFrame(() => {
rIsMounted.current = true
@ -217,7 +220,8 @@ export class TextUtil extends TDShapeUtil<T, E> {
elm.select()
}
})
} else {
} else if (rWasEditing.current) {
rWasEditing.current = false
onShapeBlur?.()
}
}, [isEditing])

View file

@ -112,8 +112,11 @@ export const TextLabel = React.memo(function TextLabel({
[isEditing]
)
const rWasEditing = React.useRef(isEditing)
React.useEffect(() => {
if (isEditing) {
rWasEditing.current = true
requestAnimationFrame(() => {
rIsMounted.current = true
const elm = rInput.current
@ -122,8 +125,9 @@ export const TextLabel = React.memo(function TextLabel({
elm.select()
}
})
} else {
} else if (rWasEditing.current) {
onBlur?.()
rWasEditing.current = false
}
}, [isEditing, onBlur])