Repository navigation
PT-4885: Keep the line still and the caret after the number in an empty verse - #34
Conversation
The transient caret host (a placeholder-only text node that gives an empty verse or a trailing collapsed note a caret to render in) was recognized only by the key one guard instance tracked, and its placeholder was stripped by content. That leaked the placeholder into saved Scripture, or deleted real zero-width spaces, in several ways: - Pasted text merged with the host, carrying the placeholder in under the pasted node's key. - Stripping removed every zero-width space from text that landed in the host, so a Thai or Khmer word break pasted or typed there was lost. - With all three guards mounted, a second instance stripped again after the first. - An undo that brought a host back left it untracked, so text typed into it kept the placeholder. The host is now marked with node state, which also keeps Lexical from merging neighboring text into it. Only marked nodes are stripped, removed or adopted, and only the host's own placeholder is removed, where its position is known. An untracked host the caret rests in is adopted. Creating or removing a host is merged into the current undo step, so it never clears the redo stack. Also: - Blur removes the host without writing the DOM selection back (which stole focus) and leaves the caret at the boundary it stood for, not inside a collapsed note. - Focus that returns without a selection change re-hosts the caret. - Any range selection, even inside the placeholder, removes the host, so it can't be copied or quoted by a footnote. - Delete and Backspace see through a bare host to the neighboring verse marker and the paragraph edges. - The delta fast path counts a bare host as zero length, so the first keystroke into it no longer emits a delete for whatever follows. - An unmarked zero-width space at a guarded boundary (loaded or typed as content) is reused rather than stacked behind, and never removed. Prerequisite for PT-4885, which keeps the host alive between two empty verses. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
An update made outside any event resolves its selection from the DOM. The focus re-host ran one from a microtask, and right after a focus the DOM may not yet hold the selection just committed (jsdom puts it at the editor start), so it could move the caret instead of hosting it. Under CI load this made noteCaretPlacement's empty-note selectNote test flaky. Decide from the committed state first and update only when a host is actually missing. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
5fecc42 to
db9ae39
Compare
17440eb to
794b95c
Compare
- Tests for typing at host offset 1, blur staying out of undo and the USJ-change handler, and $caretAtParaStart/$caretAtParaEnd with a host (each fails if its behavior is reverted). - A host undo restored is removed on blur, or when the caret leaves it, even if no selection change adopted it first. - The delta fast path diffs the previous node from its delta-doc contribution, so an empty char span's stand-in no longer deletes the next verse either. - The focus re-host flushes pending updates before deciding, and does nothing once its effect is torn down. - CaretHostRepair returns void; the $repairPast wrapper is gone; $hasCaretHostMark moves to the PR that uses it. - Docs, comments and test placement brought in line with the code. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
794b95c to
0d19617
Compare
katherinejensen00
left a comment
There was a problem hiding this comment.
Thanks, Timothy. The diagnosis in the description is right, and the fix works where it's aimed:
- No reflow, caret after the number. In the platform demo (Paragraph Structure view), I put the caret in each of 40 empty verses at 21 widths from 170 to 470px: 840 placements. No verse number moved, and the caret was always drawn right after its number. A second run at wider widths, in both LTR and RTL, gave the same result.
- Both host CSS rules are needed. Removing the word joiner moved 21–30 of 40 verses, and removing
text-wrap-mode: nowrapmoved 33–40. The comment's claim that a run of empty verses has no other break opportunity is correct. - The TS changes are guarded by tests. Dropping the host self-exemption fails 4 tests, and reverting the ActiveTextPlugin change fails 1.
I've left inline comments with the Medium and Low items. Two Medium items should be addressed before merge: the Markers view reflow and Delete with protection off. Several of the Low items come from the host now surviving between two verses, which is the point of the fix. Where one already happens on main at a paragraph-end host, I've said so.
Everything was rechecked on 0d196171, after the rebase onto #33's latest commit.
Severity: Medium = fix before merge, or ticket explicitly · Low = worth doing.
Low: "Known limitations" understates the arrow-key behavior, which this PR makes common.
- Dead ArrowRight: every empty verse followed by another verse now costs one ArrowRight press that does nothing visible. From host offset 0 the caret moves to offset 1, which is drawn at the same x. This happens in Simple and Formatted views; ArrowLeft is fine.
- Shift+ArrowRight never extends, and not just on the first press. Each press selects the placeholder. The guard reads that range as having left the host and collapses it back. After 3 presses the selection was still collapsed at (host, 0).
- Already on
mainat a paragraph-end host. This PR makes it the common case.
Suggest correcting the limitation to "every Shift+Arrow press", adding the dead ArrowRight, and ticketing both against the host machinery.
…rdening # Conflicts: # packages/platform/dist/index.js # packages/platform/dist/index.js.map
…ty verse In Simple (paragraph-structure) view, placing the insertion point in an empty verse reflowed the line, and drew the caret at the start of the next line instead of right after the verse number, although typed text landed in the right place. Two causes: - TextSpacingPlugin added its structural trailing space to the caret host that EmptyVerseCaretGuardPlugin puts after an empty verse's number. Spaced, the host looked typed into, so it was stripped and removed in the update that created it, and the caret fell back to the element point between two verse markers, which Chromium draws at the start of the next verse. That is the next line when the empty verse ends one. The host is now exempt, and text pasted in front of one is spaced against the verse past it. - ActiveTextPlugin dropped the active verse's ellipsis. That shrank the line, and exposed the verse number's trailing zero-width space as a new line-break opportunity. A run of empty verses otherwise has none, so it wraps only where it overflows. The active empty verse now gets psc-empty-text-active instead of losing psc-empty-text. The stylesheet keeps its ellipsis in place but transparent, as a fixed-width box. The caret host is pulled back over it by a margin of the same width and pushes what follows forward by the same amount, so it takes no room of its own and its caret is drawn right after the number. The host doesn't wrap and ends in a word joiner, so its zero-width space adds no break opportunity. The box rules skip visible-marker verses, whose ::after is the number itself. Builds on the caret host hardening, which made a host that stays alive between verses safe. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Mirror the caret-host mark onto the host's DOM as `data-caret-host`, and target the stylesheet's host rules at it. The no-wrap rules now apply in every view (Markers view reflowed), and real whitespace after a verse no longer matches. - With structure protection off, a delete from an empty verse's host runs from the boundary the host stands for, so it reaches the verse marker instead of only removing the placeholder. - TextSpacingPlugin looks past a host for a whitespace-only verse, a pasted char span before the next verse, and an annotation over a resting host, so each change lands in the commit the app hears about. - ActiveTextPlugin draws no focus box after a blur, leaves clicks in an editable verse marker and double-clicks alone, and clicks into an existing host. - Pin the empty-verse CSS contract, test both transform mount orders, add a CHANGELOG entry, and fix comments. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
0d19617 to
f497fe8
Compare
|
On the arrow-key item in your summary: I corrected the description's known limitations. They now list the dead ArrowRight press, and say Shift+Arrow never extends on any press. Both come from the host machinery and are already on |
katherinejensen00
left a comment
There was a problem hiding this comment.
Approving because there is nothing worth blocking the merge over. There are three things you may want to consider changing. The PR will still be approved and mergeable even if you make another commit to fix the three.
- An empty verse at the end of a paragraph now merges paragraphs on Delete. With protection off, Delete from there merges the next paragraph in and silently drops its marker (\q in my probe). Before this commit it did nothing.
- My probe showed an ordinary paragraph-end Delete in that mode does the same, so this is consistent.
- But it isn't tested, and the TSDoc on $deleteFromEmptyVerseHost only mentions reaching the verse marker. It's worth a test and a sentence there.
- Only single-character deletes are redirected. Ctrl+Delete and Ctrl+Backspace from the host probably still remove only the placeholder. I couldn't check this, because jsdom can't run word deletes. It's worth a manual check in the app.
- Nit: the same mutation listener is registered three times. Each of the three caret guards that use useTransientCaretHost registers it. Each copy runs over every text-node change on every commit, doing the same work.
@katherinejensen00 reviewed 12 files and all commit messages, made 1 comment, and resolved 16 discussions.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on timothy-mccormack).
…te listener - Word and line deletes from an empty verse's host are redirected to the boundary the host stands for, like character deletes. Run from the host, they removed only the placeholder. - Document and test what a forward delete does from an empty verse ending a paragraph with protection off: it merges the next paragraph in, as Delete at the end of any paragraph does in that mode. - Register the host-attribute mutation listener once per editor rather than once per caret guard. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
All three are handled in 92011d2.
Locally: shared 895, shared-react 2291 and platform 4134 pass; typecheck, lint and prettier clean; committed dist verified. |
katherinejensen00
left a comment
There was a problem hiding this comment.
Thanks for fixing those, Tim!
@katherinejensen00 reviewed 5 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on timothy-mccormack).
…ty verse (#2942) The app styles the editor from its own vendored stylesheet, so the CSS half of the PT-4885 fix lands here (paranext/scripture-editors#33 and paranext/scripture-editors#34 carry the editor half). Both vendored copies, `_usj-nodes.scss` and the demo `usj-nodes.css`, gain the rules: - The empty-verse ellipsis is a fixed-width box (`--psc-empty-verse-ellipsis-width`: 13px in the app copy, deliberately, 18px in the demo copy). The verse holding the caret keeps it but hides it. - The caret host (`[data-caret-host]`) is pulled back over the hidden ellipsis by an equal margin, so the caret is drawn right after the number, and in every view a host after a verse takes `nowrap` and a trailing word joiner, so the line neither changes width nor wraps. - The app copy gains the demo copy's RTL `.verse` / `.verse.marker` isolation rules, without which the caret was drawn beside the next verse's number in RTL projects. Both headers record where the rules came from. The style tests pin each load-bearing declaration on its exact selector list. Checked by hand on macOS in LTR and RTL projects and with forced colors. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Stacked on #33, which hardens the caret host so it is safe to keep alive between verses. Review that one first; this diff shows only PT-4885's own changes. A paranext-core PR carries the matching stylesheet rules, since the app styles the editor from its own vendored copy.
The bug
In Simple mode (paragraph-structure view), clicking or arrowing into an empty verse:
Why
The fix
data-caret-host(CARET_HOST_ATTRIBUTE), copied from the node's mark by a mutation listener, so the stylesheet can target the host itself rather than whatever text follows a verse.$hasCaretHostMark, added here, which asks about the mark alone so the answer does not depend on transform order). Every sibling check looks past a host, so these land in the commit the app hears about, not the later host-removal commit:psc-empty-text-activeinstead of just losingpsc-empty-text.usj-nodes.css):--psc-empty-verse-ellipsis-width).forced-color-adjust: none), so the line's width and its break points don't change.[data-caret-host]) is pulled back over it bymargin-inline-start: -widthand pushes what follows forward bymargin-inline-end: width. It takes no room, and its caret is drawn right after the number.text-wrap-mode: nowrapand a::afterword joiner, so its zero-width space adds no break opportunity.text-wrap-moderather thanwhite-space, which would turn a typed space into a no-break space..markerverses (visible markers), whose::afteris the verse number itself.usj-nodes.cssneeds the new rules.Testing
usj-nodes.css.test.ts, reading the class names and attribute from their constants) are covered too.\pof 40 empty verses, placing the caret after each verse in turn.data-caret-host, and the caret was drawn about 2px past the number's glyph.markerMode: "visible"), at 433 and 640px: no verse number moved. With the two no-wrap rules disabled, 37 and 36 of 40 placements moved.Known limitations
mainat a paragraph-end host; this PR makes them the common case:🤖 Generated with Claude Code
This change is