@@ -185,3 +185,57 @@ describe('output_window.is_at_bottom', function()
185185 assert .is_true (output_window .is_at_bottom (win ))
186186 end )
187187end )
188+
189+ describe (' renderer.scroll_to_bottom' , function ()
190+ local renderer = require (' opencode.ui.renderer' )
191+ local output_window = require (' opencode.ui.output_window' )
192+ local buf , win
193+
194+ before_each (function ()
195+ config .setup ({})
196+ buf = vim .api .nvim_create_buf (false , true )
197+ local lines = {}
198+ for i = 1 , 50 do
199+ lines [i ] = ' line ' .. i
200+ end
201+ vim .api .nvim_buf_set_lines (buf , 0 , - 1 , false , lines )
202+
203+ win = vim .api .nvim_open_win (buf , true , {
204+ relative = ' editor' , width = 80 , height = 10 , row = 0 , col = 0 ,
205+ })
206+
207+ state .windows = { output_win = win , output_buf = buf }
208+ renderer ._prev_line_count = 50
209+ end )
210+
211+ after_each (function ()
212+ pcall (vim .api .nvim_win_close , win , true )
213+ pcall (vim .api .nvim_buf_delete , buf , { force = true })
214+ state .windows = nil
215+ renderer ._prev_line_count = 0
216+ output_window .viewport_at_bottom = nil
217+ end )
218+
219+ it (' does not force-scroll when user cursor is above previous bottom' , function ()
220+ vim .api .nvim_win_set_cursor (win , { 10 , 0 })
221+ output_window .viewport_at_bottom = true
222+
223+ vim .api .nvim_buf_set_lines (buf , - 1 , - 1 , false , { ' line 51' })
224+ renderer .scroll_to_bottom ()
225+
226+ local cursor = vim .api .nvim_win_get_cursor (win )
227+ assert .equals (10 , cursor [1 ])
228+ end )
229+
230+ it (' still scrolls when always_scroll_to_bottom is enabled' , function ()
231+ config .values .ui .output .always_scroll_to_bottom = true
232+ vim .api .nvim_win_set_cursor (win , { 10 , 0 })
233+
234+ vim .api .nvim_buf_set_lines (buf , - 1 , - 1 , false , { ' line 51' })
235+ renderer .scroll_to_bottom ()
236+
237+ local cursor = vim .api .nvim_win_get_cursor (win )
238+ assert .equals (51 , cursor [1 ])
239+ config .values .ui .output .always_scroll_to_bottom = false
240+ end )
241+ end )
0 commit comments