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 // We're currently creating a shape. Override the command's
// before state so that when we undo the command, we remove // before state so that when we undo the command, we remove
// the shape we just created. // the shape we just created.
result.before = { result.before = {
appState: { appState: {
...result.before.appState, ...result.before.appState,

View file

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

View file

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