Merge lines.love
[?]
Sep 5, 2022, 9:19 PM
VHUNJHXB4BQISKAXTMVB66C4QKF2NUZQRPRB37Z7OADC7PW5IMRACDependencies
- [2]
3PSFWAILMerge lines.love - [3]
UN7GKYV5support hyperlinks in the source editor - [4]
BJ5X5O4Alet's prevent the text cursor from ever getting on a drawing - [5]
XX7G2FFJintermingle freehand line drawings with text - [6]
T4FRZSYLdelete an ancient, unused file - [7]
2CTN2IEFMerge lines.love - [8]
6LJZN727handle chords - [9]
BULPIBEGbeginnings of a module for the text editor - [10]
GUOQRUL7Merge lines.love - [11]
K2X6G75Zstart writing some tests for drawings - [12]
D2GCFTTTclean up repl functionality - [13]
VXORMHMEdelete experimental REPL - [14]
AVTNUQYRbasic test-enabled framework - [15]
TLOAPLBJadd a license - [16]
4KC7I3E2make colors easier to edit - [17]
OI4FPFINsupport drawings in the source editor - [18]
RSZD5A7Gforgot to add json.lua - [19]
32V6ZHQBMerge lines.love - [20]
3QNOKBFMbeginnings of a test harness - [21]
66X36NZNa little more prose describing manual_tests - [22]
OTIBCAUJlove2d scaffold - [23]
VHQCNMARseveral more modules - [24]
LXTTOB33extract a couple of files - [25]
KKMFQDR4editing source code from within the app - [26]
TVCPXAAUrename - [27]
R5QXEHUIsomebody stop me - [28]
FS2ITYYHrecord a known issue - [29]
BLWAYPKVextract a module - [30]
MD3W5IRAnew fork: rip out drawing support - [31]
2L5MEZV3experiment: new edit namespace - [32]
73OCE2MCafter much struggle, a brute-force undo - [33]
OGUV4HSAremove some memory leaks from rendered fragments - [34]
QS3YLNKZMerge lines.love - [35]
CE4LZV4Tdrop last couple of manual tests - [36]
4YDBYBA4clean up memory leak experiments - [37]
JOPVPUSAediting source code from within the app
Change contents
- file deletion: icons.lua
icon = {}function icon.insert_drawing(button_params)local x,y = button_params.x, button_params.yApp.color(Icon_color)love.graphics.rectangle('line', x,y, 12,12)love.graphics.line(4,y+6, 16,y+6)love.graphics.line(10,y, 10,y+12)endfunction icon.freehand(x, y)love.graphics.line(x+4,y+7,x+5,y+5)love.graphics.line(x+5,y+5,x+7,y+4)love.graphics.line(x+7,y+4,x+9,y+3)love.graphics.line(x+9,y+3,x+10,y+5)love.graphics.line(x+10,y+5,x+12,y+6)love.graphics.line(x+12,y+6,x+13,y+8)love.graphics.line(x+13,y+8,x+13,y+10)love.graphics.line(x+13,y+10,x+14,y+12)love.graphics.line(x+14,y+12,x+15,y+14)love.graphics.line(x+15,y+14,x+15,y+16)endfunction icon.line(x, y)love.graphics.line(x+4,y+2, x+16,y+18)endfunction icon.manhattan(x, y)love.graphics.line(x+4,y+20, x+4,y+2)love.graphics.line(x+4,y+2, x+10,y+2)love.graphics.line(x+10,y+2, x+10,y+10)love.graphics.line(x+10,y+10, x+18,y+10)endfunction icon.polygon(x, y)love.graphics.line(x+8,y+2, x+14,y+2)love.graphics.line(x+14,y+2, x+18,y+10)love.graphics.line(x+18,y+10, x+10,y+18)love.graphics.line(x+10,y+18, x+4,y+12)love.graphics.line(x+4,y+12, x+8,y+2)endfunction icon.rectangle(x, y)love.graphics.line(x+4,y+8, x+4,y+16)love.graphics.line(x+4,y+16, x+16,y+16)love.graphics.line(x+16,y+16, x+16,y+8)love.graphics.line(x+16,y+8, x+4,y+8)endfunction icon.square(x, y)love.graphics.line(x+6,y+6, x+6,y+16)love.graphics.line(x+6,y+16, x+16,y+16)love.graphics.line(x+16,y+16, x+16,y+6)love.graphics.line(x+16,y+6, x+6,y+6)endfunction icon.circle(x, y)love.graphics.circle('line', x+10,y+10, 8)end - file deletion: source_text.lua source_text.lua
endfunction starts_with(s, sub)return s:find(sub, 1, --[[no escapes]] true) == 1endfunction ends_with(s, sub)return s:reverse():find(sub:reverse(), 1, --[[no escapes]] true) == 1endState.link_cache = {}endfunction Text.clear_screen_line_cache(State, line_index)State.line_cache[line_index].fragments = nilState.line_cache[line_index].fragmentsB = nilState.line_cache[line_index].screen_line_starting_pos = nilState.line_cache[line_index].screen_line_starting_posB = nilendfunction trim(s)return s:gsub('^%s+', ''):gsub('%s+$', '')endfunction ltrim(s)return s:gsub('^%s+', '')endfunction rtrim(s)return s:gsub('%s+$', '')function source.link_exists(State, filename)if State.link_cache == nil thenState.link_cache = {}endif State.link_cache[filename] == nil thenState.link_cache[filename] = file_exists(filename)endreturn State.link_cache[filename]endfunction Text.redraw_all(State)--? print('clearing fragments')State.line_cache = {}for i=1,#State.lines doState.line_cache[i] = {}end-- Make [[WikiWords]] (single word, all in one screen line) clickable.local trimmed_word = rtrim(frag) -- compute_fragments puts whitespace at the endif starts_with(trimmed_word, '[[') and ends_with(trimmed_word, ']]') thenlocal filename = trimmed_word:gsub('^..(.*)..$', '%1')if source.link_exists(State, filename) thenlocal filename_text = App.newText(love.graphics.getFont(), filename)button(State, 'link', {x=x+App.width(to_text('[[')), y=y, w=App.width(filename_text), h=State.line_height, color={1,1,1},icon = icon.hyperlink_decoration,onpress1 = function()source.switch_to_file(filename)end,})endendApp.screen.draw(frag_text, x,y)-- render cursor if necessaryif State.cursor1.pos and line_index == State.cursor1.line thenif pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos thenif State.search_term thenif State.lines[State.cursor1.line].data:sub(State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)-1) == State.search_term thenlocal lo_px = Text.draw_highlight(State, line, x,y, pos, State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term))App.color(Text_color)love.graphics.print(State.search_term, x+lo_px,y)endelseif Focus == 'edit' thenText.draw_cursor(State, x+Text.x(frag, State.cursor1.pos-pos+1), y)App.color(Text_color)endendendx = x + frag_widthendpos = pos + frag_lenendreturn false, x,y, pos, screen_line_starting_posendfunction Text.draw_wrapping_lineB(State, line_index, x,y, startpos)local line = State.lines[line_index]local line_cache = State.line_cache[line_index]local screen_line_starting_pos = startposText.compute_fragmentsB(State, line_index, x)local pos = 1for _, f in ipairs(line_cache.fragmentsB) dolocal frag, frag_text = f.data, f.textlocal frag_len = utf8.len(frag)--? print('text.draw:', frag, 'at', line_index,pos, 'after', x,y)if pos < startpos then-- render nothing--? print('skipping', frag)else-- render fragmentlocal frag_width = App.width(frag_text)if x + frag_width > State.right thenassert(x > State.left) -- no overfull linesy = y + State.line_heightif y + State.line_height > App.screen.height thenreturn --[[screen filled]] true, x,y, pos, screen_line_starting_posendscreen_line_starting_pos = posx = State.leftendApp.screen.draw(frag_text, x,y)-- render cursor if necessaryif State.cursor1.posB and line_index == State.cursor1.line thenif pos <= State.cursor1.posB and pos + frag_len > State.cursor1.posB thenif State.search_term thenif State.lines[State.cursor1.line].dataB:sub(State.cursor1.posB, State.cursor1.posB+utf8.len(State.search_term)-1) == State.search_term thenlocal lo_px = Text.draw_highlight(State, line, x,y, pos, State.cursor1.posB, State.cursor1.posB+utf8.len(State.search_term))App.color(Fold_color)love.graphics.print(State.search_term, x+lo_px,y)endelseif Focus == 'edit' thenText.draw_cursor(State, x+Text.x(frag, State.cursor1.posB-pos+1), y)App.color(Fold_color)endendendx = x + frag_widthendpos = pos + frag_lenendreturn false, x,y, pos, screen_line_starting_posendfunction Text.draw_cursor(State, x, y)-- blink every 0.5sif math.floor(Cursor_time*2)%2 == 0 thenApp.color(Cursor_color)love.graphics.rectangle('fill', x,y, 3,State.line_height)endState.cursor_x = xState.cursor_y = y+State.line_heightendfunction Text.populate_screen_line_starting_pos(State, line_index)local line = State.lines[line_index] - file deletion: source_edit.lua source_edit.lua
Hyperlink_decoration_color = {r=0.4, g=0.4, b=1}Stroke_color = {r=0, g=0, b=0}Current_stroke_color = {r=0.7, g=0.7, b=0.7} -- in process of being drawnCurrent_name_background_color = {r=1, g=0, b=0, a=0.1} -- name currently being edited - edit in source_text.lua at line 113
-- Make [[WikiWords]] (single word, all in one screen line) clickable.local trimmed_word = rtrim(frag) -- compute_fragments puts whitespace at the endif starts_with(trimmed_word, '[[') and ends_with(trimmed_word, ']]') thenlocal filename = trimmed_word:gsub('^..(.*)..$', '%1')if source.link_exists(State, filename) thenlocal filename_text = App.newText(love.graphics.getFont(), filename)button(State, 'link', {x=x+App.width(to_text('[[')), y=y, w=App.width(filename_text), h=State.line_height, color={1,1,1},icon = icon.hyperlink_decoration,onpress1 = function()source.switch_to_file(filename)end,})endend - edit in source_text.lua at line 1627
function source.link_exists(State, filename)if State.link_cache == nil thenState.link_cache = {}endif State.link_cache[filename] == nil thenState.link_cache[filename] = file_exists(filename)endreturn State.link_cache[filename]end - edit in source_text.lua at line 1643
State.link_cache = {} - edit in source_text.lua at line 1663
endfunction starts_with(s, sub)return s:find(sub, 1, --[[no escapes]] true) == 1endfunction ends_with(s, sub)return s:reverse():find(sub:reverse(), 1, --[[no escapes]] true) == 1 - edit in source_edit.lua at line 4
Hyperlink_decoration_color = {r=0.4, g=0.4, b=1} - file un-deletion: icons.lua icons.lua
- resurrect zombie in icons.lua at line 1
endfunction icon.hyperlink_decoration(button_params)local x,y = button_params.x, button_params.yApp.color(Hyperlink_decoration_color)love.graphics.line(x,y+Editor_state.line_height, x+button_params.w,y+Editor_state.line_height) - edit in icons.lua at line 1
icon = {}function icon.insert_drawing(button_params)local x,y = button_params.x, button_params.yApp.color(Icon_color)love.graphics.rectangle('line', x,y, 12,12)love.graphics.line(4,y+6, 16,y+6)love.graphics.line(10,y, 10,y+12) - edit in icons.lua at line 15[3.1557]
endfunction icon.freehand(x, y)love.graphics.line(x+4,y+7,x+5,y+5)love.graphics.line(x+5,y+5,x+7,y+4)love.graphics.line(x+7,y+4,x+9,y+3)love.graphics.line(x+9,y+3,x+10,y+5)love.graphics.line(x+10,y+5,x+12,y+6)love.graphics.line(x+12,y+6,x+13,y+8)love.graphics.line(x+13,y+8,x+13,y+10)love.graphics.line(x+13,y+10,x+14,y+12)love.graphics.line(x+14,y+12,x+15,y+14)love.graphics.line(x+15,y+14,x+15,y+16)endfunction icon.line(x, y)love.graphics.line(x+4,y+2, x+16,y+18)endfunction icon.manhattan(x, y)love.graphics.line(x+4,y+20, x+4,y+2)love.graphics.line(x+4,y+2, x+10,y+2)love.graphics.line(x+10,y+2, x+10,y+10)love.graphics.line(x+10,y+10, x+18,y+10)endfunction icon.polygon(x, y)love.graphics.line(x+8,y+2, x+14,y+2)love.graphics.line(x+14,y+2, x+18,y+10)love.graphics.line(x+18,y+10, x+10,y+18)love.graphics.line(x+10,y+18, x+4,y+12)love.graphics.line(x+4,y+12, x+8,y+2)endfunction icon.rectangle(x, y)love.graphics.line(x+4,y+8, x+4,y+16)love.graphics.line(x+4,y+16, x+16,y+16)love.graphics.line(x+16,y+16, x+16,y+8)love.graphics.line(x+16,y+8, x+4,y+8)endfunction icon.square(x, y)love.graphics.line(x+6,y+6, x+6,y+16)love.graphics.line(x+6,y+16, x+16,y+16)love.graphics.line(x+16,y+16, x+16,y+6)love.graphics.line(x+16,y+6, x+6,y+6)endfunction icon.circle(x, y)love.graphics.circle('line', x+10,y+10, 8)end