Now I better understand why that code exists.
KTABGWEVR6D5KLOCVAOUDNQMRB3BUFU4GTR3OIAWLJSIPIG6G46QC
-- updating screen_top1 can be jarring if the pane had room above it on screen
-- prefer to pan the surface when possible
local cursor_sy = up_edge_sy(Cursor_pane.col, Cursor_pane.row) + y_of_schema1(pane, pane.cursor1)
if eq(old_top, {line=1, pos=1}) and pane.top > Header_height and cursor_sy - Display_settings.y > App.screen.height - Header_height - Line_height then
pane.screen_top1 = old_top
bring_cursor_of_cursor_pane_in_view('down')
Surface.cursor_on_screen_check = true -- cursor was on screen before keystroke, so it should remain on screen after
return
end