11local 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 })
3552end
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 )
4663end
4764
4865return M
0 commit comments