avoid saving fragments in lines
[?]
Apr 2, 2023, 3:03 AM
I64IPGJXWRTGHHVAYJUBUIWFR4BY6NM5P7TLTV4JOD7K4BVYDECQCDependencies
- [2]
4EGQRXDAbugfix: naming points - [3]
S2QMLRXLstop creating a singleton table for every word - [4]
V5SYDHPQstart thinking of compute_fragments as a detail - [5]
LWPRYDLWset color for each fragment - [6]
H4R5BHVYno more Text allocations - [7]
FBVUNLS4clean up some debug prints - [8]
3TFEAQSWstart using some globals - [9]
PR4KIAZDfirst stab at equally hacky cursor down support - [10]
FZBXBUFFbugfix: search - [11]
X3F7ECSLadd state arg to some functions - [12]
XUGDTYW2stop confusingly reading a global - [13]
TXHMMX25move caching behavior inside compute_fragments - [14]
6WDBV52Zmove a var closer to its use - [15]
HALS7E5Umore clearly skip prints before screen top - [16]
JY4VK7L2rename - [17]
ISOFHXB2App.width can no longer take a Text - [18]
PLKNHYZ4extract a function - [19]
ESETRNLBbugfix: printing the first part of a line at the bottom made it seem non-wrapping - [20]
LF7BWEG4group all editor globals - [21]
BULPIBEGbeginnings of a module for the text editor - [22]
XNFTJHC4split keyboard handling between Text and Drawing - [23]
A2NV3WVOscrolling with up arrow - [24]
CAMMFOJ4make cursor more obvious - [25]
ZDAJXYIXremove some unnecessary work - [26]
KWOJ6XHEcut/copy selected text to clipboard - [27]
PFT5Y2ZYmove - [28]
MYC7XR5Qbugfix: lines that aren't drawn from the start - [29]
AYE2VEGJextract a couple of methods - [30]
LXTTOB33extract a couple of files - [31]
Z4XRNDTRfind text - [32]
S2MISTTMadd state arg to a few functions - [33]
73OCE2MCafter much struggle, a brute-force undo - [34]
LAW2O3NWextract variable Margin_left - [35]
HOSPP2ANcrisp font rendering - [36]
QYIFOHW3first test! - [37]
CBPV5SSIstop handling nil screen_line_starting_pos everywhere - [38]
2H67P75Xswitch arg for a function - [39]
KJKKASHZreduce ambitions a bit: page up/down need not start screen from the middle of a line - [40]
YTSPVDZHfirst successful pagedown test, first bug found by test - [41]
AVTNUQYRbasic test-enabled framework - [42]
OIB2QPRCstart remembering where the cursor is drawn in px - [43]
R53OF3ONone bug I've repeatedly run into while testing with Moby Dick - [44]
J2SVGR2Eexperiment: blinking cursor - [45]
JJMTEZPQobsolete comment - [46]
DHI6IJCNselecting text and deleting selections - [47]
5DOC2CBMextract a function - [48]
WLHI7KD3new globals: draw partial screen line up top - [49]
B3IWYWSRdelete another arg that can be deduced - [50]
RTDYYP4Hbugfix: text past cursor was rendered red on wrapped lines - [51]
H2DPLWMVsnapshot: wrapping long lines at word boundaries - [52]
HIKLULFQextract a function - [53]
5DOTWNVMright margin - [54]
NDHQN23Gdone passing left/right margins everywhere - [55]
UHB4GARJleft/right margin -> left/right coordinates - [56]
3ZSUBI57drop some redundant args from Text.draw - [57]
MDXGMZU2disable all debug prints - [58]
PESSMQBJno, make sure to compute line width after screen dimensions - [59]
EHX6Q4OJmake the cursor a little thicker - [60]
LSYLEVBDdrop some redundant args when clearing the cache - [61]
ODLKHO7Bswitch to line index in a function - [62]
KURLAXXIclean up some prints - [63]
3OC7AIC7exclude left margin from my word-split heuristic - [64]
TGHAJBESuse line cache for drawings as well - [65]
Y4SPXCM3bugfix: pagedown was sometimes bouncing up - [66]
UV4EWOLYadd args to some functions - [67]
CVSRHMJ2experiment: slightly adaptive scrolling - [68]
XVR2O5PIchange text cursor shape - [69]
BW2IUB3Kkeep all text cache writes inside text.lua - [70]
HVJKBW5Udrop some unnecessary calls - [71]
OYVFFWBKmove - [72]
OI4FPFINsupport drawings in the source editor - [73]
ORRSP7FVdeduce test names on failures - [74]
LERERVPHkeep one screen line of overlap on pagedown - [75]
6K5PFF6Xhelper: trimming whitespace from strings - [76]
BYG5CEMVsupport for naming points - [77]
MXA3RZYKdeduce left/right from state where possible - [78]
4KC7I3E2make colors easier to edit - [79]
MGT5FTJ3first stab at supporting wrapping in cursor up - [80]
Y36LOGR5bugfix: show cursor when past end of line - [81]
EWMPYCDObugfix - [82]
ULKLJBN6couple of renames - [83]
ILOA5BYFseparate data structure for each line's cache data - [84]
IMEJA43Lsnapshot - [85]
2RXZ3PGObeginning of a new approach to scroll+wrap - [86]
HGC5RGJPswitch to line index in a function - [87]
537TQ2QNsome more logging - [88]
VVAGDVCUexperiment: line cursor - [89]
CVGE3SIGI feel confident now that page-down is working. - [90]
BZRRUIFQcorrect location of the line width slider - [91]
UPCIYZEUdrop an unnecessary level of indent - [92]
M6TH7VSZrip out notion of Line_width - [93]
JLU2RMC4allow Text.nearest_pos_less_than to return 0 - [94]
GK47BBCYstart passing left/right margins everywhere - [95]
OYXDYPGSget rid of debug variables - [*]
R5OKMVVCfix a regression in line wrapping - [*]
3QNOKBFMbeginnings of a test harness
Change contents
- replacement in text_tests.lua at line 1010
App.screen.check(y, 'mno ', 'screen:3')App.screen.check(y, 'mn', 'screen:3') - edit in text.lua at line 7
--? print('text.draw', line_index, y) - replacement in text.lua at line 13[5.1768]→[5.53:76](∅→∅),[5.92]→[5.1802:1818](∅→∅),[5.106]→[5.1802:1818](∅→∅),[5.1013]→[5.1802:1818](∅→∅),[5.1802]→[5.1802:1818](∅→∅),[5.1818]→[5.3:47](∅→∅)
local x = State.leftlocal pos = 1local screen_line_starting_pos = startposlocal final_screen_line_starting_pos = startpos -- track value to return - replacement in text.lua at line 15[5.47]→[5.3860:3906](∅→∅),[4.63]→[5.3860:3906](∅→∅),[5.93]→[5.3860:3906](∅→∅),[5.19]→[5.3860:3906](∅→∅),[5.3906]→[5.3:29](∅→∅),[5.29]→[3.3:103](∅→∅)
for _, f in ipairs(line_cache.fragments) doApp.color(Text_color)local frag_len = utf8.len(f)--? print('text.draw:', f, 'at', line_index,pos, 'after', x,y)assert(#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] - edit in text.lua at line 22
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) - edit in text.lua at line 27[5.28]→[3.136:174](∅→∅),[5.46]→[5.138:234](∅→∅),[5.74]→[5.138:234](∅→∅),[3.174]→[5.138:234](∅→∅),[5.138]→[5.138:234](∅→∅),[5.234]→[5.405:497](∅→∅),[5.405]→[5.405:497](∅→∅),[5.499]→[5.499:556](∅→∅),[5.104]→[5.255:294](∅→∅),[5.108]→[5.255:294](∅→∅),[5.272]→[5.255:294](∅→∅),[5.556]→[5.255:294](∅→∅),[5.255]→[5.255:294](∅→∅),[5.648]→[5.235:258](∅→∅),[5.110]→[5.119:129](∅→∅),[5.127]→[5.119:129](∅→∅),[5.258]→[5.119:129](∅→∅),[5.266]→[5.119:129](∅→∅),[5.119]→[5.119:129](∅→∅)
local frag_width = App.width(f)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 y, screen_line_starting_posendscreen_line_starting_pos = posx = State.leftend - replacement in text.lua at line 29
Text.draw_highlight(State, line, x,y, pos, lo,hi)Text.draw_highlight(State, line, State.left,y, pos, lo,hi) - replacement in text.lua at line 31
App.screen.print(f, x,y)App.color(Text_color)App.screen.print(f, State.left,y) - replacement in text.lua at line 35
if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos thenif pos <= State.cursor1.pos and pos + frag_len >= State.cursor1.pos then - replacement in text.lua at line 38
local lo_px = Text.draw_highlight(State, line, x,y, pos, State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term))local lo_px = Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)) - replacement in text.lua at line 40
love.graphics.print(State.search_term, x+lo_px,y)love.graphics.print(State.search_term, State.left+lo_px,y) - replacement in text.lua at line 43
Text.draw_cursor(State, x+Text.x(f, State.cursor1.pos-pos+1), y)Text.draw_cursor(State, State.left+Text.x(f, State.cursor1.pos-pos+1), y) - replacement in text.lua at line 47
x = x + frag_widthy = y + State.line_heightif y >= App.screen.height thenbreakend - edit in text.lua at line 52
pos = pos + frag_len - replacement in text.lua at line 53
if State.search_term == nil thenif line_index == State.cursor1.line and State.cursor1.pos == pos thenText.draw_cursor(State, x, y)endreturn y - State.line_height, 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) - replacement in text.lua at line 62
return y, screen_line_starting_poslocal endpos = line_cache.screen_line_starting_pos[i+1]-1local end_offset = Text.offset(line.data, endpos)return line.data:sub(offset, end_offset) - edit in text.lua at line 85
-- duplicate some logic from Text.drawText.compute_fragments(State, line_index) - replacement in text.lua at line 86
local x = State.leftlocal x = 0 - edit in text.lua at line 88[5.482]→[5.482:528](∅→∅),[5.571]→[5.571:594](∅→∅),[5.594]→[3.285:321](∅→∅),[5.88]→[5.638:792](∅→∅),[3.321]→[5.638:792](∅→∅),[5.638]→[5.638:792](∅→∅),[5.792]→[3.322:350](∅→∅),[5.304]→[5.853:859](∅→∅),[3.350]→[5.853:859](∅→∅),[5.853]→[5.853:859](∅→∅),[5.51]→[5.256:260](∅→∅),[5.687]→[5.256:260](∅→∅),[5.859]→[5.256:260](∅→∅),[5.1551]→[5.256:260](∅→∅),[5.55726]→[5.256:260](∅→∅),[5.256]→[5.256:260](∅→∅),[5.260]→[5.41:42](∅→∅),[5.2796]→[5.41:42](∅→∅),[5.41]→[5.41:42](∅→∅),[5.42]→[5.50:101](∅→∅),[5.155]→[5.147:186](∅→∅),[5.147]→[5.147:186](∅→∅),[5.186]→[5.93:134](∅→∅),[5.134]→[5.54:104](∅→∅),[5.186]→[5.54:104](∅→∅),[5.104]→[5.135:183](∅→∅),[5.104]→[5.3962:3990](∅→∅),[5.183]→[5.3962:3990](∅→∅),[5.3962]→[5.3962:3990](∅→∅),[5.3990]→[5.187:210](∅→∅),[5.73]→[5.187:210](∅→∅)
for _, f in ipairs(line_cache.fragments) do-- render fragmentlocal frag_width = App.width(f)if x + frag_width > State.right thenx = State.lefttable.insert(line_cache.screen_line_starting_pos, pos)endx = x + frag_widthpos = pos + utf8.len(f)endendfunction Text.compute_fragments(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.fragments thenreturnendline_cache.fragments = {}local x = State.left - replacement in text.lua at line 91
while x + frag_width > State.right doif (x-State.left) < 0.8 * (State.right-State.left) then--? 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 - replacement in text.lua at line 97
local bpos = Text.nearest_pos_less_than(frag, State.right - x)if bpos == 0 then break end -- avoid infinite loop when window is too narrowlocal bpos = Text.nearest_pos_less_than(frag, State.width - x)-- everything works if bpos == 0, but is a little inefficientpos = pos + bpos - edit in text.lua at line 101
local frag1 = string.sub(frag, 1, boffset-1)local frag1_width = App.width(frag1)assert(x + frag1_width <= State.right)table.insert(line_cache.fragments, frag1) - edit in text.lua at line 102
--? if bpos > 0 then--? print('after chop:', frag)--? end - replacement in text.lua at line 107[5.1377]→[5.1203:1237](∅→∅),[5.1237]→[5.1377:1407](∅→∅),[5.1377]→[5.1377:1407](∅→∅),[5.1407]→[3.402:449](∅→∅)
x = State.left -- new lineendif #frag > 0 thentable.insert(line_cache.fragments, frag)--? print('screen line:', pos)table.insert(line_cache.screen_line_starting_pos, pos)x = 0 -- new screen line - edit in text.lua at line 112
pos = pos + utf8.len(frag) - edit in text.lua at line 957
State.line_cache[line_index].fragments = nil - replacement in app.lua at line 376
local stack_trace = debug.traceback('', --[[stack frame]]4)local stack_trace = debug.traceback('', --[[stack frame]]5)