Skip to content

Commit fccd818

Browse files
committed
feat(ui): add toggle between tab pages
1 parent 574c536 commit fccd818

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

lua/opencode/api.lua

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,29 @@ function M.paste_image()
5555
core.paste_image_from_clipboard()
5656
end
5757

58+
--- Check if opencode windows are in the current tab page
59+
--- @return boolean
60+
local function are_windows_in_current_tab()
61+
if not state.windows or not state.windows.output_win then
62+
return false
63+
end
64+
65+
local current_tab = vim.api.nvim_get_current_tabpage()
66+
local ok, win_tab = pcall(vim.api.nvim_win_get_tabpage, state.windows.output_win)
67+
return ok and win_tab == current_tab
68+
end
69+
5870
M.toggle = Promise.async(function(new_session)
5971
-- When auto_hide input is enabled, always focus input; otherwise use last focused
6072
local focus = 'input' ---@cast focus 'input' | 'output'
6173
if not config.ui.input.auto_hide then
6274
focus = state.last_focused_opencode_window or 'input'
6375
end
64-
if state.windows == nil then
76+
77+
if state.windows == nil or not are_windows_in_current_tab() then
78+
if state.windows then
79+
M.close()
80+
end
6581
core.open({ new_session = new_session == true, focus = focus, start_insert = false }):await()
6682
else
6783
M.close()

0 commit comments

Comments
 (0)