Skip to content

fix(open_file): select in the preview window when preview is true - #375

Merged
ThomasK33 merged 2 commits into
mainfrom
fix/open-file-preview-selection
Nov 1, 2026
Merged

ThomasK33 merged 2 commits into
mainfrom
fix/open-file-preview-selection

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Why

This PR is one of the small, reviewed fixes that close the open follow-up issues in claudecode.nvim. With preview: true, openFile runs :pedit, which shows the file in the preview window and keeps the cursor in the main window. openFile then selected in the main window's file. Lines 2 to 3 selected two/three of other.txt, not beta/gamma of the previewed hello.txt. A startText search looked in the wrong file too, and the makeFrontmost: false answer reported the wrong file's lineCount and languageId.

openFile now uses the preview window after :pedit. makeFrontmost focuses it, because Visual mode exists only in the current window. The VS Code extension also selects in the editor it opens, with or without preview.

What changed

  • openFile finds the preview window in the tab page where :pedit ran. It uses that window for the selection, the cursor, the focus, and the JSON details. It raises -32000 when no preview window exists after :pedit.
  • A unit spec mocks :pedit the way Neovim runs it, and a real-Neovim spec checks the selected text. lua/claudecode/tools/README.md describes the behavior.

Scope

  • Covers preview: true with line ranges, text ranges, makeFrontmost: false, and a pending operator.
  • The :edit path does not change. The other items of the issue get their own PRs.

Blast Radius

Only openFile calls with preview: true change. With makeFrontmost true (the default), the focus now goes to the preview window. Before, it went to the main window, which did not show the file.

Verification

  • Headless Neovim 0.8.3 and 0.12.3, 'selection' inclusive and exclusive, four layouts (one window, focus in a side window, no editor window, editor in another tab page). Before, every preview case selected in or searched the wrong file. After, every case selects beta/gamma in the preview window, and no buffer text changes. A pending d is cancelled and the next w only moves the cursor. With 'selectmode' set to cmd, Select mode starts in the preview window and nothing is typed over it. Both versions give the same results.
  • Live run with the verify-claudecode-nvim harness on 0.12.3. getCurrentSelection and selection_changed report beta\ngamma from hello.txt.
  • The 3 new unit tests and the real-Neovim spec fail on the test commit and pass with the fix. mise run check, mise run test (833 passed), and the integration suite on 0.8.3 and 0.12.3 (21 passed each) pass.

Before the fix, the selection is in other.txt:

Before: the selection is in other.txt

After the fix, the selection is in the preview window:

After: the selection is in the preview window

Part of #374


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

With `preview: true`, openFile runs `:pedit`, which shows the file in
the preview window and leaves the cursor in the main window. The
selection, the text search, the focus and the makeFrontmost=false
details all use the main window, which still shows another file.

The unit spec mocks `:pedit` the way Neovim runs it, and the real-Neovim
spec checks the selected text. Both fail until the next commit.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
`:pedit` shows the file in the preview window and leaves the cursor in
the window it ran in. openFile kept using that window, so it selected
lines in the main window's file, searched startText there, focused it
for makeFrontmost, and described its buffer in the makeFrontmost=false
answer.

openFile now looks up the preview window after `:pedit` and uses it for
all four. makeFrontmost focuses it, as the VS Code extension focuses the
editor it selects in. A missing preview window raises -32000.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T02:30:21.800242Z 62e911a Manual request
🔒 Security Review ✅ Completed 2026-11-01T02:30:32.677529Z 62e911a Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 62e911a9ea

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 62e911a9ea

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit ed9000e Nov 1, 2026
5 checks passed
@ThomasK33
ThomasK33 deleted the fix/open-file-preview-selection branch November 1, 2026 02:53
@github-actions github-actions Bot mentioned this pull request Nov 1, 2026
ThomasK33 added a commit that referenced this pull request Nov 1, 2026
…in again

Main changed selection.lua, utils.lua, openFile (#375), and the server's
send path (#378, which makes each outbound message valid UTF-8). None of
them changes a diff's status, which diffs close, or how many answers a
call gets. check.sh passes on the merged tree.

Part of #363

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
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.

1 participant