File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,13 +55,29 @@ function M.paste_image()
5555 core .paste_image_from_clipboard ()
5656end
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+
5870M .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 ()
You can’t perform that action at this time.
0 commit comments