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N24J4YRQC WKXJNESIMLTTUCTCT7Y32R4ESTKREY7L5JDZ43MWIPM5DVM47R5AC UGTWUIS4MWIITRDEAGULOPRV5KJD7HEGCOSR5BP4KLVBAVHU2ETQC QMRQL2FOIIXU3PCSH7UQIDRLKJN2DQHB5IUL4TLBVANNHWWETL6AC function test_pagedown_often_shows_start_of_wrapping_line()-- draw a few lines ending in part of a wrapping lineApp.screen.init{width=50, height=60}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{'abc', 'def ghi jkl', 'mno'}Text.redraw_all(Editor_state)Editor_state.cursor1 = {line=1, pos=1}Editor_state.screen_top1 = {line=1, pos=1}Editor_state.screen_bottom1 = {}edit.draw(Editor_state)local y = Editor_state.topApp.screen.check(y, 'abc', 'baseline/screen:1')y = y + Editor_state.line_heightApp.screen.check(y, 'def ', 'baseline/screen:2')y = y + Editor_state.line_heightApp.screen.check(y, 'ghi ', 'baseline/screen:3')-- after pagedown we start drawing from the bottom _line_ (multiple screen lines)edit.run_after_keychord(Editor_state, 'pagedown', 'pagedown')check_eq(Editor_state.screen_top1.line, 2, 'screen_top:line')check_eq(Editor_state.screen_top1.pos, 1, 'screen_top:pos')check_eq(Editor_state.cursor1.line, 2, 'cursor:line')check_eq(Editor_state.cursor1.pos, 1, 'cursor:pos')y = Editor_state.topApp.screen.check(y, 'def ', 'screen:1')y = y + Editor_state.line_heightApp.screen.check(y, 'ghi ', 'screen:2')y = y + Editor_state.line_heightApp.screen.check(y, 'jkl', 'screen:3')end
edit.draw(Editor_state) -- populate line_cache.startpos for each lineedit.draw(Editor_state) -- populate line_cache.startpos for each lineedit.draw(Editor_state) -- populate line_cache.startpos for each lineedit.draw(Editor_state) -- populate line_cache.startpos for each lineedit.draw(Editor_state) -- populate line_cache.startpos for each line
function Text.draw(State, line_index, y, startpos)--? print('text.draw', line_index, y)local line = State.lines[line_index]local line_cache = State.line_cache[line_index]Text.populate_screen_line_starting_pos(State, line_index)
if pos < startpos then-- render nothingelselocal screen_line = Text.screen_line(line, line_cache, i)--? print('text.draw:', screen_line, 'at', line_index,pos, 'after', x,y)local frag_len = utf8.len(screen_line)
--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
--? print('pageup')
State.screen_top1 = Text.previous_screen_top1(State)State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(State)Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaksend-- return the top y coordinate of a given line_index,-- or nil if no part of it is on screenfunction Text.starty(State, line_index)
local top2 = Text.to2(State, State.screen_top1)--? print(App.screen.height)
-- does not modify State (except to populate line_cache)if line_index < State.screen_top1.line then return endlocal loc2 = Text.to2(State, State.screen_top1)local y = State.topwhile true doif loc2.line == line_index then return y endy = y + State.line_heightif y + State.line_height > App.screen.height then break endlocal next_loc2 = Text.next_screen_line(State, loc2)if Text.eq2(next_loc2, loc2) then break end -- end of fileloc2 = next_loc2endendfunction Text.previous_screen_top1(State)-- duplicate some logic from love.draw-- does not modify State (except to populate line_cache)local loc2 = Text.to2(State, State.screen_top1)
State.screen_top1 = Text.to1(State, top2)State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(State)--? print(State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)--? print('pageup end')
return Text.to1(State, loc2)
--? print('pagedown')-- If a line/paragraph gets to a page boundary, I often want to scroll-- before I get to the bottom.-- However, only do this if it makes forward progress.local bot2 = Text.to2(State, State.screen_bottom1)if bot2.screen_line > 1 thenbot2.screen_line = math.max(bot2.screen_line-10, 1)endlocal new_top1 = Text.to1(State, bot2)if Text.lt1(State.screen_top1, new_top1) thenState.screen_top1 = new_top1elseState.screen_top1 = {line=State.screen_bottom1.line, pos=State.screen_bottom1.pos}end--? print('setting top to', State.screen_top1.line, State.screen_top1.pos)
State.screen_top1 = Text.screen_bottom1(State)
--? print('pagedown end')
end-- return the location of the start of the bottom-most line on screenfunction Text.screen_bottom1(State)-- duplicate some logic from love.draw-- does not modify State (except to populate line_cache)local loc2 = Text.to2(State, State.screen_top1)local y = State.topwhile true doy = y + State.line_heightif y + State.line_height > App.screen.height then break endlocal next_loc2 = Text.next_screen_line(State, loc2)if Text.eq2(next_loc2, loc2) then break endloc2 = next_loc2endreturn Text.to1(State, loc2)
--? print('down', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
--? print('down', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)
if State.cursor1.line > State.screen_bottom1.line then
local screen_bottom1 = Text.screen_bottom1(State)--? print('down 2', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, screen_bottom1.line, screen_bottom1.pos)if State.cursor1.line > screen_bottom1.line then
--? print('=>', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
--? print('=>', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)
--? print('snap', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
--? print('snap', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
--? print('snap =>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
--? print('snap =>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
if line_cache.starty == nil then return false end -- outside current pageif y < line_cache.starty then return false end
local starty = Text.starty(State, line_index)if starty == nil then return false end -- outside current pageif y < starty then return false end
return y < line_cache.starty + State.line_height*(#line_cache.screen_line_starting_pos - Text.screen_line_index(line_cache.screen_line_starting_pos, line_cache.startpos) + 1)
return y < starty + State.line_height*(#line_cache.screen_line_starting_pos - Text.screen_line_index(line_cache.screen_line_starting_pos, line_cache.startpos) + 1)
function Text.next_screen_line(State, loc2)Text.populate_screen_line_starting_pos(State, loc2.line)if loc2.screen_line >= #State.line_cache[loc2.line].screen_line_starting_pos thenif loc2.line < #State.lines thenreturn {line=loc2.line+1, screen_line=1, screen_pos=1}elsereturn loc2endelsereturn {line=loc2.line, screen_line=loc2.screen_line+1, screen_pos=1}endend
-- this approach is cheaper and almost works, except on the final screen-- where file ends above bottom of screen--? local botpos = Text.pos_at_start_of_screen_line(State, State.cursor1)--? local botline1 = {line=State.cursor1.line, pos=botpos}--? return Text.lt1(State.screen_bottom1, botline1)
end--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)State.screen_top1 = Text.previous_screen_top1(State)State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(State)Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaksend-- return the top y coordinate of a given line_index,-- or nil if no part of it is on screenfunction Text.starty(State, line_index)-- duplicate some logic from love.draw-- does not modify State (except to populate line_cache)if line_index < State.screen_top1.line then return endlocal loc2 = Text.to2(State, State.screen_top1)local y = State.topwhile true doif loc2.line == line_index then return y endy = y + State.line_heightif y + State.line_height > App.screen.height then break endlocal next_loc2 = Text.next_screen_line(State, loc2)if Text.eq2(next_loc2, loc2) then break end -- end of fileloc2 = next_loc2endendfunction Text.previous_screen_top1(State)-- does not modify State (except to populate line_cache)local loc2 = Text.to2(State, State.screen_top1)if loc2.line == 1 and loc2.screen_line == 1 and loc2.screen_pos == 1 then break endy = y - State.line_heightloc2 = Text.previous_screen_line(State, loc2)return Text.to1(State, loc2)State.screen_top1 = Text.screen_bottom1(State)end-- return the location of the start of the bottom-most line on screenfunction Text.screen_bottom1(State)-- duplicate some logic from love.draw-- does not modify State (except to populate line_cache)local loc2 = Text.to2(State, State.screen_top1)local y = State.topwhile true doy = y + State.line_heightif y + State.line_height > App.screen.height then break endlocal next_loc2 = Text.next_screen_line(State, loc2)if Text.eq2(next_loc2, loc2) then break endloc2 = next_loc2endreturn Text.to1(State, loc2)--? print('down', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)--? print('cursor at final screen line of its line')--? print(State.cursor1.pos)local screen_bottom1 = Text.screen_bottom1(State)--? print('down 2', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, screen_bottom1.line, screen_bottom1.pos)if State.cursor1.line > screen_bottom1.line thenlocal screen_bottom1 = Text.screen_bottom1(State)local scroll_down = Text.le1(screen_bottom1, State.cursor1)--? print('cursor is NOT at final screen line of its line')--? print('screen top before:', State.screen_top1.line, State.screen_top1.pos)--? print('scroll up preserving cursor')--? print('screen top after:', State.screen_top1.line, State.screen_top1.pos)--? print('switching pos of screen line at cursor from '..tostring(screen_line_starting_pos)..' to '..tostring(new_screen_line_starting_pos))--? print('cursor pos is now', State.cursor1.line, State.cursor1.pos)--? print('scroll up preserving cursor')--? print('screen top after:', State.screen_top1.line, State.screen_top1.pos)function Text.final_text_loc_on_screen(State)local screen_bottom1 = Text.screen_bottom1(State)return {line=screen_bottom1.line,pos=Text.pos_at_end_of_screen_line(State, screen_bottom1),}
--? print('snap', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)--? print('snap =>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)local starty = Text.starty(State, line_index)if starty == nil then return false end -- outside current pageif y < starty then return false endreturn y < starty + State.line_height*(#line_cache.screen_line_starting_pos - Text.screen_line_index(line_cache.screen_line_starting_pos, line_cache.startpos) + 1)local starty = Text.starty(State, line_index)assert(my >= starty, 'failed to map y pixel to line')local y = startyfunction Text.eq2(a, b)return a.line == b.line and a.screen_line == b.screen_line and a.screen_pos == b.screen_posendendendfunction Text.next_screen_line(State, loc2)Text.populate_screen_line_starting_pos(State, loc2.line)if loc2.screen_line >= #State.line_cache[loc2.line].screen_line_starting_pos thenif loc2.line < #State.lines thenreturn {line=loc2.line+1, screen_line=1, screen_pos=1}elsereturn loc2endelsereturn {line=loc2.line, screen_line=loc2.screen_line+1, screen_pos=1}local screen_bottom1 = Text.screen_bottom1(State)elseif State.cursor1.line >= screen_bottom1.line thenState.cursor1 = Text.final_text_loc_on_screen(State)--? print('=>', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)
Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{}Text.redraw_all(Editor_state)edit.draw(Editor_state)edit.run_after_mouse_click(Editor_state, 8,Editor_state.top+8, 1)-- cursor skips drawing to always remain on text
endfunction test_backspace_to_delete_drawing()-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)App.screen.init{width=120, height=60}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{'```lines', '```', ''}Text.redraw_all(Editor_state)-- cursor is on text as always (outside tests this will get initialized correctly)Editor_state.cursor1.line = 2-- backspacing deletes the drawing
edit.run_after_keychord(Editor_state, 'M-right', 'right')edit.run_after_keychord(Editor_state, 'M-right', 'right')edit.draw(Editor_state) -- populate line_cache.startpos for each lineedit.run_after_keychord(Editor_state, 'S-right', 'right')edit.run_after_keychord(Editor_state, 'right', 'right')edit.draw(Editor_state) -- populate line_cache.startpos for each lineedit.draw(Editor_state) -- populate line_cache.startpos for each line
local drawing_height = Drawing_padding_height + drawing_width/2 -- default-- initially the screen displays the first line and the drawing-- 15px margin + 15px line1 + 10px margin + 25px drawing + 10px margin = 75px < screen height 80pxedit.draw(Editor_state)local y = Editor_state.top
-- return y for the next linefinal_screen_line_starting_pos = pos
endfunction Text.screen_line(line, line_cache, i)local pos = line_cache.screen_line_starting_pos[i]local offset = Text.offset(line.data, pos)if i >= #line_cache.screen_line_starting_pos thenreturn line.data:sub(offset)
--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
--? print('pageup')
State.screen_top1 = Text.previous_screen_top1(State)State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(State)Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaksend-- return the top y coordinate of a given line_index,-- or nil if no part of it is on screenfunction Text.starty(State, line_index)
local top2 = Text.to2(State, State.screen_top1)--? print(App.screen.height)
-- does not modify State (except to populate line_cache)if line_index < State.screen_top1.line then return endlocal loc2 = Text.to2(State, State.screen_top1)local y = State.topwhile true doif State.lines[loc2.line].mode == 'drawing' theny = y + Drawing_padding_topendif loc2.line == line_index then return y endif State.lines[loc2.line].mode == 'text' theny = y + State.line_heightelseif State.lines[loc2.line].mode == 'drawing' theny = y + Drawing.pixels(State.lines[loc2.line].h, State.width) + Drawing_padding_bottomendif y + State.line_height > App.screen.height then break endlocal next_loc2 = Text.next_screen_line(State, loc2)if Text.eq2(next_loc2, loc2) then break end -- end of fileloc2 = next_loc2endendfunction Text.previous_screen_top1(State)-- duplicate some logic from love.draw-- does not modify State (except to populate line_cache)local loc2 = Text.to2(State, State.screen_top1)
--? print(y, top2.line, top2.screen_line, top2.screen_pos)if State.screen_top1.line == 1 and State.screen_top1.pos == 1 then break endif State.lines[State.screen_top1.line].mode == 'text' then
if loc2.line == 1 and loc2.screen_line == 1 and loc2.screen_pos == 1 then break endif State.lines[loc2.line].mode == 'text' then
elseif State.lines[State.screen_top1.line].mode == 'drawing' theny = y - Drawing_padding_height - Drawing.pixels(State.lines[State.screen_top1.line].h, State.width)
elseif State.lines[loc2.line].mode == 'drawing' theny = y - Drawing_padding_height - Drawing.pixels(State.lines[loc2.line].h, State.width)
State.screen_top1 = Text.to1(State, top2)State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(State)--? print(State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)--? print('pageup end')
return Text.to1(State, loc2)
--? print('pagedown end')
end-- return the location of the start of the bottom-most line on screenfunction Text.screen_bottom1(State)-- duplicate some logic from love.draw-- does not modify State (except to populate line_cache)local loc2 = Text.to2(State, State.screen_top1)local y = State.topwhile true doif State.lines[loc2.line].mode == 'text' theny = y + State.line_heightelseif State.lines[loc2.line].mode == 'drawing' theny = y + Drawing_padding_height + Drawing.pixels(State.lines[loc2.line].h, State.width)endif y + State.line_height > App.screen.height then break endlocal next_loc2 = Text.next_screen_line(State, loc2)if Text.eq2(next_loc2, loc2) then break endloc2 = next_loc2endreturn Text.to1(State, loc2)
--? print('down', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
--? print('down', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)
if State.cursor1.line > State.screen_bottom1.line then
local screen_bottom1 = Text.screen_bottom1(State)--? print('down 2', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, screen_bottom1.line, screen_bottom1.pos)if State.cursor1.line > screen_bottom1.line then
--? print('=>', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
--? print('=>', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)
endfunction Text.final_text_loc_on_screen(State)local screen_bottom1 = Text.screen_bottom1(State)if State.lines[screen_bottom1.line].mode == 'text' thenreturn {line=screen_bottom1.line,pos=Text.pos_at_end_of_screen_line(State, screen_bottom1),}endlocal loc2 = Text.to2(State, screen_bottom1)while true doif State.lines[loc2.line].mode == 'text' then break endassert(loc2.line > 1 or loc2.screen_line > 1 and loc2.screen_pos > 1) -- elsewhere we're making sure there's always at least one text line on screenloc2 = Text.previous_screen_line(State, loc2)endlocal result = Text.to1(State, loc2)result.pos = Text.pos_at_end_of_screen_line(State, result)return result
--? print('snap', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
--? print('snap', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
--? print('snap =>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
--? print('snap =>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
if line_cache.starty == nil then return false end -- outside current pageif y < line_cache.starty then return false end
local starty = Text.starty(State, line_index)if starty == nil then return false end -- outside current pageif y < starty then return false end
return y < line_cache.starty + State.line_height*(#line_cache.screen_line_starting_pos - Text.screen_line_index(line_cache.screen_line_starting_pos, line_cache.startpos) + 1)
return y < starty + State.line_height*(#line_cache.screen_line_starting_pos - Text.screen_line_index(line_cache.screen_line_starting_pos, line_cache.startpos) + 1)
function Text.next_screen_line(State, loc2)if State.lines[loc2.line].mode == 'drawing' thenreturn {line=loc2.line+1, screen_line=1, screen_pos=1}endText.populate_screen_line_starting_pos(State, loc2.line)if loc2.screen_line >= #State.line_cache[loc2.line].screen_line_starting_pos thenif loc2.line < #State.lines thenreturn {line=loc2.line+1, screen_line=1, screen_pos=1}elsereturn loc2endelsereturn {line=loc2.line, screen_line=loc2.screen_line+1, screen_pos=1}endend
-- this approach is cheaper and almost works, except on the final screen-- where file ends above bottom of screen--? local botpos = Text.pos_at_start_of_screen_line(State, State.cursor1)--? local botline1 = {line=State.cursor1.line, pos=botpos}--? return Text.lt1(State.screen_bottom1, botline1)
--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)State.screen_top1 = Text.previous_screen_top1(State)State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(State)Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaksend-- return the top y coordinate of a given line_index,-- or nil if no part of it is on screenfunction Text.starty(State, line_index)-- does not modify State (except to populate line_cache)if line_index < State.screen_top1.line then return endlocal loc2 = Text.to2(State, State.screen_top1)local y = State.topwhile true doif State.lines[loc2.line].mode == 'drawing' theny = y + Drawing_padding_topendif loc2.line == line_index then return y endif State.lines[loc2.line].mode == 'text' theny = y + State.line_heightelseif State.lines[loc2.line].mode == 'drawing' theny = y + Drawing.pixels(State.lines[loc2.line].h, State.width) + Drawing_padding_bottomendif y + State.line_height > App.screen.height then break endlocal next_loc2 = Text.next_screen_line(State, loc2)if Text.eq2(next_loc2, loc2) then break end -- end of fileloc2 = next_loc2endendfunction Text.previous_screen_top1(State)-- duplicate some logic from love.draw-- does not modify State (except to populate line_cache)local loc2 = Text.to2(State, State.screen_top1)if loc2.line == 1 and loc2.screen_line == 1 and loc2.screen_pos == 1 then break endif State.lines[loc2.line].mode == 'text' thenelseif State.lines[loc2.line].mode == 'drawing' theny = y - Drawing_padding_height - Drawing.pixels(State.lines[loc2.line].h, State.width)loc2 = Text.previous_screen_line(State, loc2)return Text.to1(State, loc2)State.screen_top1 = Text.screen_bottom1(State)State.cursor1 = Text.final_text_loc_on_screen(State)elseif State.cursor1.line >= screen_bottom1.line thenlocal screen_bottom1 = Text.screen_bottom1(State)function Text.next_screen_line(State, loc2)if State.lines[loc2.line].mode == 'drawing' thenreturn {line=loc2.line+1, screen_line=1, screen_pos=1}endText.populate_screen_line_starting_pos(State, loc2.line)if loc2.screen_line >= #State.line_cache[loc2.line].screen_line_starting_pos thenif loc2.line < #State.lines thenreturn {line=loc2.line+1, screen_line=1, screen_pos=1}elsereturn loc2endelsereturn {line=loc2.line, screen_line=loc2.screen_line+1, screen_pos=1}endendendfunction Text.eq2(a, b)return a.line == b.line and a.screen_line == b.screen_line and a.screen_pos == b.screen_poslocal y = startylocal starty = Text.starty(State, line_index)assert(my >= starty, 'failed to map y pixel to line')return y < starty + State.line_height*(#line_cache.screen_line_starting_pos - Text.screen_line_index(line_cache.screen_line_starting_pos, line_cache.startpos) + 1)local starty = Text.starty(State, line_index)if starty == nil then return false end -- outside current pageif y < starty then return false end--? print('snap =>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)--? print('snap', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)endfunction Text.final_text_loc_on_screen(State)local screen_bottom1 = Text.screen_bottom1(State)if State.lines[screen_bottom1.line].mode == 'text' thenreturn {line=screen_bottom1.line,pos=Text.pos_at_end_of_screen_line(State, screen_bottom1),}endlocal loc2 = Text.to2(State, screen_bottom1)while true doif State.lines[loc2.line].mode == 'text' then break endassert(loc2.line > 1 or loc2.screen_line > 1 and loc2.screen_pos > 1) -- elsewhere we're making sure there's always at least one text line on screenloc2 = Text.previous_screen_line(State, loc2)endlocal result = Text.to1(State, loc2)result.pos = Text.pos_at_end_of_screen_line(State, result)return resultassert(State.lines[loc1.line].mode == 'text')--? print('=>', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)local screen_bottom1 = Text.screen_bottom1(State)local scroll_down = Text.le1(screen_bottom1, State.cursor1)local screen_bottom1 = Text.screen_bottom1(State)--? print('down 2', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos, screen_bottom1.line, screen_bottom1.pos)if State.cursor1.line > screen_bottom1.line then--? print('down', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)end-- return the location of the start of the bottom-most line on screenfunction Text.screen_bottom1(State)-- duplicate some logic from love.draw-- does not modify State (except to populate line_cache)local loc2 = Text.to2(State, State.screen_top1)local y = State.topwhile true doif State.lines[loc2.line].mode == 'text' theny = y + State.line_heightelseif State.lines[loc2.line].mode == 'drawing' theny = y + Drawing_padding_height + Drawing.pixels(State.lines[loc2.line].h, State.width)endif y + State.line_height > App.screen.height then break endlocal next_loc2 = Text.next_screen_line(State, loc2)if Text.eq2(next_loc2, loc2) then break endloc2 = next_loc2endreturn Text.to1(State, loc2)
-- a (h)eight,-- an array of points, and-- an array of shapes-- a shape is a table containing:-- a mode-- an array points for mode 'freehand' (raw x,y coords; freehand drawings don't pollute the points array of a drawing)-- an array vertices for mode 'polygon', 'rectangle', 'square'-- p1, p2 for mode 'line'-- center, radius for mode 'circle'-- center, radius, start_angle, end_angle for mode 'arc'-- Unless otherwise specified, coord fields are normalized; a drawing is always 256 units wide-- The field names are carefully chosen so that switching modes in midstream-- remembers previously entered points where that makes sense.
State.selection1 = Text.final_text_loc_on_screen(State)State.cursor1 = Text.final_text_loc_on_screen(State)State.cursor1 = Text.screen_bottom1(State)
chord ~= 'C-a' and chord ~= 'C-c' and chord ~= 'C-x' and chord ~= 'backspace' and chord ~= 'delete' and chord ~= 'C-z' and chord ~= 'C-y' and not App.is_cursor_movement(chord) then
chord ~= 'C-a' and chord ~= 'C-c' and chord ~= 'C-x' and chord ~= 'backspace' and chord ~= 'delete' and chord ~= 'C-z' and chord ~= 'C-y' and not App.is_cursor_movement(key) then
record_undo_event(State, {before=before, after=snapshot(State, drawing_index)})schedule_save(State)endelseif chord == 'escape' and not App.mouse_down(1) thenfor _,line in ipairs(State.lines) doif line.mode == 'drawing' thenline.show_help = falseendend
if chord == 'return' thenState.current_drawing_mode = State.previous_drawing_modeState.previous_drawing_mode = nilelselocal before = snapshot(State, State.lines.current_drawing_index)local drawing = State.lines.current_drawinglocal p = drawing.points[drawing.pending.target_point]if chord == 'escape' thenp.name = nilrecord_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)})elseif chord == 'backspace' thenlocal len = utf8.len(p.name)
if y < State.top thenlocal screen_bottom1 = Text.screen_bottom1(State)return screen_bottom1.line, Text.pos_at_end_of_screen_line(State, screen_bottom1)
---- On lines that are drawings, pos will be nil.cursor1 = {line=1, pos=1}, -- position of cursor; must be on a text line
--? print('== draw')for line_index = State.screen_top1.line,#State.lines dolocal line = State.lines[line_index]--? print('draw:', y, line_index, line)if y + State.line_height > App.screen.height then break end--? print('text.draw', y, line_index)local startpos = 1if line_index == State.screen_top1.line thenstartpos = State.screen_top1.posend
--? print('=> y', y)endif State.search_term thenText.draw_search_bar(State)endreturn yendfunction edit.update(State, dt)if State.next_save and State.next_save < Current_time thensave_to_disk(State)State.next_save = nilendendfunction schedule_save(State)if State.next_save == nil thenState.next_save = Current_time + 3 -- short enough that you're likely to still remember what you didendendfunction edit.quit(State)-- make sure to save before quittingif State.next_save thensave_to_disk(State)-- give some time for the OS to flush everything to disklove.timer.sleep(0.1)endendfunction edit.mouse_press(State, x,y, mouse_button)
--? print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))if y < State.top thenState.old_cursor1 = State.cursor1State.old_selection1 = State.selection1State.mousepress_shift = App.shift_down()State.selection1 = {line=State.screen_top1.line,pos=State.screen_top1.pos,}returnendfor line_index,line in ipairs(State.lines) doif Text.in_line(State, line_index, x,y) then-- delicate dance between cursor, selection and old cursor/selection-- scenarios:-- regular press+release: sets cursor, clears selection-- shift press+release:-- sets selection to old cursor if not set otherwise leaves it untouched-- sets cursor-- press and hold to start a selection: sets selection on press, cursor on release-- press and hold, then press shift: ignore shift-- i.e. mouse_release should never look at shift state--? print_and_log(('edit.mouse_press: in line %d'):format(line_index))State.old_cursor1 = State.cursor1State.old_selection1 = State.selection1State.mousepress_shift = App.shift_down()State.selection1 = {line=line_index,pos=Text.to_pos_on_line(State, line_index, x, y),}returnendend
for line_index,line in ipairs(State.lines) doif Text.in_line(State, line_index, x,y) then--? print_and_log(('edit.mouse_release: in line %d'):format(line_index))State.cursor1 = {line=line_index,pos=Text.to_pos_on_line(State, line_index, x, y),}--? print_and_log(('edit.mouse_release: cursor now %d,%d'):format(State.cursor1.line, State.cursor1.pos))
for i=1,math.floor(-dy) doText.down(State)endendendfunction edit.text_input(State, t)--? print('text input', t)if State.search_term thenState.search_term = State.search_term..tText.search_next(State)elseText.text_input(State, t)endschedule_save(State)endfunction edit.keychord_press(State, chord, key)if State.selection1.line and-- printable character created using shift key => delete selection-- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys)(not App.shift_down() or utf8.len(key) == 1) and
Text.delete_selection(State, State.left, State.right)endif State.search_term thenif chord == 'escape' thenState.search_term = nilState.cursor1 = State.search_backup.cursorState.screen_top1 = State.search_backup.screen_topState.search_backup = nilText.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leakselseif chord == 'return' thenState.search_term = nilState.search_backup = nilelseif chord == 'backspace' thenlocal len = utf8.len(State.search_term)local byte_offset = Text.offset(State.search_term, len)State.search_term = string.sub(State.search_term, 1, byte_offset-1)elseif chord == 'down' thenState.cursor1.pos = State.cursor1.pos+1Text.search_next(State)elseif chord == 'up' thenText.search_previous(State)endreturnelseif chord == 'C-f' thenState.search_term = ''State.search_backup = {cursor={line=State.cursor1.line, pos=State.cursor1.pos},screen_top={line=State.screen_top1.line, pos=State.screen_top1.pos},}-- zoomelseif chord == 'C-=' thenedit.update_font_settings(State, State.font_height+2)Text.redraw_all(State)elseif chord == 'C--' thenif State.font_height > 2 thenedit.update_font_settings(State, State.font_height-2)Text.redraw_all(State)endelseif chord == 'C-0' thenedit.update_font_settings(State, 20)Text.redraw_all(State)-- undoelseif chord == 'C-z' thenlocal event = undo_event(State)if event thenlocal src = event.beforeState.screen_top1 = deepcopy(src.screen_top)State.cursor1 = deepcopy(src.cursor)State.selection1 = deepcopy(src.selection)patch(State.lines, event.after, event.before)patch_placeholders(State.line_cache, event.after, event.before)-- if we're scrolling, reclaim all fragments to avoid memory leaksText.redraw_all(State)schedule_save(State)endelseif chord == 'C-y' thenlocal event = redo_event(State)if event thenlocal src = event.afterState.screen_top1 = deepcopy(src.screen_top)State.cursor1 = deepcopy(src.cursor)State.selection1 = deepcopy(src.selection)patch(State.lines, event.before, event.after)-- if we're scrolling, reclaim all fragments to avoid memory leaksText.redraw_all(State)schedule_save(State)end-- clipboardelseif chord == 'C-a' thenState.selection1 = {line=1, pos=1}State.cursor1 = {line=#State.lines, pos=utf8.len(State.lines[#State.lines].data)+1}elseif chord == 'C-c' thenlocal s = Text.selection(State)if s thenApp.set_clipboard(s)endelseif chord == 'C-x' thenlocal s = Text.cut_selection(State, State.left, State.right)if s thenApp.set_clipboard(s)endschedule_save(State)elseif chord == 'C-v' then-- We don't have a good sense of when to scroll, so we'll be conservative-- and sometimes scroll when we didn't quite need to.local before_line = State.cursor1.linelocal before = snapshot(State, before_line)local clipboard_data = App.get_clipboard()for _,code in utf8.codes(clipboard_data) dolocal c = utf8.char(code)if c == '\n' thenText.insert_return(State)elseText.insert_at_cursor(State, c)endendif Text.cursor_out_of_screen(State) thenText.snap_cursor_to_bottom_of_screen(State, State.left, State.right)endschedule_save(State)record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)})-- dispatch to textelseText.keychord_press(State, chord)endendfunction edit.key_release(State, key, scancode)endfunction edit.update_font_settings(State, font_height)State.font_height = font_height
State.line_height = math.floor(font_height*1.3)end--== some methods for tests-- Insulate tests from some key globals so I don't have to change the vast-- majority of tests when they're modified for the real app.Test_margin_left = 25Test_margin_right = 0function edit.initialize_test_state()-- if you change these values, tests will start failingreturn edit.initialize_state(15, -- top marginTest_margin_left,App.screen.width - Test_margin_right,
15) -- line heightend-- all text_input events are also keypresses-- TODO: handle chords of multiple keysfunction edit.run_after_text_input(State, t)edit.keychord_press(State, t)edit.text_input(State, t)edit.key_release(State, t)App.screen.contents = {}edit.update(State, 0)edit.draw(State)end-- not all keys are text_input
App.screen.contents = {}edit.update(State, 0)edit.draw(State)endfunction edit.run_after_mouse_click(State, x,y, mouse_button)App.fake_mouse_press(x,y, mouse_button)edit.mouse_press(State, x,y, mouse_button)
App.fake_mouse_release(x,y, mouse_button)edit.mouse_release(State, x,y, mouse_button)App.screen.contents = {}edit.update(State, 0)edit.draw(State)endfunction edit.run_after_mouse_press(State, x,y, mouse_button)App.fake_mouse_press(x,y, mouse_button)edit.mouse_press(State, x,y, mouse_button)App.screen.contents = {}edit.update(State, 0)edit.draw(State)endfunction edit.run_after_mouse_release(State, x,y, mouse_button)App.fake_mouse_release(x,y, mouse_button)edit.mouse_release(State, x,y, mouse_button)App.screen.contents = {}edit.update(State, 0)edit.draw(State)end