Merge lines.love
[?]
Apr 2, 2023, 6:10 AM
OEIR7M74D747NZME7BK6YHKHNBIYLVE6HD7FZN2HITFF7MX4JLUACDependencies
- [2]
6K5PFF6Xhelper: trimming whitespace from strings - [3]
KGBSEDPFMerge lines.love - [4]
I64IPGJXavoid saving fragments in lines - [5]
ISOFHXB2App.width can no longer take a Text - [6]
Z4XRNDTRfind text - [7]
H4R5BHVYno more Text allocations - [8]
VG34LDWYexperiment: simple hyperlinks just to local files - [9]
X3F7ECSLadd state arg to some functions - [10]
S2QMLRXLstop creating a singleton table for every word - [11]
6WDBV52Zmove a var closer to its use - [12]
HALS7E5Umore clearly skip prints before screen top - [13]
WLHI7KD3new globals: draw partial screen line up top - [14]
DHI6IJCNselecting text and deleting selections - [15]
LERERVPHkeep one screen line of overlap on pagedown - [*]
BULPIBEGbeginnings of a module for the text editor - [*]
V5SYDHPQstart thinking of compute_fragments as a detail - [*]
PFT5Y2ZYmove - [*]
2CK5QI7Wmake love event names consistent - [*]
TGHAJBESuse line cache for drawings as well
Change contents
- edit in text.lua at line 15
Text.populate_link_offsets(State, line_index) - edit in text.lua at line 27
-- render fragment - resurrect zombie in text.lua at line 27
end - edit in text.lua at line 27
-- render any link decorationsfor _,link_offsets in ipairs(line_cache.link_offsets) dolocal s,e,filename = unpack(link_offsets)local lo, hi = Text.clip_filename_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()run.switch_to_file(filename)end,})end - replacement in text.lua at line 40[5.13]→[5.13:505](∅→∅),[5.13]→[5.13:505](∅→∅),[5.505]→[3.3:81](∅→∅),[3.81]→[5.580:591](∅→∅),[5.580]→[5.580:591](∅→∅),[5.580]→[5.580:591](∅→∅)
-- If fragment is a filename relative to the current directory, register-- a button for clicks on it.local filename = rtrim(frag) -- compute_fragments puts whitespace at the endif file_exists(filename) thenlocal filename_text = App.newText(love.graphics.getFont(), filename)button(State, 'link', {x=x,y=y, w=App.width(filename_text), h=State.line_height, color={1,1,1},icon = icon.hyperlink_decoration,onpress1 = function()run.switch_to_file(filename)end,})-- render fragment - edit in text.lua at line 127
endendfunction Text.populate_link_offsets(State, line_index)local line = State.lines[line_index]if line.mode ~= 'text' then return endlocal line_cache = State.line_cache[line_index]if line_cache.link_offsets thenreturnendline_cache.link_offsets = {}local pos = 1-- try to wrap at word boundarieslocal s, e = 1, 0while s <= #line.data dos, e = line.data:find('%w+', s)if s == nil then break endlocal word = line.data:sub(s, e)if file_exists(word) then--? print('filename:', s, e, word)table.insert(line_cache.link_offsets, {s, e, word})ends = e + 1 - edit in text.lua at line 153
-- 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_filename_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 thenreturnendendlocal loff = math.max(s, soff)local hoffif eoff thenhoff = math.min(e, eoff)elsehoff = eend--? print(s, e, soff, eoff, loff, hoff)return App.width(line.data:sub(1, loff-1)), App.width(line.data:sub(1, hoff))end - edit in text.lua at line 1023[21.1777][2.3]
State.line_cache[line_index].link_offsets = nil