Looks pretty clean.
MGT5FTJ35MGYCQO3TZVK3RYUIN5YX475R4XG7RO42SYLYF4AIKFAC
5ED3YGHW6H7XIXPMHRI5ZJ3VA5UCANZF4AJRSE6V7BLUF67Q6NAAC
WLHI7KD3LJTQH6V7RLVJWGZUR4YQK6LN4OIUMIN45BGMMQGN6RNQC
76AIXR7HAUL74GYPPFH3N5N4VJWZL67WM4XTKWGSA6ESLIJZPB6QC
H2DPLWMVRFYTO2CQTG54FMT2LF3B6UKLXH32CUA22DNQJVP5XBNQC
BULPIBEGL7TMK6CVIE7IS7WGAHGOSUJBGJSFQK542MOWGHP2ADQQC
XNFTJHC4QSHNSIWNN7K6QZEZ37GTQYKHS4EPNSVPQCUSWREROGIQC
DLQMM2656JHXX3ONOEM6UIOXKFJFT5QT7RHWK7YS2W77PVZWHRSAC
FEEGTRGQR5PETZZQLXVDMILD3Z3CMXP7IDR3DFVXBCGE7GMHB7GQC
BJ5X5O4ACBBJ56LRBBSTCW6IBQP4HAEOOOPNH3SKTA4F66YTOIDAC
-- previous text line
local new_cursor_line = Cursor_line
while new_cursor_line > 1 do
new_cursor_line = new_cursor_line-1
if Lines[new_cursor_line].mode == 'text' then
local old_x = Text.cursor_x(Lines[new_cursor_line].data, Cursor_pos)
Cursor_line = new_cursor_line
Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x)
break
if Top_screen_line_starting_pos == 1 then
-- top line is done; skip to previous text line
local new_cursor_line = Cursor_line
while new_cursor_line > 1 do
new_cursor_line = new_cursor_line-1
if Lines[new_cursor_line].mode == 'text' then
local old_x = Text.cursor_x(Lines[new_cursor_line].data, Cursor_pos)
Cursor_line = new_cursor_line
Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x)
break
end
end
if Cursor_line < Screen_top_line then
Screen_top_line = Cursor_line
end
if Cursor_line < Screen_top_line then
Screen_top_line = Cursor_line
else
-- scroll up just one screen line in current line
local screen_line_index = table.find(Lines[Cursor_line].screen_line_starting_pos, Top_screen_line_starting_pos)
assert(screen_line_index > 1)
Top_screen_line_starting_pos = Lines[Cursor_line].screen_line_starting_pos[screen_line_index-1]
local s = string.sub(Lines[Cursor_line].data, Top_screen_line_starting_pos)
Cursor_pos = Text.nearest_cursor_pos(s, Cursor_x)
scrolling:
given moby dick, a file containing all text:
page up moves top line on screen to bottom
page down moves bottom line on screen to top
cursor remains on screen
cursor remains on text line
'up' arrow with cursor at top of screen scrolls up one line (drawings still fully in or out)
if top line wrapped before, it scrolls up by only one screen line
'down' arrow with cursor at bottom of screen scrolls down one line (drawings still fully in or out)
if top line wrapped before, it scrolls down by only one screen line