Fix editing blurs (#1037)
This commit is contained in:
parent
6e275f09ef
commit
cde5f711a5
3 changed files with 11 additions and 2 deletions
|
@ -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,
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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])
|
||||
|
||||
|
|
Loading…
Reference in a new issue