chore: await local propagation before replacing plain text contents
This commit is contained in:
@@ -55,6 +55,8 @@ export const PlainEditor = forwardRef<PlainEditorInterface, Props>(
|
|||||||
const isAdjustingMobileCursor = useRef(false)
|
const isAdjustingMobileCursor = useRef(false)
|
||||||
const note = useRef(controller.item)
|
const note = useRef(controller.item)
|
||||||
|
|
||||||
|
const [isPendingLocalPropagation, setIsPendingLocalPropagation] = useState(false)
|
||||||
|
|
||||||
const tabObserverDisposer = useRef<Disposer>()
|
const tabObserverDisposer = useRef<Disposer>()
|
||||||
const mutationObserver = useRef<MutationObserver | null>(null)
|
const mutationObserver = useRef<MutationObserver | null>(null)
|
||||||
|
|
||||||
@@ -79,27 +81,40 @@ export const PlainEditor = forwardRef<PlainEditorInterface, Props>(
|
|||||||
throw Error('Editor received changes for non-current note')
|
throw Error('Editor received changes for non-current note')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!isPendingLocalPropagation) {
|
||||||
isPayloadSourceRetrieved(source) ||
|
if (
|
||||||
editorText == undefined ||
|
isPayloadSourceRetrieved(source) ||
|
||||||
updatedNote.editorIdentifier !== note.current.editorIdentifier ||
|
editorText == undefined ||
|
||||||
updatedNote.noteType !== note.current.noteType
|
updatedNote.editorIdentifier !== note.current.editorIdentifier ||
|
||||||
) {
|
updatedNote.noteType !== note.current.noteType
|
||||||
setEditorText(updatedNote.text)
|
) {
|
||||||
|
setEditorText(updatedNote.text)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
note.current = updatedNote
|
note.current = updatedNote
|
||||||
})
|
})
|
||||||
|
|
||||||
return disposer
|
return disposer
|
||||||
}, [controller, editorText, controller.item.uuid, controller.item.editorIdentifier, controller.item.noteType])
|
}, [
|
||||||
|
controller,
|
||||||
|
editorText,
|
||||||
|
controller.item.uuid,
|
||||||
|
controller.item.editorIdentifier,
|
||||||
|
controller.item.noteType,
|
||||||
|
isPendingLocalPropagation,
|
||||||
|
])
|
||||||
|
|
||||||
const onTextAreaChange: ChangeEventHandler<HTMLTextAreaElement> = ({ currentTarget }) => {
|
const onTextAreaChange: ChangeEventHandler<HTMLTextAreaElement> = ({ currentTarget }) => {
|
||||||
const text = currentTarget.value
|
const text = currentTarget.value
|
||||||
|
|
||||||
setEditorText(text)
|
setEditorText(text)
|
||||||
|
|
||||||
void controller.saveAndAwaitLocalPropagation({ text: text, isUserModified: true })
|
setIsPendingLocalPropagation(true)
|
||||||
|
|
||||||
|
void controller.saveAndAwaitLocalPropagation({ text: text, isUserModified: true }).then(() => {
|
||||||
|
setIsPendingLocalPropagation(false)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const onContentFocus = useCallback(() => {
|
const onContentFocus = useCallback(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user