Skip to content

refactor(caret): extract moveTo, add goToNow and updatePositionNow (@miodec) - #8493

Closed
Miodec wants to merge 1 commit into
masterfrom
caret-go-to-now
Closed

Miodec wants to merge 1 commit into
masterfrom
caret-go-to-now

Conversation

@Miodec

@Miodec Miodec commented Oct 21, 2026

Copy link
Copy Markdown
Member

Summary

Split out of #8491 (Solid Words component) to shrink its diff. No behaviour change on master: the existing goTo / updatePosition path is the same code, moved into moveTo.

 Caret (elements/caret.ts)
-  goTo(options)
-    requestDebouncedAnimationFrame("caret.<id>.goTo", () => ...measure + animate...)
+  goTo(options: GoToOptions)
+    requestDebouncedAnimationFrame("caret.<id>.goTo", () => this.moveTo(options))
+  goToNow(options: GoToOptions)            // new, unused on master
+    cancelPendingAnimationFrame("caret.<id>.goTo")
+    this.moveTo(options)
+  private moveTo(options)                  // old goTo body, unchanged

 test/caret.ts
-  updatePosition(noAnim) -> caret.goTo({...})
+  positionOptions(noAnim)                  // shared options builder
+  updatePosition(noAnim) -> caret.goTo(positionOptions(noAnim))
+  updatePositionNow(noAnim) -> caret.goToNow(positionOptions(noAnim))   // new, unused on master

goToNow / updatePositionNow are used by #8491, where the caret moves inside the shared words frame right after the DOM update instead of queueing its own frame.

Evidence

  • Browser (master renderer): caret starts at letter 0, after wa sits before letter 2, after extra letters + space + h sits before letter 1 of the next word.
  • frontend/__tests__/test + __tests__/elements (258) pass.

Merge Danger

Door: two-way

Blast Radius: caret

Pure extraction; the moved body is unchanged (diff is mostly re-indentation).

🤖 Generated with Claude Code

…Miodec)

goTo keeps queueing the move in a debounced animation frame; goToNow
cancels that frame and moves immediately, for callers that already run
in a frame after the words DOM is updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 15:51
@monkeytypegeorge monkeytypegeorge added the frontend User interface or web stuff label Oct 21, 2026
@github-actions github-actions Bot added the waiting for review Pull requests that require a review before continuing label Oct 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is a faithful, behavior-preserving extraction with verified dependencies and matching frame-id handling, and the new immediate-move helpers are isolated and unused on master.

No open issues 🎉

What changed in this PR

This PR is a pure, behavior-preserving refactor of the test caret, split out of #8491 to shrink that PR's diff. It extracts the body of Caret.goTo into a new private moveTo method and introduces an immediate (non-debounced) path (goToNow / updatePositionNow) that #8491 will use to move the caret inside the shared words animation frame instead of queuing its own frame. On master these new functions are introduced but unused.

Changes:

  • Extract goTo's rAF callback body into private moveTo(options); goTo now just schedules moveTo via requestDebouncedAnimationFrame.
  • Add goToNow(options) which cancels any pending debounced frame (caret.<id>.goTo) and runs moveTo synchronously; hoist the inline options type into a reusable GoToOptions type.
  • In test/caret.ts, factor shared option-building into positionOptions(noAnim) and add updatePositionNow wrapping goToNow.
File Description
frontend/​src/​ts/​elements/​caret.ts Extracts moveTo, adds goToNow, imports cancelPendingAnimationFrame, hoists GoToOptions type.
frontend/​src/​ts/​test/​caret.ts Adds shared positionOptions builder and new updatePositionNow that calls goToNow.

I verified that cancelPendingAnimationFrame is exported (utils/debounced-animation-frame.ts:23) and uses the same frame id (caret.<id>.goTo) as requestDebouncedAnimationFrame, that the extracted moveTo body is logically identical to the prior goTo callback (only re-indentation/reformatting), and that Parameters<Caret["goTo"]>[0] resolves to the new GoToOptions type so positionOptions stays correctly typed. No issues found.

Review effort: Balanced

@Miodec
Miodec marked this pull request as draft October 21, 2026 15:54
@github-actions github-actions Bot removed the waiting for review Pull requests that require a review before continuing label Oct 21, 2026
@Miodec

Miodec commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

Folded into #8491: the caret moves synchronously there, so goToNow isn't needed.

@Miodec Miodec closed this Oct 21, 2026
@Miodec
Miodec deleted the caret-go-to-now branch October 21, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend User interface or web stuff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants