Skip to content

Go to Selection Anchor: reveal the anchor position - #350427

Merged
Alexandru Dima (alexdima) merged 1 commit into
mainfrom
agents/fix-go-to-selection-anchor-reveal
Nov 28, 2026
Merged

Alexandru Dima (alexdima) merged 1 commit into
mainfrom
agents/fix-go-to-selection-anchor-reveal

Conversation

@alexdima

Copy link
Copy Markdown
Member

Fixes #347657

When you set a selection anchor, scroll away from it and run Go to Selection Anchor, the cursor moves to the anchor but the editor does not scroll. The anchor stays off-screen until you press an arrow key or type.

Demo

issue-347657-before-after.png

Change

SelectionAnchorController.goToSelectionAnchor() only called editor.setPosition(). That moves the cursor but asks for no reveal. It now also calls editor.revealPositionInCenterIfOutsideViewport(position, ScrollType.Smooth). This is the same reveal that other navigation commands use, such as Go to Definition (goToCommands.ts), Go to Next Problem (gotoErrorWidget.ts) and fold navigation (folding.ts). When the anchor is already visible, the view does not move. When it is off-screen, it is centered.

SelectionAnchorController is now exported so that the new unit test can get it from a test editor.

How it was tested

  • ./scripts/test.sh --runGlob '**/anchorSelect.test.js': the new test "Go to Selection Anchor reveals the anchor" passes. Without the fix it fails, because no reveal is requested (reveals: []).
  • pnpm run oxlint src/vs/editor/contrib/anchorSelect/browser/anchorSelect.ts src/vs/editor/contrib/anchorSelect/test/browser/anchorSelect.test.ts: no problems.
  • pnpm run typecheck-client: passed.
  • I recorded a UI scenario (a 120-line file; Set Selection Anchor on line 1; scroll down and click line 41; Go to Selection Anchor). On Insiders 1.148.0-insider (Linux), its check fails: the cursor is at Ln 1, Col 1 but the top visible line is still line 16. On a build of this branch, it passes: line 1 is scrolled into view.

Before / after

Before

issue-347657-go-to-selection-anchor-insiders.mp4

After

issue-347657-after-fix.mp4

🤖 Authored with GitHub Copilot on behalf of Alexandru Dima (@alexdima).

Go to Selection Anchor moved the cursor to the anchor without asking the
editor to reveal it, so the anchor stayed off-screen until the next key
press. Reveal the position (centered when outside the viewport), like
other navigation commands do.

Fixes #347657

🤖 Authored with GitHub Copilot on behalf of @alexdima.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 17:20

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

No active review issues remain for the change that brings off-screen selection anchors into view.

No open issues 🎉

What changed in this PR

Fixes #347657 by making Go to Selection Anchor bring off-screen anchors into view, consistent with other editor navigation commands.

Changes:

  • Requests a smooth, centered reveal when the anchor is outside the viewport.
  • Exports SelectionAnchorController and adds a regression test for the cursor destination and reveal request.

No actionable findings remain.

File Description
src/​vs/​editor/​contrib/​anchorSelect/​test/​browser/​anchorSelect.test.ts Verifies navigation restores the anchor position and requests the expected reveal.
src/​vs/​editor/​contrib/​anchorSelect/​browser/​anchorSelect.ts Reveals the anchor after moving the cursor and exports the controller for testing.

Review effort: Balanced

@alexdima
Alexandru Dima (alexdima) marked this pull request as ready for review November 28, 2026 19:13

@bhavyaus Bhavya U (bhavyaus) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Small, low-risk fix: Go to Selection Anchor now reveals the anchor via the same reveal used by other navigation commands. Diff and new test look right, and CI is green.

@alexdima
Alexandru Dima (alexdima) added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 5b559f5 Nov 28, 2026
38 checks passed
@alexdima
Alexandru Dima (alexdima) deleted the agents/fix-go-to-selection-anchor-reveal branch November 28, 2026 21:34
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.

Go to Selection Anchor does not reveal the position

4 participants