Skip to content
This repository was archived by the owner on Apr 25, 2026. It is now read-only.

Fix click cursor animation detaching on page scroll#8

Merged
4fuu merged 2 commits into
mainfrom
fix/cursor-scroll-detach
Mar 28, 2026
Merged

Fix click cursor animation detaching on page scroll#8
4fuu merged 2 commits into
mainfrom
fix/cursor-scroll-detach

Conversation

@4fuu
Copy link
Copy Markdown
Owner

@4fuu 4fuu commented Mar 28, 2026

Summary

  • Track the active target element during click/type operations via a new activeTarget field on CursorAgent
  • Add a scroll event listener that repositions the cursor overlay to the target's updated viewport coordinates
  • Hide the cursor when the target scrolls out of view
  • Clear activeTarget on endTask() and stop()

Test plan

  • Click an element that triggers a page scroll (e.g. anchor link, scrollIntoView)
  • Verify the cursor pulse animation follows the target instead of staying at the old position
  • Verify cursor hides when target scrolls completely out of view
  • Verify normal click/type behavior is unaffected when no scroll occurs

Closes #1

Track the active target element during click/type operations and
reposition the cursor overlay on scroll events. When the target
remains in the viewport, the cursor follows it; when the target
scrolls out of view, the cursor is hidden.

Closes #1
@4fuu
Copy link
Copy Markdown
Owner Author

4fuu commented Mar 28, 2026

@codex review this pr

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf58df008c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return;
}
if (this.activeTarget) {
const rect = this.activeTarget.getBoundingClientRect();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Skip scroll tracking for detached active targets

When a click/type action causes the target node to be unmounted before endTask() runs (common in SPA rerenders), this.activeTarget can remain set to a detached element and getBoundingClientRect() returns a zero rect. The current check then treats (0,0) as in-viewport and moves the cursor to the top-left corner on subsequent scroll events, which is a visible regression during post-action stability waits. Guarding with isConnected (or clearing activeTarget) avoids this misplacement.

Useful? React with 👍 / 👎.

Comment thread extension/src/content/content-script.ts Outdated
Comment on lines +112 to +113
centerX >= 0 && centerX <= window.innerWidth &&
centerY >= 0 && centerY <= window.innerHeight
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3 Badge Determine target visibility from rect intersection

The scroll handler hides the cursor as soon as the target’s center point exits the viewport, but that does not mean the element is fully out of view. For partially visible elements near an edge, the cursor is hidden prematurely even though the target is still visible, which conflicts with the intended "hide only when out of view" behavior. Use rectangle intersection against the viewport instead of center-point inclusion.

Useful? React with 👍 / 👎.

@4fuu 4fuu merged commit 796165f into main Mar 28, 2026
2 checks passed
@4fuu 4fuu deleted the fix/cursor-scroll-detach branch March 28, 2026 16:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Click cursor animation becomes detached when the page scrolls after a click

1 participant