Repository navigation
fix(open_file): keep the user's Visual mode, unsaved changes and focus - #387
Conversation
- Visual or Select mode that CTRL-O started from Insert mode takes the normal path: openFile edits the file into the user's window and ends the user's selection, and Insert mode then resumes in the opened file. - A window that already shows the file with unsaved changes makes openFile fail: :edit and :pedit re-read it and stop with E37. - With only the preview window and a terminal, openFile splits the small preview window instead of the terminal. - With no editor window and makeFrontmost=false, the focus moves to the split openFile makes. The specs fail until the next commit. The preview mock now models how :edit and :pedit re-read a shown file and end Visual mode, and the fallback mock models wincmd and vsplit. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
- Visual or Select mode that CTRL-O started from Insert or Replace mode now counts as the middle of a command on Neovim 0.10 and later, where state() shows it with "S". openFile then shows the file in the preview window and the user's selection stays. - A loaded buffer is shown as it is. openFile no longer runs :edit in a window that already shows the buffer, and it no longer runs :pedit: both re-read that buffer, which failed with E37 on unsaved changes and opened the folds of the user's diff windows, and :pedit also ended Visual mode. The preview path now loads the buffer and makes the preview window the way :pedit does. - In the middle of a command openFile sends no keys at all, so it no longer centers the preview window on a text match. - The fallback splits the window below the preview window, not the small preview window, and with makeFrontmost=false it gives the focus back. The READMEs now name the new-tab and split paths of openDiff, the outline sidebars, and what makeFrontmost=false with preview selects. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…followups # Conflicts: # lua/claudecode/README.md
|
@codex review |
|
@codex security review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 11afa73bb2
ℹ️ 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".
…e preview path - An existing preview window with 'winfixbuf' set makes openFile fail with E1513, while :pedit shows the file there and keeps the option. - An autocommand that clears 'previewwindow' when the window gets the file leaves openFile answering success with no preview window, while :pedit answered -32000. The specs fail until the next commit. The preview mock now models 'winfixbuf', which nvim_win_set_buf refuses and a split does not copy. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…ewwindow' after - openFile clears 'winfixbuf' on the preview window while it shows the file there and sets it again after, so a pinned preview window gets the file as with :pedit, instead of failing with E1513. - After the preview window gets the file, openFile checks that the window is still valid and still has 'previewwindow' set. When an autocommand cleared it or closed the window, openFile raises -32000 "No preview window shows the file", as it did with :pedit. tools/README.md documents the new error data and the 'winfixbuf' case. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…he file changed on disk When a window already shows the loaded buffer, openFile neither runs :edit nor switches the buffer, so Neovim does not check the file on disk. After Claude writes the file, openFile then searches the old text: startText is not found. On main, :edit and :pedit re-read it. The specs fail until the next commit. The preview mock now models how entering a buffer, :edit and :checktime load a changed file again, and how Neovim asks the user when the buffer has unsaved changes. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
When a window already shows the loaded buffer, openFile now runs :checktime for it, as Neovim does when a window enters a buffer. So after Claude writes the file, openFile searches the new text, as :edit and :pedit did before. The check runs only when the buffer has no unsaved changes: for a changed buffer Neovim asks the user, and the user's next key would answer. An unchanged file is not read again, so the folds of other windows on the buffer stay. The preview mock now reports 'modified' from the buffer. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…d of the preview path - With 'noautoread', the :checktime that openFile runs for a shown buffer whose file changed on disk makes Neovim ask the user. The user's next key answers, and the reply waits for it. - For a file that is not loaded yet, the preview path loads it with bufload() in Neovim's hidden autocommand window. FileType options for the window are lost, and BufEnter runs twice. The specs fail until the next commit. The preview mock now models 'autoread', FileChangedShell and v:fcs_choice, and which window loads and enters a buffer. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…eview in its window - When a window already shows the buffer and its file changed on disk, openFile now adds a one-shot FileChangedShell autocommand for that buffer that chooses "reload", then runs :checktime. With 'noautoread', :checktime alone asked the user: the reply waited for the answer, and in the middle of a command the dialog took the user's typed keys. A buffer with unsaved changes is still not checked. - The preview path no longer runs bufload() before nvim_win_set_buf(). bufload() loaded the file in Neovim's hidden autocommand window, so FileType options for the window were lost in the preview window, and BufEnter and BufWinEnter ran twice. nvim_win_set_buf() now loads it in the preview window, once, as :pedit did. tools/README.md now says that openFile reloads without asking, and what the mode is after a CTRL-O Visual openFile on Neovim 0.8 and 0.9. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…den changed buffer - When the buffer is loaded but not shown in the window openFile uses, :edit and nvim_win_set_buf() enter it, and Neovim checks its file on disk. After Claude rewrote the file, Neovim asks the user (W12 for unsaved changes, W11 with 'noautoread'). The reply waits, and the user's next `l` loads the file and drops the unsaved changes. - With 'eventignore' set to ignore FileChangedShell, openFile's :checktime still asks with 'noautoread'. - A user's FileChangedShell autocommand that runs `autocmd!` makes openFile's nvim_del_autocmd() fail. The specs fail until the next commit. The preview mock now models 'eventignore' and the failing delete. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…le enters a buffer openFile now runs :edit and nvim_win_set_buf() for a loaded buffer, and :checktime, with a one-shot FileChangedShell autocommand for that buffer. It keeps a buffer with unsaved changes as it is and loads one without unsaved changes again. Before, entering a hidden buffer whose file Claude rewrote made Neovim ask (W12 for unsaved changes, W11 with 'noautoread'): the reply waited, and the user's next `l` loaded the file and dropped the unsaved changes. openFile skips :checktime when 'eventignore' ignores FileChangedShell, because Neovim would ask without the autocommand. Deleting the autocommand no longer fails when a user's autocommand ran `autocmd! FileChangedShell`. tools/README.md describes when Neovim can still ask. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb1097b085
ℹ️ 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".
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Why
This PR is one of the small, reviewed fixes that close the open follow-up issues in claudecode.nvim (#385). It covers the openFile items of #385 item 5, and one more bug found while testing them.
i<C-o>v, then openFile: openFile ended the user's Visual mode, selected in the opened file, and Insert mode resumed there. The user's next keys acted on Claude's selection. In the live run,lddeletedbetaandgammafrom the opened file.E37: No write since last change.:editand:peditre-read the shown buffer. The preview path also left a stray preview window. This happens when the user types in the file Claude opens.makeFrontmost: false, openFile left the focus in the split it made.What changed
All code changes are in
lua/claudecode/tools/open_file.lua.state()showsS. openFile then shows the file in the preview window and leaves the user's mode alone. On 0.8 and 0.9 this mode looks like plain Visual mode: after the call the mode isvwith Claude's selection, and the user's next Visual command acts on it. The README documents that.:editwhen the window already shows the buffer, and the preview path no longer runs:pedit. It puts the buffer in the preview window withnvim_win_set_buf(), which loads a new file there, so BufReadPost, FileType and BufEnter run once, in the preview window, as with:pedit. It makes that window with the options:peditsets when the tab page has none.:peditalso ended Visual mode.:pedit, the preview path shows the file in a preview window that has 'winfixbuf' set, and keeps the option. When an autocommand clears 'previewwindow' as the window gets the file, openFile answers-32000, as before.:editandnvim_win_set_buf()for a loaded buffer, and:checktimefor a buffer the window already shows, with a one-shot FileChangedShell autocommand for that buffer. The autocommand loads a buffer without unsaved changes again, as:editdid, and keeps a buffer with unsaved changes as it is. An unchanged file is not read again. On main, entering a hidden buffer with unsaved changes asked W12, and the user's nextlloaded the file and dropped the changes. The README names the two cases where Neovim can still ask ('eventignore' that ignores FileChangedShell, and a user's autocommand that deletes openFile's).zzon a text match.makeFrontmost: falseit gives the focus back.lua/claudecode/README.md(Diffs) names openDiff's new-tab and split paths.lua/claudecode/tools/README.mdnames outline sidebars, the CTRL-O Visual case, and the preview case ofmakeFrontmost: false.Scope
preview: truewithmakeFrontmost: falsewhen the current window shows the file, is kept as it is and documented. The file goes to the preview window, which gets the marks but no selection, because Visual mode exists only in the current window."aregister prefix stays documented. On 0.10 and laterstate()can tell it apart. That is a follow-up.diff.luais unchanged, because another PR owns it. openDiff can still split the preview window when no other editor window exists, and the unused legacydiff.open_difffallback has no preview-window check.Blast Radius
openFile only. Normal-mode openFile into a window that does not show the file runs
:editas before. The preview window now shows a loaded buffer without re-reading it from disk. The mid-command and preview paths change only as described above.Verification
other.txt, then Claude opensother.txtat line 3. Before:-32000withE37and a stray preview window. After: the preview window shows line 3, and the user keeps typing.i<C-o>v, Claude openshello.txtwithstartText/endText, and the user typesld. Before:hello.txtlostbetaandgamma, and Insert mode resumed inhello.txt. After:hello.txtis unchanged, Visual mode stays inother.txt,lddeletesonthere, and Insert mode resumes inother.txt.i<C-o>vcase on 0.8 and 0.9. The openFile matrix from fix(open_file): leave the user's window alone in the middle of a command #382 (1,120 runs) gives the same results before and after, except 48 runs that change as intended: the user's diff window keeps its closed fold, so the user'sdwacts as in plain Vim, and a pendingdvkeeps its forced motion (modenov). The fix(open_file,diff): never pick the preview window as the main editor window #384 window-choice runs still keep the file out of the preview window (12 of 12).startTextin the new text. An earlier commit of this PR (522788d) searched the old text.hello worldbecamelo world. Now, as on main, the reply comes at once, the file shows the new text, and the typed text is intact (alphaabchello world).l: on 32cc297, 3 of 4 runs showed the W11/W12 dialog and held the reply, andlloaded the file and dropped the unsaved edits. Now all 4 reply at once with no dialog, the clean buffer shows Claude's text, and the unsaved edits stay. The same holds while the user types in another file (the preview path).dvkeeping modenov(32 of 1,568), the fix(open_file,diff): never pick the preview window as the main editor window #384 matrix only in the split below the preview window (8 of 416). In the openFile probes, events for a new file run once in the preview window, FileType window options stay there, and a clean changed file reloads with and without 'autoread', as on main.mise run check,mise run test(947 passed, shuffled), and the integration suite on 0.8.3 and 0.12.3 (21 passed each) pass on the head.Before the fix,
ldafteri<C-o>vdeleted Claude's selection inhello.txt:After the fix,
hello.txtis unchanged in the preview window, andlddeletedonin the user's file:Part of #385
Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:xhigh