Skip to content

fix: Activation with the caret at a line's end puts the Cursor on that line's last character (#99) - #102

Merged
Kyu-seok merged 2 commits into
mainfrom
issue-99
Nov 22, 2026
Merged

Kyu-seok merged 2 commits into
mainfrom
issue-99

Conversation

@Kyu-seok

Copy link
Copy Markdown
Owner

Closes #99.

Summary

The Field's caret at Activation is the mirror's first cursor. The engine does not clip an empty selection given from outside, so at a line's end the Cursor sat one past the last character. Session's constructor now clips a caret with clipToLine, the rule a caret the person moves later already goes through.

 new Session(field)
   sel = field.getSelection()
   new Mirror({
-    cursor: sel.head
+    cursor: sel is a caret ? clipToLine(doc, sel.head) : sel.head
   })
   render()            # the Field's selection now reads as a Normal Cursor on the last character

Both ways a Session is made (the Activation key, focus on a Site whose policy is "normal") go through this constructor. A selection held at Activation is given as before (out of the brief's scope; a unit test pins it).

Coverage (CODING_STANDARDS rule 5): Normal, the only Mode a Session is made in; a textarea, a Single-line Field, a plain contenteditable, a contenteditable in an open shadow root, a block of the Notion shape.

Evidence

  • Before: npm run red-on-main -- tests/e2e/activation-line-end.spec.ts tests/unit/session.test.ts on main's source: the unit test reads the textarea's selection as [59, 59], expected [58, 59]; 15 of the 16 e2e tests then in the spec fail (the empty-line test passes there by design: that behaviour stays as it was). The shadow-root case and the held-selection unit test were added after that run.
    After: tests/e2e/activation-line-end.spec.ts 18 passed. Per Field kind:

    caret at a line's end, the Activating Esc
      the Cursor is on the line's last character   # one selected character, or a caret before it with the block drawn and painted over it
      l  -> stays
      h  -> the character before it
    fresh run, x -> the line's last character is gone, nothing else
    

    npm run check: 289 e2e passed, 0 failed, 0 flaky. npm run test:e2e:editors: 295 passed, 0 failed, 0 flaky.

Merge Danger

Door: two-way

One expression in Session's constructor; reverting it restores the old cursor.

Blast Radius: Activation

Every Activation with a caret goes through the clip. A caret anywhere but a non-empty line's end is unchanged. The clip splits lines on \n only while the mirror also splits on \r; a textarea never holds one, not checked for a contenteditable projection.

🤖 Generated with Claude Code

Kyu-seok and others added 2 commits November 22, 2026 23:25
…t line's last character (#99)

The Session gave the mirror the Field's caret as its first cursor as it
was. The engine does not clip an empty selection given from outside, so at
a line's end the Cursor sat one past the last character: the block drawn
past the text, no selection at all on a textarea or a Single-line Field,
and the first `l` moving it left. The constructor now clips a caret with
`clipToLine`, the rule a caret the person moves later already goes through.
A selection held at Activation is given as before (out of scope).

Coverage (CODING_STANDARDS rule 5): Normal, the Start Mode, the only Mode a
Session is made in. Placements: a textarea (the text's end and an inner
line's end), a Single-line Field, a plain contenteditable, a contenteditable
in an open shadow root, a block of the Notion shape (one line; three lines
at the text's end and at the first line's end), and a Field Activated by
focus on a Site whose policy is "normal".

Red on main: `npm run red-on-main -- tests/e2e/activation-line-end.spec.ts
tests/unit/session.test.ts`. The empty-line test and the held-selection
unit test pass there by design: they guard what stays as it was.

`caretCharBox` and `near` move from drawn-cursor.spec.ts to extension.ts,
shared by the new spec.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
# Conflicts:
#	src/bridge/Session.ts
@Kyu-seok
Kyu-seok merged commit 98bdf9b into main Nov 22, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Activation with the caret at a line's end leaves the Cursor one past the last character, on every Field kind

1 participant