Skip to content

Commit e2199b2

Browse files
author
Raphaël CHARTIER
committed
feat(buffer): add auto_accept option for hotkey actions. Fixes #69
1 parent 803208f commit e2199b2

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lua/tiny-code-action/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ M.picker_config = {
3535
hotkeys = false,
3636
hotkeys_mode = "text_diff_based",
3737
auto_preview = false,
38+
auto_accept = false,
3839
position = "cursor",
3940
winborder = nil,
4041
conceallevel = 1,

lua/tiny-code-action/pickers/buffer_utils/window.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ local function setup_window_autocmds(
8080
end
8181
end
8282

83-
local function setup_hotkey_navigation(buf, config, line_to_hotkey)
83+
local function setup_hotkey_navigation(buf, config, line_to_hotkey, handle_selection_cb)
8484
if not (config.picker and config.picker.opts and config.picker.opts.hotkeys) then
8585
return
8686
end
@@ -91,10 +91,17 @@ local function setup_hotkey_navigation(buf, config, line_to_hotkey)
9191
end
9292

9393
local keymap_opts = { buffer = buf, nowait = true }
94+
local auto_accept = config.picker and config.picker.opts and config.picker.opts.auto_accept
95+
or false
96+
9497
for hotkey, line in pairs(hotkey_to_line) do
9598
local function jumpto()
9699
vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { line, 0 })
100+
if auto_accept then
101+
handle_selection_cb()
102+
end
97103
end
104+
98105
vim.keymap.set("n", hotkey, jumpto, keymap_opts)
99106
if #hotkey == 1 then
100107
vim.keymap.set("n", hotkey:upper(), jumpto, keymap_opts)
@@ -127,6 +134,8 @@ function M.create_main_window(
127134
match_hl_kind
128135
)
129136
local keymaps = config.picker and config.picker.opts and config.picker.opts.keymaps or {}
137+
local auto_accept = config.picker and config.picker.opts and config.picker.opts.auto_accept
138+
or false
130139
local preview_key = keymaps.preview or "K"
131140
local close_key = keymaps.close or "q"
132141

@@ -225,7 +234,7 @@ function M.create_main_window(
225234
vim.keymap.set("n", preview_key, handle_preview, keymap_opts)
226235
vim.keymap.set("n", close_key, close_window, keymap_opts)
227236

228-
setup_hotkey_navigation(buf, config, line_to_hotkey)
237+
setup_hotkey_navigation(buf, config, line_to_hotkey, handle_selection)
229238
setup_window_autocmds(
230239
buf,
231240
win,

0 commit comments

Comments
 (0)