Skip to content

Commit 826341d

Browse files
committed
fix(toggle): toggle keymap was always triggering insert mode
This should fix #77
1 parent 803eb3e commit 826341d

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

lua/opencode/api.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ function M.swap_position()
1717
end
1818

1919
function M.open_input()
20-
core.open({ new_session = false, focus = 'input' })
20+
core.open({ new_session = false, focus = 'input', start_insert = true })
2121
end
2222

2323
function M.open_input_new_session()
24-
core.open({ new_session = true, focus = 'input' })
24+
core.open({ new_session = true, focus = 'input', start_insert = true })
2525
end
2626

2727
function M.open_output()
@@ -44,7 +44,7 @@ function M.toggle(new_session)
4444
if state.windows == nil then
4545
local focus = state.last_focused_opencode_window or 'input'
4646

47-
core.open({ new_session = new_session == true, focus = focus })
47+
core.open({ new_session = new_session == true, focus = focus, start_insert = false })
4848
else
4949
M.close()
5050
end

lua/opencode/core.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function M.open(opts)
7474
end
7575

7676
if opts.focus == 'input' then
77-
ui.focus_input({ restore_position = are_windows_closed, start_insert = true })
77+
ui.focus_input({ restore_position = are_windows_closed, start_insert = opts.start_insert == true })
7878
elseif opts.focus == 'output' then
7979
ui.focus_output({ restore_position = are_windows_closed })
8080
end

lua/opencode/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@
268268

269269
---@class OpenOpts
270270
---@field focus? 'input' | 'output'
271+
---@field start_insert? boolean
271272
---@field new_session? boolean
272273

273274
---@class SendMessageOpts

lua/opencode/ui/ui.lua

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,12 @@ function M.focus_input(opts)
125125
return
126126
end
127127

128-
if vim.api.nvim_get_current_win() == windows.input_win then
129-
if opts.start_insert then
130-
vim.cmd('startinsert!')
131-
end
132-
return
133-
end
134-
135128
vim.api.nvim_set_current_win(windows.input_win)
136129

137130
if opts.restore_position and state.last_input_window_position then
138131
pcall(vim.api.nvim_win_set_cursor, 0, state.last_input_window_position)
139132
end
140-
if opts.start_insert then
133+
if vim.api.nvim_get_current_win() == windows.input_win and opts.start_insert then
141134
vim.api.nvim_feedkeys('a', 'n', false)
142135
end
143136
end

0 commit comments

Comments
 (0)