So, things I've done so far to fix up y coordinate computations:
Let's see how this looks.
X4IMZTJHZDYTKABS2SHGQWP6PN7ESECHYQQKLLGZKBDE7Y4TYX4QC
Z575DEB7ULZXYH2BJCFXQMKPVXCSG72P46EHVBDD5PAOQTUDNZHQC
DHI6IJCNSTHGED67T6H5X6Y636C7PIDGIJD32HBEKLT5WIMRS5MAC
BULPIBEGL7TMK6CVIE7IS7WGAHGOSUJBGJSFQK542MOWGHP2ADQQC
HOSPP2ANSW654DYRTC6CQUQA2GUKV6T2FI7QBKXD2DZS3R32IMGAC
HALS7E5UGKCP3DFY456F7Z3Y6WNGIABOCV2SHT34D5ZAGNCPV5PQC
J3ER7DFO2TXYUMJAXZUFEHQNLFDNIXSYDTE7HEFGQ2RYB3A6RFPAC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
EWK46OTWI2QK7ZZGYOCWWBHXHBXZQWR2FDW6LRTTKCN4K3ZFE5JAC
YKRUNSPXQMYUZM2HC2BWRL3OLVF5X3Y3XASG7JCT4TW4VUHZD6ZAC
TBRTM3AARI73LHUKOGIT66J5T3UTXQPJFLVJW7ZEBPZCOXAOGIIQC
TKAKGUAQBDJWK6DPAQC4JJYCAJFVCWNJMKBJIRDH2M3BGEZNSENAC
7AKT7IKOP6VQW3CABAVXCEZTHYNAETVXGFIQWB2L6I7LM7T57HAAC
W5D22DQ5HRM3SGVEDY3E57Q6UPXGYLPQUJEVYMP2SU5KKG4J5K2AC
print(y_of_schema1(pane, pane.cursor1))
print('viewport starts at', Display_settings.y)
print('pane starts at', up_edge_sy(Cursor_pane.col, Cursor_pane.row))
--? local result = Padding_vertical
--? for i=1,Cursor_pane.row-1 do
--? print(i, result)
--? local pane = Surface[Cursor_pane.col][i]
--? result = result + Margin_above + height(pane) + Margin_below + Padding_vertical
--? end
print('cursor line contains ^'..pane.lines[pane.cursor1.line].data..'$')
print('cursor is at', y_of_schema1(pane, pane.cursor1), 'from top of pane')
--? print(y_of_schema1(pane, pane.cursor1))
--? print('viewport starts at', Display_settings.y)
--? print('pane starts at', up_edge_sy(Cursor_pane.col, Cursor_pane.row))
--? print('cursor line contains ^'..pane.lines[pane.cursor1.line].data..'$')
--? print('cursor is at', y_of_schema1(pane, pane.cursor1), 'from top of pane')
-- I don't understand why I need 4 line heights here.
-- Search bar is approximately 1.5 line heights. 3 should be plenty to
-- show the screen.
-- Doesn't matter what column it is on screen
print('cursor used to be at ', cursor_sy - Display_settings.y)
local old = Display_settings.y
print('subtract', App.screen.height, App.screen.height-Header_height)
--? Display_settings.y = cursor_sy - (App.screen.height - Header_height)
--? print('cursor used to be at ', cursor_sy - Display_settings.y)
--? print('subtract', App.screen.height, App.screen.height-Header_height)
--? Display_settings.y = cursor_sy + Line_height + Text.search_bar_height(pane) - (App.screen.height - Header_height)
print('=>', Display_settings.y)
print('cursor now at ', cursor_sy - Display_settings.y)
print('viewport height', App.screen.height)
print('cursor row starts', App.screen.height - (cursor_sy-Display_settings.y), 'px above bottom of viewport') -- totally wrong
--? print('=>', Display_settings.y)
--? print('cursor now at ', cursor_sy - Display_settings.y)
--? print('viewport height', App.screen.height)
--? print('cursor row starts', App.screen.height - (cursor_sy-Display_settings.y), 'px above bottom of viewport') -- totally wrong