fix(plugin-annotation): mark FreeText as editing on input so blur doesn't drop changes#682
Open
seanlim wants to merge 1 commit into
Open
fix(plugin-annotation): mark FreeText as editing on input so blur doesn't drop changes#682seanlim wants to merge 1 commit into
seanlim wants to merge 1 commit into
Conversation
…sn't drop changes handleBlur early-returns unless editingRef is set, and the ref was only raised inside the isEditing effect. After a blur reset the ref, further typing left it false, so the next blur skipped updateAnnotation and the typed text was lost. Set editingRef on every onInput so a later blur always saves the content. Applies to both FreeText and CalloutFreeText.
|
@seanlim is attempting to deploy a commit to the OpenBook Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #681
Root cause
In
packages/plugin-annotation/src/shared/components/annotations/free-text.tsx(andcallout-free-text.tsx), the commit-on-blur is gated byeditingRef.current:editingRef.currentis only ever armed inside the[isEditing]effect:When the style-panel interaction blurs the editor,
handleBlurruns and setseditingRef.current = false. The annotation stays selected, soisEditingnever changes and the effect doesn't re-run. Re-focusing the still-contentEditablespan does not re-arm the gate (there is noonFocushandler), so the next blur bails out before committing.Proposed fix
Re-arm the gate whenever the user actually edits the text, on the contentEditable element in both
free-text.tsxandcallout-free-text.tsx:A single
onInputhandler is sufficient. A contentEditable only emitsinputwhen it's editable and its content actually changes, so "the user typed something" guaranteeseditingRef.currentis armed before the next blur — which is the only case where text would otherwise be lost. (Verified against the repro above; re-arming ononFocusinstead/additionally isn't needed, since a focus/blur with no typing has nothing new to commit.)Testing
Ran the snippet viewer
@embedpdf/snippetand added a FreeText annotation, typed text, blurred — text persists.Re-edited the existing annotation, typed more, blurred — change is saved and the comment sidebar reflects the updated text (this is the path that previously dropped the edit).