port inscript's bugfix to source editor
[?]
Jun 4, 2023, 7:33 PM
5SM6DRHKPLFWQPCZDTVM4ENVENWBYBQ3Q2KYKSWLWYUTOSEPCRLACDependencies
- [2]
KYNGDE2Cconsistent names in a few more places - [3]
LIKTH6HMupdate stale source X-( - [4]
7FPELAZBah, I see the problem - [5]
GFXWHTE6mouse wheel support - [6]
KKMFQDR4editing source code from within the app - [7]
B4JEWKWIhide editor cursor while in file navigator - [8]
OI4FPFINsupport drawings in the source editor - [9]
QJISOCHJsome temporary logging to catch a bug - [10]
G54H3YG2get rid of all bifold text - [11]
2L5MEZV3experiment: new edit namespace - [12]
LDFXFRUObring a few things in sync between run and source - [13]
GZ5WULJVswitch source side to new screen-line-based render - [14]
ISOFHXB2App.width can no longer take a Text - [15]
KMSL74GAsupport selections in the source editor - [16]
LNUHQOGHstart passing in Editor_state explicitly - [17]
2CK5QI7Wmake love event names consistent - [*]
ORRSP7FVdeduce test names on failures
Change contents
- edit in source_text_tests.lua at line 2
-- Arguably this should be called source_edit_tests.lua,-- but that would mess up the git blame at this point. - edit in source_text_tests.lua at line 831[19.30265][5.9170]
endfunction test_select_text_using_mouse_starting_above_text()App.screen.init{width=50, height=60}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{'abc', 'def', 'xyz'}Text.redraw_all(Editor_state)Editor_state.cursor1 = {line=1, pos=1}Editor_state.screen_top1 = {line=1, pos=1}Editor_state.screen_bottom1 = {}Editor_state.selection1 = {}edit.draw(Editor_state) -- populate line_cache.starty for each line Editor_state.line_cache-- press mouse above first line of textedit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')check_eq(Editor_state.selection1.line, 1, 'selection:line')check_eq(Editor_state.selection1.pos, 1, 'selection:pos') - edit in source_text_tests.lua at line 850
function test_select_text_using_mouse_starting_above_text_wrapping_line()-- first screen line starts in the middle of a lineApp.screen.init{width=50, height=60}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{'abc', 'defgh', 'xyz'}Text.redraw_all(Editor_state)Editor_state.cursor1 = {line=2, pos=5}Editor_state.screen_top1 = {line=2, pos=3}Editor_state.screen_bottom1 = {}-- press mouse above first line of textedit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)-- selection is at screen topcheck(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')check_eq(Editor_state.selection1.line, 2, 'selection:line')check_eq(Editor_state.selection1.pos, 3, 'selection:pos')endfunction test_select_text_using_mouse_starting_below_text()-- I'd like to test what happens when a mouse click is below some page of-- text, potentially even in the middle of a line.-- However, it's brittle to set up a text line boundary just right.-- So I'm going to just check things below the bottom of the final line of-- text when it's in the middle of the screen.-- final screen line ends in the middle of screenApp.screen.init{width=50, height=60}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{'abcde'}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, 'ab', 'baseline:screen:1')y = y + Editor_state.line_heightApp.screen.check(y, 'cde', 'baseline:screen:2')-- press mouse above first line of textedit.run_after_mouse_press(Editor_state, 5,App.screen.height-5, 1)-- selection is past bottom-most text in screencheck(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')check_eq(Editor_state.selection1.line, 1, 'selection:line')check_eq(Editor_state.selection1.pos, 6, 'selection:pos')end - edit in source_text_tests.lua at line 946[19.30731][5.33133]
endfunction test_select_all_text()-- display a single line of textApp.screen.init{width=75, height=80}Editor_state = edit.initialize_test_state()Editor_state.lines = load_array{'abc def'}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)-- select allApp.fake_key_press('lctrl')edit.run_after_keychord(Editor_state, 'C-a')App.fake_key_release('lctrl')edit.key_release(Editor_state, 'lctrl')-- selectioncheck_eq(Editor_state.selection1.line, 1, 'selection:line')check_eq(Editor_state.selection1.pos, 1, 'selection:pos')check_eq(Editor_state.cursor1.line, 1, 'cursor:line')check_eq(Editor_state.cursor1.pos, 8, 'cursor:pos') - edit in source_text.lua at line 653
-- result: pos, index of screen line - edit in source_text.lua at line 666
function Text.pos_at_end_of_screen_line(State, loc1)Text.populate_screen_line_starting_pos(State, loc1.line)local line_cache = State.line_cache[loc1.line]local most_recent_final_pos = utf8.len(State.lines[loc1.line].data)+1for i=#line_cache.screen_line_starting_pos,1,-1 dolocal spos = line_cache.screen_line_starting_pos[i]if spos <= loc1.pos thenreturn most_recent_final_posendmost_recent_final_pos = spos-1endassert(false)end - edit in source_select.lua at line 2
-- To keep things simple, we'll ignore the B side when selections start on the-- A side, and stick to within a single B side selections start in. - edit in source_select.lua at line 32
--? print(minl,line_index,maxl, '--', minp,apos,bpos,maxp, '--', a_ge,b_lt) - edit in source_select.lua at line 62
--? print(lo,pos,hi, '--', lo_offset,pos_offset,hi_offset, '--', lo_px) - edit in source_select.lua at line 70
-- inefficient for some reason, so don't do it on every frame - replacement in source_select.lua at line 71
local time = love.timer.getTime()if State.recent_mouse.time and State.recent_mouse.time > time-0.1 thenreturn State.recent_mouse.line, State.recent_mouse.posendState.recent_mouse.time = timelocal line,pos = Text.to_pos(State, App.mouse_x(), App.mouse_y())if line thenState.recent_mouse.line = lineState.recent_mouse.pos = poslocal x,y = App.mouse_x(), App.mouse_y()if y < State.line_cache[State.screen_top1.line].starty thenreturn State.screen_top1.line, State.screen_top1.pos - edit in source_select.lua at line 75
return State.recent_mouse.line, State.recent_mouse.posendfunction Text.to_pos(State, x,y) - edit in source_select.lua at line 82
return State.screen_bottom1.line, Text.pos_at_end_of_screen_line(State, State.screen_bottom1) - edit in source_edit.lua at line 79
-- when selecting text, avoid recomputing some state on every single framerecent_mouse = {}, - edit in source_edit.lua at line 156
local screen_bottom1 = {line=nil, pos=nil} - replacement in source_edit.lua at line 162
State.screen_bottom1 = {line=line_index, pos=nil}screen_bottom1.line = line_index - replacement in source_edit.lua at line 185
y, State.screen_bottom1.pos = Text.draw(State, line_index, y, startpos, hide_cursor)y, screen_bottom1.pos = Text.draw(State, line_index, y, startpos, hide_cursor) - edit in source_edit.lua at line 196
State.screen_bottom1 = screen_bottom1 - replacement in source_edit.lua at line 227
--? print('press', State.cursor1.line)--? print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos)) - edit in source_edit.lua at line 233
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,}returnend - edit in source_edit.lua at line 256
--? print_and_log(('edit.mouse_press: in line %d'):format(line_index)) - replacement in source_edit.lua at line 264[5.6941]→[5.6941:7017](∅→∅),[5.7017]→[5.21843:21857](∅→∅),[5.31203]→[5.21843:21857](∅→∅),[5.21843]→[5.21843:21857](∅→∅)
--? print('selection', State.selection1.line, State.selection1.pos)breakreturn - replacement in source_edit.lua at line 273
breakreturn - edit in source_edit.lua at line 277
-- still here? click is below all screen linesState.old_cursor1 = State.cursor1State.old_selection1 = State.selection1State.mousepress_shift = App.shift_down()State.selection1 = {line=State.screen_bottom1.line,pos=Text.pos_at_end_of_screen_line(State, State.screen_bottom1),} - replacement in source_edit.lua at line 290
--? print('release', State.cursor1.line)--? print_and_log(('edit.mouse_release: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos)) - edit in source_edit.lua at line 299
--? print_and_log('edit.mouse_release: no current drawing') - replacement in source_edit.lua at line 303
--? print('reset selection')--? print_and_log(('edit.mouse_release: in line %d'):format(line_index)) - replacement in source_edit.lua at line 308
--? print('cursor', State.cursor1.line, State.cursor1.pos)--? print_and_log(('edit.mouse_release: cursor now %d,%d'):format(State.cursor1.line, State.cursor1.pos)) - replacement in source_edit.lua at line 324
--? print('selection:', State.selection1.line, State.selection1.pos)--? print_and_log(('edit.mouse_release: finally selection %s,%s cursor %d,%d'):format(tostring(State.selection1.line), tostring(State.selection1.pos), State.cursor1.line, State.cursor1.pos)) - edit in source.lua at line 116
function print_and_log(s)print(s)log(3, s)end - replacement in edit.lua at line 255
print_and_log(('edit.mouse_press: in line %d'):format(line_index))--? print_and_log(('edit.mouse_press: in line %d'):format(line_index))