Skip to content

Commit f2b3249

Browse files
committed
feat: better merging of action desc when overriding keymaps
1 parent 3c2de37 commit f2b3249

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

lua/oil/config.lua

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
--stylua: ignore
2-
31
local default_config = {
42
-- Oil will take over directory buffers (e.g. `vim .` or `:e src/`)
53
-- Set to false if you want some other plugin (e.g. netrw) to open when you edit directories.
@@ -60,22 +58,22 @@ local default_config = {
6058
-- Set to `false` to remove a keymap
6159
-- See :help oil-actions for a list of all available actions
6260
keymaps = {
63-
["g?"] = "actions.show_help",
61+
["g?"] = { "actions.show_help", mode = "n" },
6462
["<CR>"] = "actions.select",
65-
["<C-s>"] = { "actions.select", opts = { vertical = true }, desc = "Open the entry in a vertical split" },
66-
["<C-h>"] = { "actions.select", opts = { horizontal = true }, desc = "Open the entry in a horizontal split" },
67-
["<C-t>"] = { "actions.select", opts = { tab = true }, desc = "Open the entry in new tab" },
63+
["<C-s>"] = { "actions.select", opts = { vertical = true } },
64+
["<C-h>"] = { "actions.select", opts = { horizontal = true } },
65+
["<C-t>"] = { "actions.select", opts = { tab = true } },
6866
["<C-p>"] = "actions.preview",
69-
["<C-c>"] = "actions.close",
67+
["<C-c>"] = { "actions.close", mode = "n" },
7068
["<C-l>"] = "actions.refresh",
71-
["-"] = "actions.parent",
72-
["_"] = "actions.open_cwd",
73-
["`"] = "actions.cd",
74-
["~"] = { "actions.cd", opts = { scope = "tab" }, desc = ":tcd to the current oil directory", mode = "n" },
75-
["gs"] = "actions.change_sort",
69+
["-"] = { "actions.parent", mode = "n" },
70+
["_"] = { "actions.open_cwd", mode = "n" },
71+
["`"] = { "actions.cd", mode = "n" },
72+
["~"] = { "actions.cd", opts = { scope = "tab" }, mode = "n" },
73+
["gs"] = { "actions.change_sort", mode = "n" },
7674
["gx"] = "actions.open_external",
77-
["g."] = "actions.toggle_hidden",
78-
["g\\"] = "actions.toggle_trash",
75+
["g."] = { "actions.toggle_hidden", mode = "n" },
76+
["g\\"] = { "actions.toggle_trash", mode = "n" },
7977
},
8078
-- Set to false to disable all of the above keymaps
8179
use_default_keymaps = true,

lua/oil/keymap_util.lua

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,18 @@ local function resolve(rhs)
1919
elseif type(rhs) == "table" then
2020
local opts = vim.deepcopy(rhs)
2121
-- We support passing in a `callback` key, or using the 1 index as the rhs of the keymap
22-
local callback = resolve(opts.callback or opts[1])
22+
local callback, parent_opts = resolve(opts.callback or opts[1])
23+
24+
-- Fall back to the parent desc, adding the opts as a string if it exists
25+
if parent_opts.desc and not opts.desc then
26+
if opts.opts then
27+
opts.desc =
28+
string.format("%s %s", parent_opts.desc, vim.inspect(opts.opts):gsub("%s+", " "))
29+
else
30+
opts.desc = parent_opts.desc
31+
end
32+
end
33+
2334
local mode = opts.mode
2435
if type(rhs.callback) == "string" then
2536
local action_opts, action_mode

0 commit comments

Comments
 (0)