Skip to content

Commit 28d6379

Browse files
committed
fix: focusing input window in insert mode
The shortcut <C-i> is interpreted as <tab> by terminals I moved it to i. #72 focusing the input_window should restore to the previous position not the char before #64
1 parent 946af3a commit 28d6379

File tree

6 files changed

+11
-6
lines changed

6 files changed

+11
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ require('opencode').setup({
143143
[']]'] = { 'next_message' }, -- Navigate to next message in the conversation
144144
['[['] = { 'prev_message' }, -- Navigate to previous message in the conversation
145145
['<tab>'] = { 'toggle_pane', mode = { 'n', 'i' } }, -- Toggle between input and output panes
146-
['<C-i>'] = { 'focus_input' }, -- Focus on input window and enter insert mode at the end of the input from the output window
146+
['i'] = { 'focus_input', 'n' }, -- Focus on input window and enter insert mode at the end of the input from the output window
147147
['<leader>oS'] = { 'select_child_session' }, -- Select and load a child session
148148
['<leader>oD'] = { 'debug_message' }, -- Open raw message in new buffer for debugging
149149
['<leader>oO'] = { 'debug_output' }, -- Open raw output in new buffer for debugging

lua/opencode/api.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ end
1818

1919
function M.open_input()
2020
core.open({ new_session = false, focus = 'input' })
21-
vim.cmd('startinsert')
2221
end
2322

2423
function M.open_input_new_session()
2524
core.open({ new_session = true, focus = 'input' })
26-
vim.cmd('startinsert')
2725
end
2826

2927
function M.open_output()

lua/opencode/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ M.defaults = {
4242
[']]'] = { 'next_message' },
4343
['[['] = { 'prev_message' },
4444
['<tab>'] = { 'toggle_pane', mode = { 'n', 'i' } },
45-
['<C-i>'] = { 'focus_input' },
45+
['i'] = { 'focus_input' },
4646
['<leader>oS'] = { 'select_child_session' },
4747
['<leader>oD'] = { 'debug_message' },
4848
['<leader>oO'] = { 'debug_output' },

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 })
77+
ui.focus_input({ restore_position = are_windows_closed, start_insert = true })
7878
elseif opts.focus == 'output' then
7979
ui.focus_output({ restore_position = are_windows_closed })
8080
end

lua/opencode/ui/autocmds.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ function M.setup_autocmds(windows)
2929
if not require('opencode.ui.ui').is_opencode_focused() then
3030
require('opencode.context').load()
3131
require('opencode.state').last_code_win_before_opencode = vim.api.nvim_get_current_win()
32+
else
33+
local pos = vim.api.nvim_win_get_cursor(0)
34+
if windows.input_win and vim.api.nvim_get_current_win() == windows.input_win then
35+
require('opencode.state').last_input_window_position = pos
36+
elseif windows.output_win and vim.api.nvim_get_current_win() == windows.output_win then
37+
require('opencode.state').last_output_window_position = pos
38+
end
3239
end
3340
end,
3441
})

lua/opencode/ui/ui.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function M.focus_input(opts)
135135
pcall(vim.api.nvim_win_set_cursor, 0, state.last_input_window_position)
136136
end
137137
if opts.start_insert then
138-
vim.cmd('startinsert')
138+
vim.api.nvim_feedkeys('a', 'n', false)
139139
end
140140
end
141141

0 commit comments

Comments
 (0)