Skip to content

Commit

Permalink
feat: better merging of action desc when overriding keymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Dec 3, 2024
1 parent 3c2de37 commit f2b3249
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
26 changes: 12 additions & 14 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
--stylua: ignore

local default_config = {
-- Oil will take over directory buffers (e.g. `vim .` or `:e src/`)
-- Set to false if you want some other plugin (e.g. netrw) to open when you edit directories.
Expand Down Expand Up @@ -60,22 +58,22 @@ local default_config = {
-- Set to `false` to remove a keymap
-- See :help oil-actions for a list of all available actions
keymaps = {
["g?"] = "actions.show_help",
["g?"] = { "actions.show_help", mode = "n" },
["<CR>"] = "actions.select",
["<C-s>"] = { "actions.select", opts = { vertical = true }, desc = "Open the entry in a vertical split" },
["<C-h>"] = { "actions.select", opts = { horizontal = true }, desc = "Open the entry in a horizontal split" },
["<C-t>"] = { "actions.select", opts = { tab = true }, desc = "Open the entry in new tab" },
["<C-s>"] = { "actions.select", opts = { vertical = true } },
["<C-h>"] = { "actions.select", opts = { horizontal = true } },
["<C-t>"] = { "actions.select", opts = { tab = true } },
["<C-p>"] = "actions.preview",
["<C-c>"] = "actions.close",
["<C-c>"] = { "actions.close", mode = "n" },
["<C-l>"] = "actions.refresh",
["-"] = "actions.parent",
["_"] = "actions.open_cwd",
["`"] = "actions.cd",
["~"] = { "actions.cd", opts = { scope = "tab" }, desc = ":tcd to the current oil directory", mode = "n" },
["gs"] = "actions.change_sort",
["-"] = { "actions.parent", mode = "n" },
["_"] = { "actions.open_cwd", mode = "n" },
["`"] = { "actions.cd", mode = "n" },
["~"] = { "actions.cd", opts = { scope = "tab" }, mode = "n" },
["gs"] = { "actions.change_sort", mode = "n" },
["gx"] = "actions.open_external",
["g."] = "actions.toggle_hidden",
["g\\"] = "actions.toggle_trash",
["g."] = { "actions.toggle_hidden", mode = "n" },
["g\\"] = { "actions.toggle_trash", mode = "n" },
},
-- Set to false to disable all of the above keymaps
use_default_keymaps = true,
Expand Down
13 changes: 12 additions & 1 deletion lua/oil/keymap_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ local function resolve(rhs)
elseif type(rhs) == "table" then
local opts = vim.deepcopy(rhs)
-- We support passing in a `callback` key, or using the 1 index as the rhs of the keymap
local callback = resolve(opts.callback or opts[1])
local callback, parent_opts = resolve(opts.callback or opts[1])

-- Fall back to the parent desc, adding the opts as a string if it exists
if parent_opts.desc and not opts.desc then
if opts.opts then
opts.desc =
string.format("%s %s", parent_opts.desc, vim.inspect(opts.opts):gsub("%s+", " "))
else
opts.desc = parent_opts.desc
end
end

local mode = opts.mode
if type(rhs.callback) == "string" then
local action_opts, action_mode
Expand Down

0 comments on commit f2b3249

Please sign in to comment.