Skip to content

Commit 8d513e4

Browse files
committed
Add descriptions to hunk keymaps
Closes #26
1 parent 1e0a4d7 commit 8d513e4

3 files changed

Lines changed: 35 additions & 16 deletions

File tree

lua/hunk/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ local function set_global_bindings(layout, buf)
113113
ui.help.create()
114114
end, {
115115
buffer = buf,
116+
desc = "Open hunk.nvim help",
116117
})
117118

118119
for _, chord in ipairs(utils.into_table(config.keys.global.accept)) do
@@ -121,6 +122,7 @@ local function set_global_bindings(layout, buf)
121122
vim.cmd("qa")
122123
end, {
123124
buffer = buf,
125+
desc = "Accept the current selection",
124126
})
125127
end
126128

@@ -129,6 +131,7 @@ local function set_global_bindings(layout, buf)
129131
vim.cmd("cq")
130132
end, {
131133
buffer = buf,
134+
desc = "Cancel selection and quit",
132135
})
133136
end
134137

@@ -137,6 +140,7 @@ local function set_global_bindings(layout, buf)
137140
vim.api.nvim_set_current_win(layout.tree)
138141
end, {
139142
buffer = buf,
143+
desc = "Focus hunk.nvim file-tree",
140144
})
141145
end
142146
end

lua/hunk/ui/file.lua

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,13 @@ function M.create(window, params)
9696
change = params.change,
9797
}
9898

99-
local map_opts = {
100-
buffer = buf,
101-
nowait = true,
102-
}
99+
local function map_opts(desc)
100+
return {
101+
buffer = buf,
102+
nowait = true,
103+
desc = desc,
104+
}
105+
end
103106

104107
for _, chord in ipairs(utils.into_table(config.keys.diff.toggle_line)) do
105108
vim.keymap.set("n", chord, function()
@@ -109,7 +112,7 @@ function M.create(window, params)
109112
lines = { line },
110113
file = File,
111114
})
112-
end, map_opts)
115+
end, map_opts("Toggle line under cursor"))
113116

114117
vim.keymap.set("v", chord, function()
115118
local lines = get_selected_lines()
@@ -120,7 +123,7 @@ function M.create(window, params)
120123
file = File,
121124
})
122125
end)
123-
end, map_opts)
126+
end, map_opts("Toggle selected line(s)"))
124127
end
125128

126129
for _, chord in ipairs(utils.into_table(config.keys.diff.toggle_line_pair)) do
@@ -132,7 +135,7 @@ function M.create(window, params)
132135
file = File,
133136
both_sides = true,
134137
})
135-
end, map_opts)
138+
end, map_opts("Toggle line pair under cursor (left + right)"))
136139

137140
vim.keymap.set("v", chord, function()
138141
local lines = get_selected_lines()
@@ -144,7 +147,7 @@ function M.create(window, params)
144147
both_sides = true,
145148
})
146149
end)
147-
end, map_opts)
150+
end, map_opts("Toggle selected line pair(s) (left + right)"))
148151
end
149152

150153
for _, chord in ipairs(utils.into_table(config.keys.diff.toggle_hunk)) do
@@ -154,7 +157,7 @@ function M.create(window, params)
154157
line = vim.api.nvim_win_get_cursor(window)[1],
155158
file = File,
156159
})
157-
end, map_opts)
160+
end, map_opts("Toggle entire hunk under cursor"))
158161
end
159162

160163
for _, chord in ipairs(utils.into_table(config.keys.diff.prev_hunk)) do
@@ -168,7 +171,7 @@ function M.create(window, params)
168171
break
169172
end
170173
end
171-
end, map_opts)
174+
end, map_opts("Go to prev hunk"))
172175
end
173176

174177
for _, chord in ipairs(utils.into_table(config.keys.diff.next_hunk)) do
@@ -181,7 +184,7 @@ function M.create(window, params)
181184
break
182185
end
183186
end
184-
end, map_opts)
187+
end, map_opts("Go to next hunk"))
185188
end
186189

187190
for _, chord in ipairs(utils.into_table(config.keys.diff.toggle_focus)) do
@@ -190,7 +193,7 @@ function M.create(window, params)
190193
type = "toggle-focus",
191194
side = params.side,
192195
})
193-
end, map_opts)
196+
end, map_opts("Toggle focused window between left/right"))
194197
end
195198

196199
config.hooks.on_diff_mount({ buf = buf, win = window })

lua/hunk/ui/tree.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ function M.create(opts)
225225
if node and node.type == "file" then
226226
opts.on_open(node.change, callback_opts)
227227
end
228-
end, { buffer = buf })
228+
end, {
229+
buffer = buf,
230+
desc = "Open file under cursor",
231+
})
229232
end
230233

231234
for _, chord in ipairs(utils.into_table(config.keys.tree.expand_node)) do
@@ -241,7 +244,10 @@ function M.create(opts)
241244
node:expand()
242245
Component.render()
243246
end
244-
end, { buffer = buf })
247+
end, {
248+
buffer = buf,
249+
desc = "Expand or preview node under cursor",
250+
})
245251
end
246252

247253
for _, chord in ipairs(utils.into_table(config.keys.tree.collapse_node)) do
@@ -251,7 +257,10 @@ function M.create(opts)
251257
node:collapse()
252258
Component.render()
253259
end
254-
end, { buffer = buf })
260+
end, {
261+
buffer = buf,
262+
desc = "Collapse node under cursor",
263+
})
255264
end
256265

257266
for _, chord in ipairs(utils.into_table(config.keys.tree.toggle_file)) do
@@ -267,7 +276,10 @@ function M.create(opts)
267276
for _, change in ipairs(changeset) do
268277
opts.on_toggle(change, state ~= "all", callback_opts)
269278
end
270-
end, { buffer = buf })
279+
end, {
280+
buffer = buf,
281+
desc = "Toggle all hunks in file under cursor",
282+
})
271283
end
272284

273285
config.hooks.on_tree_mount({ buf = buf, tree = tree, opts = opts })

0 commit comments

Comments
 (0)