I'm still not sure I have the right 'theory' for this ball of mud.
L2R5WULWN44SCNUPP7R7I2AQCWQR6D3E2YZA35RBXZAR2LGC6LQQC
V4ZZDSYWKYREINXLP6NZ4O2JK6J6FEWIKA7E22FUO7TTJAXGKPOAC
5U5N3KZY7HZB4YV3UBFO7ZZJLIJUWLKYDSHZXJVWOB36T2M2HWGQC
UTKVVOY74ICTNL3YNFPPJOJK565BTG673BURU53URE7A24FHQVLQC
HQCEHEHJXKH7ZU4OGLHT5QCY75YKPBH6WVSLXJKSQI4V7PKUBVEQC
CZY3IDERLI6MTKKKMX6QLLERSPM2ZJ57NGQRKILJBM7S5PYPQ3XAC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
DYPXQWZ6RE4WQWYRMWLI4JVNTEH637CDVLG5RQ3D5KNPZ73C7UHAC
SKMUH5RWOBUHRAQ3TUEIH5EEHN3YOC35GJOJY7GPY7VY6QXLSODAC
VHWC2IGQD72ZZUIONIAEP45KPMPX2N6DXN6NU2QGBIWDUHP7INAAC
J3ER7DFO2TXYUMJAXZUFEHQNLFDNIXSYDTE7HEFGQ2RYB3A6RFPAC
MO4B3HJQL7KU2CETG74EV367YPREQN3Z5DJP2MNHITVW2KQRXRCAC
NGCYNQEAAROJCQKUJDLGZALNYAU5MTNTGW4XBG6MGAHSHFG6PPMAC
UMRNXBPB2VOBLHHWVNFQDF5YYQ3IWYHSGFUTXURKYW4MZLPB33BQC
S4U35JJQWC3CBNKHAEZ2DYEGUT5L3UYVAO6PJ5R7HSTD53KWVAXQC
OANSMSQYJARQ5ZCJ62CO3TL4EF7ZDJE6RUGGROWDTMTZRHBUGMGQC
BJ5X5O4ACBBJ56LRBBSTCW6IBQP4HAEOOOPNH3SKTA4F66YTOIDAC
5XQ4Y7NU63X2WW4ZR4P46LX5GEOTE7JH3AUMTDQW5VZ53GELNP2QC
pane.screen_top1, y_offset = schema1_of_y(pane, Display_settings.y - Margin_top)
--? print(('%d,%d: => %d,%d'):format(column_index, pane_index, pane.screen_top1.line, pane.screen_top1.pos))
pane.screen_top1, y_offset = schema1_of_y(pane, Display_settings.y - sy)
--? print(('%d,%d: => %d,%d with offset %d'):format(column_index, pane_index, pane.screen_top1.line, pane.screen_top1.pos, y_offset))
--? print(('%d,%d; %d,%d: adjusting pane top %d; screen_top is at %d,%d (max %d)'):format(column_index,pane_index, sx,sy, pane.top, pane.screen_top1.line, pane.screen_top1.pos, #pane.lines))
--? print(('%d,%d; %d,%d: adjusting pane top %d; screen_top is at %d,%d (max %d); y_offset is %d'):format(column_index,pane_index, sx,sy, pane.top, pane.screen_top1.line, pane.screen_top1.pos, #pane.lines, y_offset))
Display_settings.y = up_edge_sy(Cursor_pane.col, Cursor_pane.row) + y_of_schema1(pane, pane.screen_top1)
Display_settings.y = Display_settings.y - Margin_top -- don't hide under column headers
--? print(('display settings.y is now %d'):format(Display_settings.y))
Surface.cursor_on_screen_check = true -- cursor was on screen before keystroke, so it should remain on screen after
--? print('screen top after:', pane.screen_top1.line, pane.screen_top1.pos)
if not eq(old_top, pane.screen_top1) then -- and not eq(pane.screen_top1, {line=1, pos=1}) then
Display_settings.y = up_edge_sy(Cursor_pane.col, Cursor_pane.row) + y_of_schema1(pane, pane.screen_top1)
Display_settings.y = Display_settings.y - Margin_top -- don't hide under column headers
--? print(('display settings.y is now %d'):format(Display_settings.y))
Surface.cursor_on_screen_check = true -- cursor was on screen before keystroke, so it should remain on screen after
end