Merge text.love
[?]
Jun 4, 2023, 10:25 PM
X43ZIKR3WHHUHTIBN76H25FLACL7SMKXXHFX7GDD552UF3V2UDPACDependencies
- [2]
O3WZWLYCMerge text.love - [3]
ZJFSVE47Merge text.love - [4]
IGBTDA6YMerge text.love - [5]
ONHKBLLCMerge lines.love - [6]
XX7G2FFJintermingle freehand line drawings with text - [7]
ECBDENZ4Merge text.love - [8]
3QNOKBFMbeginnings of a test harness - [9]
BJ5X5O4Alet's prevent the text cursor from ever getting on a drawing - [10]
JZR3QMTNMerge lines.love - [11]
EX43CDDIMerge text.love - [12]
2CFLXLIEMerge text.love - [13]
VXORMHMEdelete experimental REPL - [14]
LF7BWEG4group all editor globals - [15]
JCXL74WVbring back everything from commit a68647ae22 - [16]
QD4LOFQRMerge text.love - [17]
CE4LZV4Tdrop last couple of manual tests - [18]
FS2ITYYHrecord a known issue - [19]
6XCJX4DZbugfix: inscript's bug - [20]
BLWAYPKVextract a module - [21]
4YDBYBA4clean up memory leak experiments - [22]
LXTTOB33extract a couple of files - [23]
VP5KC4XZMerge lines.love - [24]
D76MS2G2Merge lines.love - [25]
D2GCFTTTclean up repl functionality - [26]
K2X6G75Zstart writing some tests for drawings - [27]
BULPIBEGbeginnings of a module for the text editor - [28]
D4B52CQ2Merge lines.love - [29]
2TQUKHBCMerge lines.love - [30]
VOU73AK6Merge lines.love - [31]
ZLJYLPOTMerge lines.love - [32]
36Z442IVback to commit 8123959e52f without code editing - [33]
N2NUGNN4include a brief reference enabling many useful apps - [34]
QF3HGULOMerge text.love - [35]
KKMFQDR4editing source code from within the app - [36]
UAYCSFSKMerge text.love - [37]
ORKN6EOBMerge lines.love - [38]
4U4VQWNYMerge lines.love - [39]
4HR3G5ZDMerge text.love - [40]
6LJZN727handle chords - [41]
3PSFWAILMerge lines.love - [42]
SGMA5JLEsave the list of tests in repo - [43]
REAIVN7WMerge lines.love - [44]
AVTNUQYRbasic test-enabled framework - [45]
TVCPXAAUrename - [46]
TLOAPLBJadd a license - [47]
JKENJ2UGMerge lines.love - [48]
Y5XAFGMWMerge text.love - [49]
OTIBCAUJlove2d scaffold - [50]
2344TV56Merge lines.love - [51]
3G723RV5Merge text.love - [52]
JDZVBFEIMerge lines.love - [53]
2L5MEZV3experiment: new edit namespace - [54]
Q6RXCILQMerge text.love - [55]
VBU5YHLRMerge lines.love - [56]
VHUNJHXBMerge lines.love - [57]
K74U4BAUMerge lines.love - [58]
RSZD5A7Gforgot to add json.lua - [59]
A4BSGS2CMerge lines.love - [60]
66X36NZNa little more prose describing manual_tests - [61]
DUHVCYW5Merge text.love - [62]
2CTN2IEFMerge lines.love - [63]
ZTZOO2OQMerge lines.love - [64]
OGUV4HSAremove some memory leaks from rendered fragments - [65]
C3GUE45IMerge text.love - [66]
LXFHXL2NMerge text.love - [67]
LNUHQOGHstart passing in Editor_state explicitly - [68]
MUJTM6REbring back a level of wrapping - [69]
T4FRZSYLdelete an ancient, unused file - [70]
73OCE2MCafter much struggle, a brute-force undo - [71]
KMSL74GAsupport selections in the source editor - [72]
YDUIKWSFMerge text.love - [73]
5SM6DRHKport inscript's bugfix to source editor - [74]
4SR3Z4Y3document the version of LÖVE I've been using - [75]
OI4FPFINsupport drawings in the source editor - [76]
MD3W5IRAnew fork: rip out drawing support - [77]
R5QXEHUIsomebody stop me - [78]
VHQCNMARseveral more modules - [79]
JOPVPUSAediting source code from within the app - [80]
PJ5PQAQErecord support for multiple versions
Change contents
- file deletion: source_select.lua source_select.lua
return State.screen_bottom1.line, Text.pos_at_end_of_screen_line(State, State.screen_bottom1)endfunction Text.cut_selection(State)if State.selection1.line == nil then return endlocal result = Text.selection(State)Text.delete_selection(State)return resultendfunction Text.delete_selection(State)if State.selection1.line == nil then return endlocal minl,maxl = minmax(State.selection1.line, State.cursor1.line)local before = snapshot(State, minl, maxl)Text.delete_selection_without_undo(State)record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)})endfunction Text.delete_selection_without_undo(State)if State.selection1.line == nil then return end-- min,max = sorted(State.selection1,State.cursor1)local minl,minp = State.selection1.line,State.selection1.poslocal maxl,maxp = State.cursor1.line,State.cursor1.posif minl > maxl thenminl,maxl = maxl,minlminp,maxp = maxp,minpelseif minl == maxl thenif minp > maxp thenminp,maxp = maxp,minpendend-- update State.cursor1 and State.selection1State.cursor1.line = minlState.cursor1.pos = minpif Text.lt1(State.cursor1, State.screen_top1) thenState.screen_top1.line = State.cursor1.lineState.screen_top1.pos = Text.pos_at_start_of_screen_line(State, State.cursor1)endState.selection1 = {}-- delete everything between min (inclusive) and max (exclusive)Text.clear_screen_line_cache(State, minl)local min_offset = Text.offset(State.lines[minl].data, minp)local max_offset = Text.offset(State.lines[maxl].data, maxp)if minl == maxl then--? print('minl == maxl')State.lines[minl].data = State.lines[minl].data:sub(1, min_offset-1)..State.lines[minl].data:sub(max_offset)returnendassert(minl < maxl)local rhs = State.lines[maxl].data:sub(max_offset)for i=maxl,minl+1,-1 dotable.remove(State.lines, i)table.remove(State.line_cache, i)endState.lines[minl].data = State.lines[minl].data:sub(1, min_offset-1)..rhsendfunction Text.selection(State)if State.selection1.line == nil then return end-- min,max = sorted(State.selection1,State.cursor1)local minl,minp = State.selection1.line,State.selection1.poslocal maxl,maxp = State.cursor1.line,State.cursor1.posif minl > maxl thenminl,maxl = maxl,minlminp,maxp = maxp,minpelseif minl == maxl thenif minp > maxp thenminp,maxp = maxp,minpendendlocal min_offset = Text.offset(State.lines[minl].data, minp)local max_offset = Text.offset(State.lines[maxl].data, maxp)if minl == maxl thenreturn State.lines[minl].data:sub(min_offset, max_offset-1)endassert(minl < maxl)local result = {State.lines[minl].data:sub(min_offset)}for i=minl+1,maxl-1 doif State.lines[i].mode == 'text' thentable.insert(result, State.lines[i].data)endendtable.insert(result, State.lines[maxl].data:sub(1, max_offset-1))return table.concat(result, '\n')endlocal 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.posend - file deletion: source_text_tests.lua source_text_tests.lua
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')endfunction 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')endfunction test_select_text_using_mouse_and_shift()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')end-- Arguably this should be called source_edit_tests.lua,-- but that would mess up the git blame at this point.function test_initial_state() - file deletion: source_text.lua source_text.lua
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)endfunction Text.cursor_at_final_screen_line(State)Text.populate_screen_line_starting_pos(State, State.cursor1.line)-- result: pos, index of screen linefunction Text.pos_at_start_of_screen_line(State, loc1)Text.populate_screen_line_starting_pos(State, loc1.line)local line_cache = State.line_cache[loc1.line]for i=#line_cache.screen_line_starting_pos,1,-1 dolocal spos = line_cache.screen_line_starting_pos[i]if spos <= loc1.pos thenreturn spos,i - file deletion: source_edit.lua source_edit.lua
--? 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))endendfunction edit.mouse_wheel_move(State, dx,dy)if dy > 0 thenState.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}for i=1,math.floor(dy) doText.up(State)endelseif dy < 0 thenState.cursor1 = {line=State.screen_bottom1.line, pos=State.screen_bottom1.pos}for i=1,math.floor(-dy) doText.down(State)end--? print_and_log(('edit.mouse_release: cursor now %d,%d'):format(State.cursor1.line, State.cursor1.pos))if State.mousepress_shift thenif State.old_selection1.line == nil thenState.selection1 = State.old_cursor1elseState.selection1 = State.old_selection1endendState.old_cursor1, State.old_selection1, State.mousepress_shift = nilif eq(State.cursor1, State.selection1) thenState.selection1 = {}endbreakendendend--? 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: no current drawing')for line_index,line in ipairs(State.lines) doif line.mode == 'text' thenif Text.in_line(State, line_index, x,y) then--? print_and_log(('edit.mouse_release: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))if State.lines.current_drawing then-- 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),}endreturnendreturnendelseif line.mode == 'drawing' thenlocal line_cache = State.line_cache[line_index]if Drawing.in_drawing(line, line_cache, x, y, State.left,State.right) thenState.lines.current_drawing_index = line_indexState.lines.current_drawing = lineDrawing.before = snapshot(State, line_index)--? 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()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) do--? print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))if mouse_press_consumed_by_any_button_handler(State, x,y, mouse_button) then-- press on a button and it returned 'true' to short-circuitreturnendState.screen_bottom1 = screen_bottom1if State.search_term thenText.draw_search_bar(State)endendfunction edit.update(State, dt)y, screen_bottom1.pos = Text.draw(State, line_index, y, startpos, hide_cursor)--? print('=> y', y)elseif line.mode == 'drawing' theny = y+Drawing_padding_topDrawing.draw(State, line_index, y)y = y + Drawing.pixels(line.h, State.width) + Drawing_padding_bottomelseprint(line.mode)assert(false)screen_bottom1.line = line_indexif line.mode == 'text' thenlocal screen_bottom1 = {line=nil, pos=nil}--? print('== draw')for line_index = State.screen_top1.line,#State.lines dolocal line = State.lines[line_index] - file deletion: source.lua source.lua
function print_and_log(s)print(s)log(3, s)endfunction source.load_settings()local settings = Settings.sourcelove.graphics.setFont(love.graphics.newFont(settings.font_height)) - file deletion: run.lua run.lua
function print_and_log(s)print(s)log(3, s)endfunction run.load_settings()love.graphics.setFont(love.graphics.newFont(Settings.font_height)) - edit in main.lua at line 81
function print_and_log(s)print(s)log(3, s)end - edit in edit.lua at line 115
State.screen_bottom1 = {line=line_index, pos=nil} - edit in edit.lua at line 124
--? print('screen bottom: '..tostring(State.screen_bottom1.pos)..' in '..tostring(State.lines[State.screen_bottom1.line].data))