@@ -76,7 +76,7 @@ local function capture_hidden_snapshot(windows)
7676 output_cursor = cursor_positions .output ,
7777 output_view = ok and type (view ) == ' table' and view or nil ,
7878 focused_window = focused ,
79- position = config . ui .position ,
79+ position = windows .position ,
8080 owner_tab = state .ui .are_windows_in_current_tab () and vim .api .nvim_get_current_tabpage () or nil ,
8181 }
8282end
@@ -115,7 +115,7 @@ local function close_or_restore_output_window(windows)
115115
116116 output_window .restore_winfix_options (windows .output_win )
117117
118- if config . ui .position == ' current' then
118+ if windows .position == ' current' then
119119 if state .current_code_buf and vim .api .nvim_buf_is_valid (state .current_code_buf ) then
120120 pcall (vim .api .nvim_win_set_buf , windows .output_win , state .current_code_buf )
121121 end
@@ -143,7 +143,7 @@ function M.hide_visible_windows(windows)
143143 local snapshot = capture_hidden_snapshot (windows )
144144
145145 -- Only save width ratio for split modes (not dialog/current mode)
146- if config . ui .position ~= ' current' then
146+ if windows .position ~= ' current' then
147147 local total_cols = vim .o .columns
148148 local current_width = vim .api .nvim_win_get_width (windows .output_win )
149149 state .ui .set_last_window_width_ratio (current_width / total_cols )
@@ -225,21 +225,22 @@ function M.restore_hidden_windows()
225225 footer_buf = footer .create_buf ()
226226 end
227227
228- local win_ids = M .create_split_windows (hidden .input_buf , hidden .output_buf )
229-
230- state .ui .consume_hidden_buffers ()
231-
232- state .ui .set_windows ({
228+ local windows = {
233229 input_buf = hidden .input_buf ,
234230 output_buf = hidden .output_buf ,
235231 footer_buf = footer_buf ,
236- input_win = win_ids .input_win ,
237- output_win = win_ids .output_win ,
238- footer_win = nil ,
239- output_was_at_bottom = hidden .output_was_at_bottom == true ,
240- saved_width_ratio = state .last_window_width_ratio ,
241- })
242- local windows = state .windows
232+ position = config .ui .position ,
233+ }
234+ local win_ids = M .create_split_windows (windows )
235+
236+ state .ui .consume_hidden_buffers ()
237+
238+ windows .input_win = win_ids .input_win
239+ windows .output_win = win_ids .output_win
240+ windows .footer_win = nil
241+ windows .output_was_at_bottom = hidden .output_was_at_bottom == true
242+ windows .saved_width_ratio = state .last_window_width_ratio
243+ state .ui .set_windows (windows )
243244
244245 state .ui .set_cursor_position (' input' , hidden .input_cursor )
245246 state .ui .set_cursor_position (' output' , hidden .output_cursor )
@@ -318,48 +319,43 @@ local function open_split(direction, type)
318319 return vim .api .nvim_get_current_win ()
319320end
320321
321- --- @param input_buf integer
322- --- @param output_buf integer
322+ --- @param windows OpencodeWindowState
323323--- @return { input_win : integer , output_win : integer }
324- local function open_float (input_buf , output_buf )
325- local output_config , input_config =
326- float_layout .window_configs ({ input_buf = input_buf , output_buf = output_buf }, true )
327- local output_win = float_layout .open_win (output_buf , true , output_config )
328- local input_win = float_layout .open_win (input_buf , true , input_config )
324+ local function open_float (windows )
325+ local output_config , input_config = float_layout .window_configs (windows , true )
326+ local output_win = float_layout .open_win (windows .output_buf , true , output_config )
327+ local input_win = float_layout .open_win (windows .input_buf , true , input_config )
329328
330329 return { input_win = input_win , output_win = output_win }
331330end
332331
333- --- @param input_buf integer
334- --- @param output_buf integer
332+ --- @param windows OpencodeWindowState
335333--- @return { input_win : integer , output_win : integer }
336- function M .create_split_windows (input_buf , output_buf )
334+ function M .create_split_windows (windows )
337335 if input_window .mounted () or output_window .mounted () then
338336 M .close_windows (state .windows , false )
339337 end
340- local ui_conf = config .ui
341-
342- if ui_conf .position == ' float' then
343- return open_float (input_buf , output_buf )
338+ if windows .position == ' float' then
339+ return open_float (windows )
344340 end
345341
346342 local main_win
347- if ui_conf .position == ' current' then
343+ if windows .position == ' current' then
348344 main_win = vim .api .nvim_get_current_win ()
349345 else
350- main_win = open_split (ui_conf .position , ' vertical' )
346+ main_win = open_split (windows .position , ' vertical' )
351347 end
352348 vim .api .nvim_set_current_win (main_win )
353349
354- local input_win = open_split (ui_conf .input_position , ' horizontal' )
350+ local input_win = open_split (config . ui .input_position , ' horizontal' )
355351 local output_win = main_win
356352
357- if ui_conf .position == ' current' then
353+ if windows .position == ' current' then
358354 pcall (vim .api .nvim_set_option_value , ' winfixbuf' , false , { win = output_win })
359355 end
360356
361- vim .api .nvim_win_set_buf (input_win , input_buf )
362- vim .api .nvim_win_set_buf (output_win , output_buf )
357+ vim .api .nvim_win_set_buf (input_win , windows . input_buf )
358+ vim .api .nvim_win_set_buf (output_win , windows . output_buf )
363359 return { input_win = input_win , output_win = output_win }
364360end
365361
@@ -383,16 +379,16 @@ function M.create_windows()
383379 end
384380
385381 -- Create new windows from scratch
386- local buffers = M .setup_buffers ()
387- local windows = buffers
388- local win_ids = M .create_split_windows (buffers . input_buf , buffers . output_buf )
382+ local windows = M .setup_buffers ()
383+ windows . position = config . ui . position
384+ local win_ids = M .create_split_windows (windows )
389385
390386 windows .input_win = win_ids .input_win
391387 windows .output_win = win_ids .output_win
392388
393389 local filetype = config .ui .output .filetype or ' opencode_output'
394390 vim .api .nvim_win_call (windows .output_win , function ()
395- vim .api .nvim_set_option_value (' filetype' , filetype , { buf = buffers .output_buf })
391+ vim .api .nvim_set_option_value (' filetype' , filetype , { buf = windows .output_buf })
396392 end )
397393
398394 windows .saved_width_ratio = state .last_window_width_ratio
0 commit comments