Skip to content

fix(picker_ui): don't :edit the current buffer on select (E37 on modified file) - #907

Merged
dmtrKovalenko merged 1 commit into
dmtrKovalenko:mainfrom
TNVC:fix/select-modified-current-buffer
Oct 9, 2026
Merged

dmtrKovalenko merged 1 commit into
dmtrKovalenko:mainfrom
TNVC:fix/select-modified-current-buffer

Conversation

@TNVC

@TNVC TNVC commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Selecting the file that is already open in the current window fails when its
buffer has unsaved changes:

vim.schedule callback: [string "vim/_core/editor"]:353: nvim_exec2(), line 1: Vim(edit):E37: No write since last change (add ! to override)
stack traceback:
    [C]: in function 'nvim_exec2'
    [string "vim/_core/editor"]:353: in function 'cmd'
    .../lua/fff/picker_ui/picker_ui.lua:547: in function <.../lua/fff/picker_ui/picker_ui.lua:509>

The error aborts the rest of the vim.schedule callback, so for a file:line
query the jump to the location never happens. Selecting any other file from a
modified buffer works.

Reproduction

  1. Open foo.txt and change it without saving.
  2. :lua require('fff').find_files(), type foo.txt:3.
  3. Select foo.txt (marked (current)).

Expected: the picker closes, unsaved changes are kept, the cursor is on line 3.
Actual: E37, the cursor stays where it was.

Reproduced with nvim --clean (Neovim 0.12.5, Linux) on current main (c188e7a).

Cause

The edit action always runs :edit <path> (picker_ui.lua:547). When <path>
is the file of the current buffer, :edit means "reload from disk", which Neovim
refuses for a modified buffer with E37 regardless of 'hidden':

:edit other.txt    " from a modified buffer -> ok (with 'hidden')
:edit current.txt  " from a modified buffer -> E37

Fix

Skip :edit when the selected path resolves to the current buffer; only the
location jump runs. Buffer identity is checked with vim.fn.bufadd(path), which
resolves names the same way :edit does. A plain path comparison
(fnamemodify(path, ':p') == nvim_buf_get_name(0)) is not enough: selecting a
symlink to the current file still hits E37.

Summary by CodeRabbit

  • Bug Fixes
    • Selecting the current file with the edit action no longer reloads it.
    • File selection still opens in a split when the current window is fixed to its buffer.

Selecting the file that is already open in the current window ran
`:edit <path>`, which reloads the buffer from disk and fails with E37 when it
has unsaved changes. The error aborted the select callback, so the jump to a
`file:line` location never happened.

Skip `:edit` when the selected path resolves to the current buffer. Identity is
checked with bufadd(), which matches names the same way `:edit` does, so a
symlink to the current file is handled too.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f0ec963-9b0f-403d-946a-9c78de601849
📥 Commits

Reviewing files that changed from the base of the PR and between c188e7a and 1b2f075.

📒 Files selected for processing (1)
  • lua/fff/picker_ui/picker_ui.lua

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The picker’s edit action skips :edit when the selected path resolves to the current buffer. It retains the :split path when the current window has winfixbuf enabled.

Changes

Edit action

Layer / File(s) Summary
Current buffer check
lua/fff/picker_ui/picker_ui.lua
The edit action compares the buffer returned by bufadd(edit_path) with the current buffer. It runs :edit only when they differ and retains the :split path when winfixbuf is enabled.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: dmtrkovalenko

Merge Risk: ⚪ Minimal · up to 1b2f0

The picker preserves unsaved edits when the current file is selected again, including through a symlink alias. No actionable merge-blocking issue remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary fix: avoiding :edit on the current buffer to prevent E37 for modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dmtrKovalenko
dmtrKovalenko merged commit 794080f into dmtrKovalenko:main Oct 9, 2026
54 checks passed
@TNVC
TNVC deleted the fix/select-modified-current-buffer branch October 9, 2026 05:52
wpenistone pushed a commit to wpenistone/fffork that referenced this pull request Oct 13, 2026
…enko#907)

Selecting the file that is already open in the current window ran
`:edit <path>`, which reloads the buffer from disk and fails with E37 when it
has unsaved changes. The error aborted the select callback, so the jump to a
`file:line` location never happened.

Skip `:edit` when the selected path resolves to the current buffer. Identity is
checked with bufadd(), which matches names the same way `:edit` does, so a
symlink to the current file is handled too.
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.

2 participants