Repository navigation
HTML viewer: a highlight whose content was removed is restored exactly or reported as unanchored - #4152
Merged
Conversation
…tions re-anchor Pages that detach and re-attach nodes (virtualized docs such as Feishu) collapse the stored Range onto the still-connected parent. rangeAlive() saw connected containers and kept the empty range, so the highlight vanished after scrolling away and back and the text re-search never ran.
With a collapsed Range counted as dead, the re-search took the first occurrence of the quoted words in the document: a highlight on "Revenue" in the second of two rows moved onto the first row while its row was scrolled away, and stayed there after it came back. A collapsed Range marks the place its text was removed from, so look for the same node coming back there (same name and text, nearest the point, the quote at the same offset), or for the text node itself if the page put it back or rewrote it in place. Until then the highlight stays unanchored, as it does while its text is away. The search limits are unchanged. Adds the DOM test for the collapsed Range (it fails against main's bridge) and the two-rows cases, registered in tests/dom-test-list.txt.
…-viewer-collapsed-range-4138-simplify
A highlight whose live Range collapses (its text node removed or its data rewritten) now comes back only when the very same text nodes are in the page again holding exactly the text they held while it was in place; then the recorded offsets are set back. Otherwise it stays unanchored and is reported so, until a reload restores it from its stored text. No search for its words: two rows can share them, and the highlight would land on text the person did not select. Replaces the structural lost-place search (lostPlaceOf, lostPlaceConnected, findAtLostPlace and findTextRange's at parameter). Anchored annotations keep the anchor-scoped search; a Range whose nodes left the document without collapsing keeps the search as before. Node references of a lost highlight are dropped after five minutes.
…ores An anchored highlight that was in place and collapsed is now searched for only inside its anchor element; when that finds nothing (or the anchor is gone) it stays unanchored instead of falling back to the first occurrence in the whole document. An anchored target never in place keeps the full restore ladder. A restore by identity is accepted only if the Range is not empty and, when it spans two nodes, still covers the quoted words (whitespace ignored; a capped quote as a prefix). An empty restore no longer resets the lost timer, so the node references are still dropped after the bound.
backnotprop
marked this pull request as ready for review
November 28, 2026 02:52
backnotprop
added a commit
to bendrucker/plannotator
that referenced
this pull request
Nov 28, 2026
…panel swipes and the HTML viewer's lost highlights ui 0.67.0 and core 0.25.35 went to npm on 2026-11-28 with package files that match the v0.29.6 tag (c21f65e), so this pair carries what merged after v0.29.6, up to v0.29.7. core 0.25.36 is additive: the linked mark "decisions" and InboxDecision.machine (backnotprop#4066), DraftFileUploader.previewUrl (backnotprop#4165), and holdingsOf no longer counting a question Mark read closed (backnotprop#4160). No exports subpath changes; nothing removed. ui 0.68.0 is a minor: Escape while an input method composes only ends the composition, and shortcuts skip such keys; holdsImeEscape is new (backnotprop#3689, backnotprop#4162). HtmlViewer treats a collapsed live Range as lost (backnotprop#4152). Compact panels: OverlayScrollArea scrollMemory, SidebarContainer closing and scrollPositions, ActionMenu compactEdgeSwipe, four new hooks and the panel rules in theme.css (backnotprop#2861). useLaunchAnnouncement waits for ready (backnotprop#4067). ui uses nothing new from core; its exact pin follows so a host gets one core. Publish core first. README and HANDOFF name the new pair, and HANDOFF adds what the published 0.25.35 / 0.67.0 already held beyond their notes (backnotprop#4114, backnotprop#4151). bun.lock is bun install's own output: the two package version lines, and six app workspace version lines (0.29.5 to 0.29.7) the release bumps left behind.
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.
Carries #4138 by @HaloXie (their commit is kept as authored) and replaces what review added on top of it with exact rules. It is opened here because the fork belongs to an organization, where GitHub does not allow maintainer edits.
What was wrong. Some pages remove content from the DOM and add it back (virtualized lists, framework re-renders). When the highlighted text node is removed, or its text is rewritten, the browser collapses the highlight's live Range. The viewer still counted the collapsed Range as alive, so the highlight painted nothing, nobody was told, and the viewer never looked again.
The fix from #4138. A collapsed Range counts as lost (
rangeAlive).What happens to a lost highlight (added here). A highlight that was in place and then collapsed never moves outside where it was. It comes back on the same nodes or, for an annotation with an anchor, inside its anchor element, and otherwise stays unanchored.
isConnectedreads and two string compares; when both nodes of a two-node highlight are back but the restore is refused, each pass also builds that Range and reads its text, until the bound. After 5 minutes lost, the two node references are dropped so detached DOM is not kept alive. The highlight then stays unanchored.restoreAnnotation). All of these work as on main.Two exceptions where main's search (first occurrence) still runs, as main and a reload do:
Limit, plainly. Most virtualizers destroy rows and build new ones. Those new nodes are not the highlighted nodes, so a comment without an anchor shows as unanchored while the content is away and after it comes back, until the page is reloaded. A reload restores it from its stored text with the existing restore, which takes the first occurrence of the text. Where the person sees "Unanchored": the Inbox's HTML attachment view shows the chip while the highlight is lost and clears it when it comes back. The annotate/plan page shows its chip only from a Refresh report, so a mid-session loss there shows only that the highlight is gone. That page is unchanged here.
Tests.
bridgeCollapsedRange.test.ts, 18 tests, run in happy-dom against the bridge's own functions. happy-dom does not move live Range boundary points when the DOM changes, so the tests do the DOM spec's steps themselves (pre-remove, insert, replace data). The cases:node.dataand then written backreplaceChild, and a rewrite followed by a removalResults:
srcdoc.test.ts144,HtmlViewer.reopenComment.test.tsx11,htmlLiveProtocol.test.tsx40.tscfor packages/ui is clean.Not yet run in a real browser. The two-minute check:
rows.htmland open it in Plannotator (an HTML attachment in the Inbox shows the chip;plannotator annotate rows.htmlworks for the highlights):<div id="l"><p id="a">Revenue grew.</p><p id="b">The quoted sentence.</p><p id="c">Revenue fell.</p></div>const l = document.getElementById('l'); const b = document.getElementById('b'); b.remove(); setTimeout(() => l.append(b), 1500). The " quoted" highlight disappears and returns on exactly the same characters, leading space included.const c = document.getElementById('c'); c.remove(); setTimeout(() => { const p = document.createElement('p'); p.textContent = 'Revenue fell.'; l.append(p); }, 1500). The "Revenue" highlight disappears, never appears on "Revenue grew.", and stays gone after the copy returns. In the Inbox view its comment shows "Unanchored".