Skip to content

Commit d28d090

Browse files
committed
feat(api): add opts parameter to add_visual_selection
Add optional opts.open_input (default: true) to control whether the input window opens after adding selection.
1 parent 05747a2 commit d28d090

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,16 @@ The plugin provides the following actions that can be triggered via keymaps, com
615615
| Toggle tools output (diffs, cmd output, etc.) | `<leader>ott` | `:Opencode toggle_tool_output` | `require('opencode.api').toggle_tool_output()` |
616616
| Toggle reasoning output (thinking steps) | `<leader>otr` | `:Opencode toggle_reasoning_output` | `require('opencode.api').toggle_reasoning_output()` |
617617
| Open a quick chat input with selection/current line context | `<leader>o/` | `:Opencode quick_chat` | `require('opencode.api').quick_chat()` |
618-
| Add visual selection to context | `<leader>oy` | `:Opencode add_visual_selection` | `require('opencode.api').add_visual_selection()` |
618+
| Add visual selection to context | `<leader>oy` | `:Opencode add_visual_selection` | `require('opencode.api').add_visual_selection(opts?)` |
619+
620+
**add_visual_selection opts:**
621+
622+
- `open_input` (boolean, default: `true`): Whether to open the input window after adding the selection. Set to `false` to add selection silently without changing focus.
623+
624+
Example keymap for silent add:
625+
```lua
626+
['<leader>oY'] = { 'add_visual_selection', { open_input = false }, mode = {'v'} }
627+
```
619628

620629
### Run opts
621630

lua/opencode/api.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,16 +1013,15 @@ M.review = Promise.async(function(args)
10131013
end)
10141014
end)
10151015

1016-
--- Add the current visual selection to the context without opening/focusing the panel.
1017-
--- Can be called from any buffer. Selections accumulate across files.
10181016
M.add_visual_selection = Promise.async(
1019-
---@param _ any Unused
1017+
---@param opts? {open_input?: boolean}
10201018
---@param range OpencodeSelectionRange
1021-
function(_, range)
1019+
function(opts, range)
1020+
opts = vim.tbl_extend('force', { open_input = true }, opts or {})
10221021
local context = require('opencode.context')
10231022
local added = context.add_visual_selection(range)
10241023

1025-
if added then
1024+
if added and opts.open_input then
10261025
M.open_input():await()
10271026
end
10281027
end

0 commit comments

Comments
 (0)