Skip to content

Commit

Permalink
refactor: preview window uses Yes/No instead of Ok/Cancel (#344)
Browse files Browse the repository at this point in the history
NOTE: the `o` and `c` keymaps will continue to work. This only changes
the text labels and adds new keymaps for `y` and `n`.

* chore: replace ok and cancel with yes and no in confirmation window

* chore: allow to configure labels and keymaps for confirmation window

* chore: remove potential duplicate cancel keymaps

* chore: update README and oil.txt

* chore: nowait on confirm mappings and cleanup

* refactor: fully transition to yes/no

* move the config from under the `confirmation` key to the `preview`
  key, which is already in use for customizing the window
* fully default to yes/no, keeping the o/c keybindings for backwards
  compatibility
* make all of the `cancel` keybindings explicit (q, C-c, esc)
* more dynamically choose highlighting of the action labels

* refactor: just use yes/no and abandon configuration

---------

Co-authored-by: Steven Arcangeli <stevearc@stevearc.com>
  • Loading branch information
omelette-watin and stevearc authored May 6, 2024
1 parent 752563c commit 010b44a
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lua/oil/mutator/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ end
---@param bufnr integer
---@param lines string[]
local function render_lines(winid, bufnr, lines)
util.render_text(
bufnr,
lines,
{ v_align = "top", h_align = "left", winid = winid, actions = { "[O]k", "[C]ancel" } }
)
util.render_text(bufnr, lines, {
v_align = "top",
h_align = "left",
winid = winid,
actions = { "[Y]es", "[N]o" },
})
end

---@param actions oil.Action[]
Expand Down Expand Up @@ -165,17 +166,22 @@ M.show = vim.schedule_wrap(function(actions, should_confirm, cb)
end,
})
)
for _, cancel_key in ipairs({ "q", "C", "c", "<C-c>", "<Esc>" }) do

-- We used to use [C]ancel to cancel, so preserve the old keymap
local cancel_keys = { "n", "N", "c", "C", "q", "<C-c>", "<Esc>" }
for _, cancel_key in ipairs(cancel_keys) do
vim.keymap.set("n", cancel_key, function()
cancel()
end, { buffer = bufnr, nowait = true })
end
vim.keymap.set("n", "O", function()
confirm()
end, { buffer = bufnr })
vim.keymap.set("n", "o", function()
confirm()
end, { buffer = bufnr })

-- We used to use [O]k to confirm, so preserve the old keymap
local confirm_keys = { "y", "Y", "o", "O" }
for _, confirm_key in ipairs(confirm_keys) do
vim.keymap.set("n", confirm_key, function()
confirm()
end, { buffer = bufnr, nowait = true })
end
end)

return M

0 comments on commit 010b44a

Please # to comment.