feat(html): the pdf annotator reports its changes and takes a tool press - #906
Merged
Merged
Conversation
A host had to count the pending marks after every pointer event, because
odr.annotation had no callback. The count settles 50ms after the pointer
lifts, so each host also waited on a timer. odr.onAnnotationChange({count})
now reports each change: a mark, a finished stroke, an undo, a removal and
a clear.
odr.annotation.press(tool, style) and recolor(tool, style) do what a tool
button does. Over a selection, the tool marks it once and no tool stays
armed. With no selection, press arms or disarms the tool, and recolor
restyles the armed tool. The Android app, the iOS app and the website each
had their own copy of this logic.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H3sFjPT7zd8fvmpqhznzEP
`press` and `recolor` tested the selection for text and then disarmed the tool, even when no page held the selection and nothing was marked. Now they disarm only when the mark is made, so such a press arms the tool. The comments and the changelog entry are shorter. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C725vurM2ZqBY6ddV2FMZ7
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.
Why
Each host adds a script over
odr.annotationthat it should not need: the Android app (editing-bridge.js, opendocument-app/OpenDocument.droid#662), the iOS app (DocumentViewController.pageMessageBridgeandpressMarker), and the website (frame-bridge.js). The three copies do the same two things:pointerup,pointercancelandselectionchange, and wait 120 ms because a mark settles 50 ms after the pointer lifts. The reason is that the annotator has no change callback.What
odr.onAnnotationChange({count})fires on each change to what is pending: a mark, a finished stroke, an undo, a removal and a clear. It does not fire while a stroke is drawn, or when the count does not change.odr.annotation.press(tool, {color, width}):ink), the tool marks the selection once in the colour given, clears the selection, and no tool stays armed.nulldisarms.odr.annotation.recolor(tool, style): over a selection it marks it once, the same aspress. With no selection it restyles the tool if that tool is armed. It returns the tool that stays armed.The behaviour is the same as the behaviour of the host copies. One detail is different: a mark made once does not change the colour that is set for the armed tool.
Not in this PR
odr.onEditChange = …, and nowodr.onAnnotationChange = …). The host must hook into the callbacks, because the core cannot know the transport (addJavascriptInterface,WKScriptMessageHandlerorpostMessage). A singleodr.connect(post)could take all the callbacks, but a pdf page does not carryediting.js, so no one script could hold it. A second API for the same callbacks gives a host nothing.markOnSelectionstaysfalseby default. Every host sets it with onesetOptionscall.Test
test/browser/annotation/tests.html: 22 new checks, run in headless Chrome. The result is 63 checks and 0 failures. On main, the result is 41 checks and 0 failures.