Skip to content

Commit cfa8c0a

Browse files
committed
fix: defer input window keymaps to blink.cmp when visible
When blink.cmp completion menu is open, input window keymaps now defer to blink instead of taking precedence. Fixes #183.
1 parent a8e53d5 commit cfa8c0a

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lua/opencode/keymap.lua

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
local M = {}
22

3-
-- Helper function to process keymap entries
3+
local function is_blink_visible()
4+
local ok, blink = pcall(require, 'blink.cmp')
5+
return ok and blink.is_visible()
6+
end
7+
8+
local function wrap_with_blink_check(key_binding, callback)
9+
return function()
10+
if is_blink_visible() then
11+
return vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key_binding, true, false, true), 'n', false)
12+
end
13+
return callback()
14+
end
15+
end
16+
417
---@param keymap_config table The keymap configuration table
518
---@param default_modes table Default modes for these keymaps
619
---@param base_opts table Base options to use for all keymaps
7-
local function process_keymap_entry(keymap_config, default_modes, base_opts)
20+
---@param defer_to_blink boolean? Whether to defer to blink.cmp when visible
21+
local function process_keymap_entry(keymap_config, default_modes, base_opts, defer_to_blink)
822
local api = require('opencode.api')
923
local cmds = api.commands
1024

@@ -19,6 +33,9 @@ local function process_keymap_entry(keymap_config, default_modes, base_opts)
1933
opts.desc = config_entry.desc or cmds[func_name] and cmds[func_name].desc
2034

2135
if callback then
36+
if defer_to_blink then
37+
callback = wrap_with_blink_check(key_binding, callback)
38+
end
2239
vim.keymap.set(modes, key_binding, callback, opts)
2340
else
2441
vim.notify(string.format('No action found for keymap: %s -> %s', key_binding, func_name), vim.log.levels.WARN)
@@ -34,15 +51,15 @@ function M.setup(keymap)
3451
process_keymap_entry(keymap.editor or {}, { 'n', 'v' }, { silent = false })
3552
end
3653

37-
-- Setup window-specific keymaps (shared helper for input/output windows)
3854
---@param keymap_config table Window keymap configuration
3955
---@param buf_id integer Buffer ID to set keymaps for
40-
function M.setup_window_keymaps(keymap_config, buf_id)
56+
---@param defer_to_blink boolean? Whether to defer to blink.cmp when visible (default: false)
57+
function M.setup_window_keymaps(keymap_config, buf_id, defer_to_blink)
4158
if not vim.api.nvim_buf_is_valid(buf_id) then
4259
return
4360
end
4461

45-
process_keymap_entry(keymap_config or {}, { 'n' }, { silent = true, buffer = buf_id })
62+
process_keymap_entry(keymap_config or {}, { 'n' }, { silent = true, buffer = buf_id }, defer_to_blink)
4663
end
4764

4865
return M

lua/opencode/ui/input_window.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ end
351351

352352
function M.setup_keymaps(windows)
353353
local keymap = require('opencode.keymap')
354-
keymap.setup_window_keymaps(config.keymap.input_window, windows.input_buf)
354+
keymap.setup_window_keymaps(config.keymap.input_window, windows.input_buf, true)
355355
end
356356

357357
function M.setup_autocmds(windows, group)

0 commit comments

Comments
 (0)