Merge text.love
[?]
Apr 3, 2023, 4:28 PM
2CFLXLIERFBJDB6WXTNPKWRSJBAFYY2C4VRMWXFKGGA3DCJQIJWACDependencies
- [2]
OWPI7Y4QMerge text.love - [3]
5YXILO7XMerge text.love - [4]
QD4LOFQRMerge text.love - [5]
KWIVKQQ7Merge lines.love - [6]
R5QXEHUIsomebody stop me - [7]
BULPIBEGbeginnings of a module for the text editor - [8]
2L5MEZV3experiment: new edit namespace - [9]
MD3W5IRAnew fork: rip out drawing support - [10]
UN7GKYV5support hyperlinks in the source editor - [11]
EX43CDDIMerge text.love - [12]
ZTZOO2OQMerge lines.love - [13]
ZWDTEUH7clean up some absolute coordinates - [14]
4YDBYBA4clean up memory leak experiments - [15]
2CTN2IEFMerge lines.love - [16]
XX7G2FFJintermingle freehand line drawings with text - [17]
VHUNJHXBMerge lines.love - [18]
2TQUKHBCMerge lines.love - [19]
ZLJYLPOTMerge lines.love - [20]
Q6RXCILQMerge text.love - [21]
KKMFQDR4editing source code from within the app - [22]
3G723RV5Merge text.love - [23]
6LJZN727handle chords - [24]
K2X6G75Zstart writing some tests for drawings - [25]
T4FRZSYLdelete an ancient, unused file - [26]
VXORMHMEdelete experimental REPL - [27]
73OCE2MCafter much struggle, a brute-force undo - [28]
OGUV4HSAremove some memory leaks from rendered fragments - [29]
3PSFWAILMerge lines.love - [30]
D2GCFTTTclean up repl functionality - [31]
AVTNUQYRbasic test-enabled framework - [32]
JOPVPUSAediting source code from within the app - [33]
3QNOKBFMbeginnings of a test harness - [34]
D4B52CQ2Merge lines.love - [35]
A4BSGS2CMerge lines.love - [36]
LXTTOB33extract a couple of files - [37]
ECBDENZ4Merge text.love - [38]
66X36NZNa little more prose describing manual_tests - [39]
4SR3Z4Y3document the version of LÖVE I've been using - [40]
RSZD5A7Gforgot to add json.lua - [41]
TLOAPLBJadd a license - [42]
BJ5X5O4Alet's prevent the text cursor from ever getting on a drawing - [43]
BLWAYPKVextract a module - [44]
36Z442IVback to commit 8123959e52f without code editing - [45]
K74U4BAUMerge lines.love - [46]
FS2ITYYHrecord a known issue - [47]
TVCPXAAUrename - [48]
KMSL74GAsupport selections in the source editor - [49]
GZ5WULJVswitch source side to new screen-line-based render - [50]
OTIBCAUJlove2d scaffold - [51]
VP5KC4XZMerge lines.love - [52]
ORKN6EOBMerge lines.love - [53]
CE4LZV4Tdrop last couple of manual tests - [54]
UAYCSFSKMerge text.love - [55]
VHQCNMARseveral more modules
Change contents
- file deletion: icons.lua icons.lua
-- hack: set the hyperlink color so that caller can draw the text of the-- hyperlink in the same colorApp.color(Hyperlink_decoration_color)love.graphics.line(x,y+Editor_state.line_height, x+button_params.w,y+Editor_state.line_height) - file deletion: source_text_tests.lua source_text_tests.lua
App.screen.check(y, 'mn', 'screen:3')endfunction test_pagedown_never_moves_up() - file deletion: source_text.lua source_text.lua
State.line_cache[line_index].link_offsets = nilendfunction trim(s)return s:gsub('^%s+', ''):gsub('%s+$', '')endfunction ltrim(s)return s:gsub('^%s+', '')endfunction rtrim(s)return s:gsub('%s+$', '')edit.draw(State)return State.cursor_y == nil-- 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(s, e, soff, eoff, loff, hoff)return App.width(line.data:sub(1, loff-1)), App.width(line.data:sub(1, hoff))endendlocal loff = math.max(s, soff)local hoffif eoff thenhoff = math.min(e, eoff)elsehoff = eendlocal s, e = 1, 0while s <= #line.data dos, e = line.data:find('%[%[%S+%]%]', s)if s == nil then break endlocal word = line.data:sub(s+2, e-2) -- strip out surrounding '[[..]]'--? print('wikiword:', s, e, word)table.insert(line_cache.link_offsets, {s, e, word})s = e + 1endend-- Intersect the filename between byte offsets s,e with the bounds of screen line i.-- Return the left/right pixel coordinates of of the intersection,-- or nil if it doesn't intersect with screen line i.function Text.clip_wikiword_with_screen_line(line, line_cache, i, s, e)local spos = line_cache.screen_line_starting_pos[i]local soff = Text.offset(line.data, spos)if e < soff thenreturnendlocal eoffif i < #line_cache.screen_line_starting_pos thenlocal epos = line_cache.screen_line_starting_pos[i+1]eoff = Text.offset(line.data, epos)if s > eoff thenreturnendline_cache.link_offsets = {}local pos = 1-- try to wrap at word boundariesif line_cache.link_offsets thenreturnendfunction Text.populate_link_offsets(State, line_index)local line = State.lines[line_index]pos = pos + utf8.len(frag)endendx = 0 -- new screen lineendx = x + frag_width-- try to wrap at word boundariesfor frag in line.data:gmatch('%S*%s*') dolocal frag_width = App.width(frag)--? print('-- frag:', frag, pos, x, frag_width, State.width)while x + frag_width > State.width do--? print('frag:', frag, pos, x, frag_width, State.width)if x < 0.8 * State.width then-- long word; chop it at some letter-- We're not going to reimplement TeX here.local bpos = Text.nearest_pos_less_than(frag, State.width - x)-- everything works if bpos == 0, but is a little inefficientpos = pos + bposlocal boffset = Text.offset(frag, bpos+1) -- byte _after_ bposfrag = string.sub(frag, boffset)--? if bpos > 0 then--? print('after chop:', frag)--? endfrag_width = App.width(frag)end--? print('screen line:', pos)table.insert(line_cache.screen_line_starting_pos, pos)local x = 0local pos = 1local endpos = line_cache.screen_line_starting_pos[i+1]-1local end_offset = Text.offset(line.data, endpos)return line.data:sub(offset, end_offset)endfunction 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]return y, final_screen_line_starting_posendfunction 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)endy = y + State.line_heightif y >= App.screen.height thenbreakendendText.draw_cursor(State, State.left+Text.x(f, State.cursor1.pos-pos+1), y)endendendlove.graphics.print(State.search_term, State.left+lo_px,y)endelseif Focus == 'edit' thenlocal lo_px = Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term))App.color(Text_color)if not hide_cursor 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 thenselect_color(f)App.screen.print(f, State.left,y)-- render cursor if necessaryText.draw_highlight(State, line, State.left,y, pos, lo,hi)end-- render fragmentif State.selection1.line thenlocal lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)final_screen_line_starting_pos = poslocal f = Text.screen_line(line, line_cache, i)--? print('text.draw:', f, 'at', line_index,pos, 'after', x,y)local frag_len = utf8.len(f)-- render any link decorationsfor _,link_offsets in ipairs(line_cache.link_offsets) dolocal s,e,filename = unpack(link_offsets)local lo, hi = Text.clip_wikiword_with_screen_line(line, line_cache, i, s, e)if lo thenbutton(State, 'link', {x=State.left+lo, y=y, w=hi-lo, h=State.line_height, color={1,1,1},icon = icon.hyperlink_decoration,onpress1 = function()if file_exists(filename) thensource.switch_to_file(filename)endend,})endassert(#line_cache.screen_line_starting_pos >= 1)for i=1,#line_cache.screen_line_starting_pos dolocal pos = line_cache.screen_line_starting_pos[i]if pos < startpos then-- render nothingText.populate_link_offsets(State, line_index)initialize_color()local final_screen_line_starting_pos = startpos -- track value to returnText.populate_screen_line_starting_pos(State, line_index)-- return y for the next line, and position of start of final screen line drawnfunction Text.draw(State, line_index, y, startpos, hide_cursor) - file deletion: log_browser.lua log_browser.lua
Text.draw(State, line_index, y, --[[startpos]] 1)State.left,State.right = old_left,old_rightelseheight = log_render[line.data.name](line.data, xleft, y, xright-xleft)endendif App.mouse_x() > Log_browser_state.left and line_index == mouse_line_index thenApp.color(Cursor_line_background_color)love.graphics.rectangle('fill', xleft,y, xright-xleft, height)endy = y + heightendendendfunction render_stack_left_margin(State, line_index, line, y)if line.section_stack == nil then-- assertion messagefor k,v in pairs(line) doprint(k)endendApp.color(Section_border_color)for i=1,#line.section_stack dolocal x = State.left + (i-1)*Section_border_padding_horizontallove.graphics.line(x,y, x,y+log_browser.height(State, line_index))if y < 30 thenlove.graphics.print(line.section_stack[i].name, x+State.font_height+5, y+5, --[[vertically]] math.pi/2)endif y > App.screen.height-log_browser.height(State, line_index) then