@@ -372,7 +372,7 @@ describe('renderer.scroll_to_bottom', function()
372372 local ctx = require (' opencode.ui.renderer.ctx' )
373373 local output_window = require (' opencode.ui.output_window' )
374374 local stub = require (' luassert.stub' )
375- local buf , win
375+ local buf , win , input_buf , input_win
376376
377377 before_each (function ()
378378 config .setup ({})
@@ -396,6 +396,8 @@ describe('renderer.scroll_to_bottom', function()
396396 end )
397397
398398 after_each (function ()
399+ pcall (vim .api .nvim_win_close , input_win , true )
400+ pcall (vim .api .nvim_buf_delete , input_buf , { force = true })
399401 pcall (vim .api .nvim_win_close , win , true )
400402 pcall (vim .api .nvim_buf_delete , buf , { force = true })
401403 state .ui .set_windows (nil )
@@ -529,6 +531,43 @@ describe('renderer.scroll_to_bottom', function()
529531 assert .stub (cmd_stub ).was_called_with (' normal! zb' )
530532 cmd_stub :revert ()
531533 end )
534+
535+ it (' does not leave the focused input window while following output at bottom' , function ()
536+ input_buf = vim .api .nvim_create_buf (false , true )
537+ vim .api .nvim_buf_set_lines (input_buf , 0 , - 1 , false , { ' 中文输入' })
538+ input_win = vim .api .nvim_open_win (input_buf , true , {
539+ relative = ' editor' ,
540+ width = 40 ,
541+ height = 3 ,
542+ row = 12 ,
543+ col = 0 ,
544+ })
545+ state .ui .set_windows ({ output_win = win , output_buf = buf , input_win = input_win , input_buf = input_buf })
546+ vim .api .nvim_set_current_win (input_win )
547+
548+ local winleave_count = 0
549+ local group = vim .api .nvim_create_augroup (' OpencodeScrollImeRegression' , { clear = true })
550+ vim .api .nvim_create_autocmd (' WinLeave' , {
551+ group = group ,
552+ buffer = input_buf ,
553+ callback = function ()
554+ winleave_count = winleave_count + 1
555+ end ,
556+ })
557+
558+ vim .api .nvim_win_set_height (win , 5 )
559+ vim .api .nvim_win_set_cursor (win , { 1 , 0 })
560+ config .values .ui .output .always_scroll_to_bottom = true
561+
562+ renderer .scroll_to_bottom ()
563+
564+ assert .equals (input_win , vim .api .nvim_get_current_win ())
565+ assert .equals (0 , winleave_count )
566+ assert .equals (50 , vim .api .nvim_win_get_cursor (win )[1 ])
567+
568+ config .values .ui .output .always_scroll_to_bottom = false
569+ pcall (vim .api .nvim_del_augroup_by_id , group )
570+ end )
532571end )
533572
534573describe (' ui.focus_input' , function ()
0 commit comments