fix: escape on save prompt cancels select (#76)

Problem: when `prompt_save_on_select_new_entry` is enabled and the user
presses Escape on the "Save changes?" confirm dialog, `vim.fn.confirm`
returns 0, but the select continued as if the user had chosen "No".

Solution: add an explicit `choice == 0` branch that returns immediately,
aborting the select without saving or opening any files.
This commit is contained in:
Barrett Ruth 2026-03-06 16:28:57 -05:00 committed by GitHub
parent a74747e1f5
commit 7a46246062
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 12 deletions

View file

@ -37,17 +37,17 @@ Bugs fixed in this fork that remain open upstream.
## Open upstream PRs ## Open upstream PRs
| PR | Description | Status | | PR | Description | Status |
| ----------------------------------------------------- | ------------------------------------------- | ----------------------------------------------------------------------------------------------- | | ----------------------------------------------------- | ---------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [#488](https://github.com/stevearc/oil.nvim/pull/488) | Parent directory in a split | not actionable — empty PR | | [#488](https://github.com/stevearc/oil.nvim/pull/488) | Parent directory in a split | not actionable — empty PR |
| [#493](https://github.com/stevearc/oil.nvim/pull/493) | UNC paths on Windows | not actionable — superseded by [#686](https://github.com/stevearc/oil.nvim/pull/686) | | [#493](https://github.com/stevearc/oil.nvim/pull/493) | UNC paths on Windows | not actionable — superseded by [#686](https://github.com/stevearc/oil.nvim/pull/686) |
| [#591](https://github.com/stevearc/oil.nvim/pull/591) | release-please changelog | not applicable | | [#591](https://github.com/stevearc/oil.nvim/pull/591) | release-please changelog | not applicable |
| [#667](https://github.com/stevearc/oil.nvim/pull/667) | Virtual text columns + headers | deferred — WIP, conflicting | | [#667](https://github.com/stevearc/oil.nvim/pull/667) | Virtual text columns + headers | deferred — WIP, conflicting |
| [#686](https://github.com/stevearc/oil.nvim/pull/686) | Windows path conversion fix | not actionable — Windows-only | | [#686](https://github.com/stevearc/oil.nvim/pull/686) | Windows path conversion fix | not actionable — Windows-only |
| [#708](https://github.com/stevearc/oil.nvim/pull/708) | Move file into new dir by renaming | deferred — needs rewrite | | [#708](https://github.com/stevearc/oil.nvim/pull/708) | Move file into new dir by renaming | deferred — needs rewrite |
| [#721](https://github.com/stevearc/oil.nvim/pull/721) | `create_hook` to populate file contents | fixed — `CanolaFileCreated` autocmd — [#75](https://github.com/barrettruth/canola.nvim/pull/75) | | [#721](https://github.com/stevearc/oil.nvim/pull/721) | `create_hook` to populate file contents | deferred — fixing via autocmd event on file create |
| [#728](https://github.com/stevearc/oil.nvim/pull/728) | `open_split` for opening oil in a split | tracked — [#2](https://github.com/barrettruth/canola.nvim/issues/2) | | [#728](https://github.com/stevearc/oil.nvim/pull/728) | `open_split` for opening oil in a split | tracked — [#2](https://github.com/barrettruth/canola.nvim/issues/2) |
| [#735](https://github.com/stevearc/oil.nvim/pull/735) | gX opens external program with a selection. | not actionable — wrong abstraction layer | | [#735](https://github.com/stevearc/oil.nvim/pull/735) | gX opens external program with selection | not actionable — hardcoded Linux-only program list, no config surface, author-acknowledged incomplete |
## Upstream issues ## Upstream issues
@ -82,7 +82,7 @@ Bugs fixed in this fork that remain open upstream.
| [#359](https://github.com/stevearc/oil.nvim/issues/359) | open | Parse error on filenames differing by space (P1) | | [#359](https://github.com/stevearc/oil.nvim/issues/359) | open | Parse error on filenames differing by space (P1) |
| [#360](https://github.com/stevearc/oil.nvim/issues/360) | open | Pick window to open file into | | [#360](https://github.com/stevearc/oil.nvim/issues/360) | open | Pick window to open file into |
| [#362](https://github.com/stevearc/oil.nvim/issues/362) | open | "Could not find oil adapter for scheme" error | | [#362](https://github.com/stevearc/oil.nvim/issues/362) | open | "Could not find oil adapter for scheme" error |
| [#363](https://github.com/stevearc/oil.nvim/issues/363) | open | `prompt_save_on_select_new_entry` uses wrong prompt | | [#363](https://github.com/stevearc/oil.nvim/issues/363) | fixed | `prompt_save_on_select_new_entry` uses wrong prompt — escape now cancels select |
| [#371](https://github.com/stevearc/oil.nvim/issues/371) | open | Constrain cursor in insert mode | | [#371](https://github.com/stevearc/oil.nvim/issues/371) | open | Constrain cursor in insert mode |
| [#373](https://github.com/stevearc/oil.nvim/issues/373) | open | Dir from quickfix with bqf/trouble broken (P1) | | [#373](https://github.com/stevearc/oil.nvim/issues/373) | open | Dir from quickfix with bqf/trouble broken (P1) |
| [#375](https://github.com/stevearc/oil.nvim/issues/375) | open | Highlights for file types and permissions (P2) | | [#375](https://github.com/stevearc/oil.nvim/issues/375) | open | Highlights for file types and permissions (P2) |

View file

@ -716,6 +716,8 @@ M.select = function(opts, callback)
local ok, choice = pcall(vim.fn.confirm, 'Save changes?', 'Yes\nNo', 1) local ok, choice = pcall(vim.fn.confirm, 'Save changes?', 'Yes\nNo', 1)
if not ok then if not ok then
return finish() return finish()
elseif choice == 0 then
return
elseif choice == 1 then elseif choice == 1 then
M.save() M.save()
return finish() return finish()