Why the fuck is this so fucking hard?
IMEJA43L3OX7S5KIYLZJ4F3ITACLAA5SZBHSCIJMULCPRSW7LXBAC
XOAHJ6M3QKHSE5F7ICLPXN3RMH7JQEZXDKTOTIOBYKJFVT6PMYRAC
QYIFOHW3WDDQMK4ATY6IOSQRFHJOQ5QCPDKRC4GVGWLQEH4HGWVQC
H2DPLWMVRFYTO2CQTG54FMT2LF3B6UKLXH32CUA22DNQJVP5XBNQC
BULPIBEGL7TMK6CVIE7IS7WGAHGOSUJBGJSFQK542MOWGHP2ADQQC
2RXZ3PGOTTZ6M4R372JXIKPLBQKPVBMAXNPIEO2HZDN4EMYW4GNAC
ESETRNLB3MIJ2SID6HJMMP52FEVUBLGK2HLWD75KDQZAKQMKSF2QC
YTSPVDZHEN5LLNMGIBUBLPWFWSFM3SOHBRGWYSDEVFKRTH24ARRQC
S5VCAFKYBM35HF3SI4MCAQROWBRUC7YHWJMKWC6GWTTV5PHUCEFAC
U7M4M2F7P5TGLTHKQ7J72GQFNPBII4PLJVJ44YVVOYEI4KPUDI6AC
PFT5Y2ZYGQA6XXOZ5HH75WVUGA4B3KTDRHSFOZRAUKTPSFOPMNRAC
76AIXR7HAUL74GYPPFH3N5N4VJWZL67WM4XTKWGSA6ESLIJZPB6QC
AVTNUQYRBW7IX2YQ3KDLVQ23RGW3BAKTAE7P73ASBYNKOHMQMH5AC
3QNOKBFMKBGXBVJIRHR2444JRRMBTABHE4674NR3DT67RRM2X6GAC
check_eq(Screen_top1.line, 2, 'F - test_down_arrow_scrolls_down_by_one_line/screen_top')
check_eq(Cursor1.line, 4, 'F - test_down_arrow_scrolls_down_by_one_line/cursor')
end
function test_down_arrow_scrolls_down_by_one_screen_line()
print('test_down_arrow_scrolls_down_by_one_screen_line')
-- display the first three lines with the cursor on the bottom line
App.screen.init{width=25+30, height=60}
Lines = load_array{'abc', 'def', 'ghi jkl', 'mno'}
Line_width = App.screen.width
Cursor1 = {line=3, pos=1}
Screen_top1 = {line=1, pos=1}
Screen_bottom1 = {}
Zoom = 1
local screen_top_margin = 15 -- pixels
local line_height = math.floor(15*Zoom) -- pixels
App.draw()
local y = screen_top_margin
App.screen.check(y, 'abc', 'F - test_down_arrow_scrolls_down_by_one_screen_line/baseline/screen:1')
y = y + line_height
App.screen.check(y, 'def', 'F - test_down_arrow_scrolls_down_by_one_screen_line/baseline/screen:2')
y = y + line_height
App.screen.check(y, 'ghi ', 'F - test_down_arrow_scrolls_down_by_one_screen_line/baseline/screen:3') -- line wrapping includes trailing whitespace
-- after hitting the down arrow the screen scrolls down by one line
App.run_after_keychord('down')
check_eq(Screen_top1.line, 2, 'F - test_down_arrow_scrolls_down_by_one_screen_line/screen_top')
check_eq(Cursor1.line, 3, 'F - test_down_arrow_scrolls_down_by_one_screen_line/cursor:line')
check_eq(Cursor1.pos, 5, 'F - test_down_arrow_scrolls_down_by_one_screen_line/cursor:pos')
y = screen_top_margin
App.screen.check(y, 'def', 'F - test_down_arrow_scrolls_down_by_one_screen_line/screen:1')
y = y + line_height
App.screen.check(y, 'ghi ', 'F - test_down_arrow_scrolls_down_by_one_screen_line/screen:2')
y = y + line_height
-- HERE
App.screen.check(y, 'jkl', 'F - test_down_arrow_scrolls_down_by_one_screen_line/screen:3')
end
function test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word()
print('test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word')
-- display the first three lines with the cursor on the bottom line
App.screen.init{width=25+30, height=60}
Lines = load_array{'abc', 'def', 'ghijkl', 'mno'}
Line_width = App.screen.width
Cursor1 = {line=3, pos=1}
Screen_top1 = {line=1, pos=1}
Screen_bottom1 = {}
Zoom = 1
local screen_top_margin = 15 -- pixels
local line_height = math.floor(15*Zoom) -- pixels
App.draw()
local y = screen_top_margin
App.screen.check(y, 'abc', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/baseline/screen:1')
y = y + line_height
App.screen.check(y, 'def', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/baseline/screen:2')
y = y + line_height
App.screen.check(y, 'ghijk', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/baseline/screen:3')
-- after hitting the down arrow the screen scrolls down by one line
App.run_after_keychord('down')
check_eq(Screen_top1.line, 2, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen_top')
check_eq(Cursor1.line, 3, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/cursor:line')
check_eq(Cursor1.pos, 6, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/cursor:pos')
y = screen_top_margin
App.screen.check(y, 'def', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen:1')
y = y + line_height
App.screen.check(y, 'ghijk', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen:2')
y = y + line_height
App.screen.check(y, 'l', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen:3')
check_eq(Screen_top1.line, 1, 'F - test_up_arrow_scrolls_up_by_one_line/screen_top')
check_eq(Cursor1.line, 1, 'F - test_up_arrow_scrolls_up_by_one_line/cursor')
end
function test_up_arrow_scrolls_up_by_one_screen_line()
print('test_up_arrow_scrolls_up_by_one_screen_line')
-- display the lines 2/3/4 with the cursor on line 2
App.screen.init{width=120, height=60}
Lines = load_array{'abc', 'def', 'ghi', 'jkl'}
Line_width = App.screen.width
Cursor1 = {line=2, pos=1}
Screen_top1 = {line=2, pos=1}
Screen_bottom1 = {}
Zoom = 1
local screen_top_margin = 15 -- pixels
local line_height = math.floor(15*Zoom) -- pixels
App.draw()
local y = screen_top_margin
App.screen.check(y, 'def', 'F - test_up_arrow_scrolls_up_by_one_screen_line/baseline/screen:1')
y = y + line_height
App.screen.check(y, 'ghi', 'F - test_up_arrow_scrolls_up_by_one_screen_line/baseline/screen:2')
y = y + line_height
App.screen.check(y, 'jkl', 'F - test_up_arrow_scrolls_up_by_one_screen_line/baseline/screen:3')
-- after hitting the up arrow the screen scrolls up by one line
App.run_after_keychord('up')
y = screen_top_margin
App.screen.check(y, 'abc', 'F - test_up_arrow_scrolls_up_by_one_screen_line/screen:1')
y = y + line_height
App.screen.check(y, 'def', 'F - test_up_arrow_scrolls_up_by_one_screen_line/screen:2')
y = y + line_height
App.screen.check(y, 'ghi', 'F - test_up_arrow_scrolls_up_by_one_screen_line/screen:3')
check_eq(Screen_top1.line, 1, 'F - test_up_arrow_scrolls_up_by_one_screen_line/screen_top')
check_eq(Cursor1.line, 1, 'F - test_up_arrow_scrolls_up_by_one_screen_line/cursor')
function Text.nearest_pos_less_than(line, x) -- x DOES NOT include left margin
if x == 0 then
return 1
end
local len = utf8.len(line)
local max_x = Text.cursor_x2(line, len+1)
if x > max_x then
return len+1
end
local left, right = 1, len+1
--? print('--')
while true do
local curr = math.floor((left+right)/2)
local currxmin = Text.cursor_x2(line, curr+1)
local currxmax = Text.cursor_x2(line, curr+2)
--? print(x, left, right, curr, currxmin, currxmax)
if currxmin <= x and x < currxmax then
return curr
end
if left >= right-1 then
return left
end
if currxmin > x then
right = curr
else
left = curr
end
end
assert(false)
end