@@ -474,7 +474,7 @@ describe('renderer.scroll_to_bottom', function()
474474 cmd_stub :revert ()
475475 end )
476476
477- it (' uses zb when the followed bottom line is below the viewport' , function ()
477+ it (' bottom-aligns when the followed bottom line is below the viewport' , function ()
478478 local lines = {}
479479 for i = 1 , 40 do
480480 lines [i ] = ' line ' .. i
@@ -483,26 +483,19 @@ describe('renderer.scroll_to_bottom', function()
483483 vim .api .nvim_win_set_height (win , 5 )
484484 vim .api .nvim_win_set_cursor (win , { 1 , 0 })
485485
486- local cmd_stub = stub (vim , ' cmd' ).invokes (function (cmd )
487- if cmd == ' normal! zb' then
488- vim .api .nvim_win_call (win , function ()
489- vim .fn .winrestview ({ topline = 36 })
490- end )
491- return
492- end
493- return vim .api .nvim_cmd (vim .api .nvim_parse_cmd (cmd , {}), {})
494- end )
486+ local cmd_stub = stub (vim , ' cmd' )
495487
496488 local scroll = require (' opencode.ui.renderer.scroll' )
497489 scroll .scroll_win_to_bottom (win , buf )
498490
499491 local cursor = vim .api .nvim_win_get_cursor (win )
500492 assert .equals (40 , cursor [1 ])
501- assert .stub (cmd_stub ).was_called_with (' normal! zb' )
493+ assert .equals (40 , output_window .get_visible_bottom_line (win ))
494+ assert .stub (cmd_stub ).was_not_called_with (' normal! zb' )
502495 cmd_stub :revert ()
503496 end )
504497
505- it (' uses zb when a wrapped bottom line grows past the last screen row' , function ()
498+ it (' keeps the visual end selected when a wrapped bottom line grows past the last screen row' , function ()
506499 local long_line = string.rep (' x' , 80 )
507500 local longer_line = string.rep (' x' , 180 )
508501
@@ -511,12 +504,7 @@ describe('renderer.scroll_to_bottom', function()
511504 vim .api .nvim_set_option_value (' wrap' , true , { win = win , scope = ' local' })
512505 vim .api .nvim_buf_set_lines (buf , 0 , - 1 , false , { long_line })
513506
514- local cmd_stub = stub (vim , ' cmd' ).invokes (function (cmd )
515- if cmd == ' normal! zb' then
516- return
517- end
518- return vim .api .nvim_cmd (vim .api .nvim_parse_cmd (cmd , {}), {})
519- end )
507+ local cmd_stub = stub (vim , ' cmd' )
520508
521509 local scroll = require (' opencode.ui.renderer.scroll' )
522510 scroll .scroll_win_to_bottom (win , buf )
@@ -528,7 +516,7 @@ describe('renderer.scroll_to_bottom', function()
528516 local cursor = vim .api .nvim_win_get_cursor (win )
529517 assert .equals (1 , cursor [1 ])
530518 assert .equals (# longer_line - 1 , cursor [2 ])
531- assert .stub (cmd_stub ).was_called_with (' normal! zb' )
519+ assert .stub (cmd_stub ).was_not_called_with (' normal! zb' )
532520 cmd_stub :revert ()
533521 end )
534522
@@ -545,21 +533,36 @@ describe('renderer.scroll_to_bottom', function()
545533 state .ui .set_windows ({ output_win = win , output_buf = buf , input_win = input_win , input_buf = input_buf })
546534 vim .api .nvim_set_current_win (input_win )
547535
548- local winleave_count = 0
549- local modechanged_count = 0
536+ local events = {
537+ BufEnter = 0 ,
538+ ModeChanged = 0 ,
539+ WinEnter = 0 ,
540+ WinLeave = 0 ,
541+ }
550542 local group = vim .api .nvim_create_augroup (' OpencodeScrollImeRegression' , { clear = true })
543+ vim .api .nvim_create_autocmd (' WinEnter' , {
544+ group = group ,
545+ callback = function ()
546+ events .WinEnter = events .WinEnter + 1
547+ end ,
548+ })
551549 vim .api .nvim_create_autocmd (' WinLeave' , {
552550 group = group ,
553- buffer = input_buf ,
554551 callback = function ()
555- winleave_count = winleave_count + 1
552+ events .WinLeave = events .WinLeave + 1
553+ end ,
554+ })
555+ vim .api .nvim_create_autocmd (' BufEnter' , {
556+ group = group ,
557+ callback = function ()
558+ events .BufEnter = events .BufEnter + 1
556559 end ,
557560 })
558561 vim .api .nvim_create_autocmd (' ModeChanged' , {
559562 group = group ,
560563 pattern = ' i:n' ,
561564 callback = function ()
562- modechanged_count = modechanged_count + 1
565+ events . ModeChanged = events . ModeChanged + 1
563566 end ,
564567 })
565568
@@ -578,10 +581,14 @@ describe('renderer.scroll_to_bottom', function()
578581 renderer .scroll_to_bottom ()
579582
580583 assert .equals (input_win , vim .api .nvim_get_current_win ())
581- assert .equals (0 , winleave_count )
582- assert .equals (0 , modechanged_count )
584+ assert .same ({
585+ BufEnter = 0 ,
586+ ModeChanged = 0 ,
587+ WinEnter = 0 ,
588+ WinLeave = 0 ,
589+ }, events )
583590 assert .equals (50 , vim .api .nvim_win_get_cursor (win )[1 ])
584- assert .stub (cmd_stub ).was_called_with (' normal! zb' )
591+ assert .stub (cmd_stub ).was_not_called_with (' normal! zb' )
585592
586593 cmd_stub :revert ()
587594 config .values .ui .output .always_scroll_to_bottom = false
0 commit comments