fix(ui): keep annotation comment popover open while it has unsaved content#886
Draft
gwynnnplaine wants to merge 1 commit into
Draft
fix(ui): keep annotation comment popover open while it has unsaved content#886gwynnnplaine wants to merge 1 commit into
gwynnnplaine wants to merge 1 commit into
Conversation
…ntent Selecting new text or clicking outside discarded an in-progress comment: web-highlighter wrapped the new selection and the CREATE handler reset the popover, and the popover's own outside-click handler closed it on any click. Pause the highlighter (stop/run) while the comment buffer holds unsaved content so a new selection stays a plain, copyable browser selection and the popover survives; guard the popover's outside-click the same way. Mirror the fix in the HTML/annotate iframe-bridge surface. Escape and the close button remain explicit exits. Closes backnotprop#821
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.
Warning
WIP — do not merge. Opening as a draft to share the approach. I haven't got sign-off on the implementation direction in #821 yet (only the go-ahead to take the issue). Happy to adjust before this leaves draft.
Closes #821
What
The annotation comment popover discarded an in-progress comment when the user clicked elsewhere or selected other text (e.g. to copy a snippet into their comment). Now the popover stays open and keeps its text while it holds unsaved content; the only exits are the explicit ones (Escape, the close button, ⌘/Ctrl+Enter to submit).
How it works
Two separate paths could drop the comment:
CommentPopover's capture-phasepointerdownhandler calledonClose()on any click outside. Now it bails when the buffer is dirty.CREATE, whose handler ransetCommentPopover(null)and opened a fresh popover, wiping the in-progress text.The fix centers on a small dirty signal:
packages/ui/utils/commentContent.ts—hasUnsavedContent(text, images), the single predicate for "is there content worth protecting."packages/ui/hooks/useAnnotationHighlighter.ts— while the popover is dirty, the highlighter is paused (stop()); a new selection then stays a plain, copyable browser selection and the existing popover is untouched. It resumes (run()) on submit/close. Wired via a newhandleCommentDraftChangefed by the popover'sonDraftChange.packages/ui/components/CommentPopover.tsx— outside-click now no-ops while dirty (mirrored into a ref so the listener doesn't re-subscribe per keystroke).packages/ui/components/html-viewer/useHtmlAnnotation.ts— same fix for the HTML/annotate surface, which uses an iframe message bridge instead of web-highlighter: theselectionmessage early-returns while dirty.Notes
Testing
bun run typecheckclean;bun test1369 pass / 0 fail (addedcommentContent.test.ts).hasUnsavedContentpredicate is unit-tested. Flagging this as the weak spot — open to adding happy-dom if you'd want real coverage.