add state arg to a few functions
[?]
Jul 13, 2022, 12:24 AM
QCPXQ2E3USF3Z6R6WJ2JKHTRMPKA6QWXFKKRMLXA3MXABJEL543ACDependencies
- [2]
WLJCIXYMadd state arg to a few functions - [3]
HYEAFRZ2split mouse_pressed events between Text and Drawing - [4]
KOTI3MFGbugfix in previous commit - [5]
ZHLO7K3Madd args to some functions - [6]
PX7DDEMOautosave slightly less aggressively - [7]
4CTZOJPCstop pretending globals are local - [8]
2LOQ5ALJadd args to some functions - [9]
YPHKZVWMextract a new variable - [10]
2RXZ3PGObeginning of a new approach to scroll+wrap - [11]
MDXGMZU2disable all debug prints - [12]
QYIFOHW3first test! - [13]
AYE2VEGJextract a couple of methods - [14]
ESETRNLBbugfix: printing the first part of a line at the bottom made it seem non-wrapping - [15]
GN3IF4WFbugfix: pasting newlines - [16]
YJJ4X4JGbugfix: avoid scrolling on 'end' - [17]
KECEMMMRextract couple of functions - [18]
OMTGHWMAyet another bugfix. But for how long? - [19]
KOYAJWE4extract a couple more methods - [20]
HMODUNJEscroll on backspace - [21]
MP2TBKU6bugfix: crash in Text.up() after return - [22]
3TDOZESEextract scrolling logic out of insert_return - [23]
3OKKTUT4up and down arrow now moving by screen line where possible - [24]
QLTJG7Q3indent - [25]
HTWAM4NZbugfix: scrolling in left/right movements - [26]
XNFTJHC4split keyboard handling between Text and Drawing - [27]
JJ7J4PUBsome unnecessary mutations - [28]
PFT5Y2ZYmove - [29]
IMEJA43Lsnapshot - [30]
GCEF4N3Vstop repeatedly checking for line wrapping - [31]
2CH77LZCadd args to some functions - [32]
5OALPNN3add args to some functions - [33]
CVSRHMJ2experiment: slightly adaptive scrolling - [34]
KZ5GAYRPthis fixes the immediate regression - [35]
LF7BWEG4group all editor globals - [36]
OGUV4HSAremove some memory leaks from rendered fragments - [37]
BTKAW76Lrename - [38]
M6TH7VSZrip out notion of Line_width - [39]
3MAZEQK5add state arg to Text.textinput - [40]
S2MISTTMadd state arg to a few functions - [41]
F65ADDGLadd state arg to a few functions - [42]
H2DPLWMVsnapshot: wrapping long lines at word boundaries - [43]
RF5ALVNYallow the window to be resized - [44]
Z5HLXU4Padd state arg to a few functions - [45]
CCYSVZA2bugfix: BSOD in #4. - [46]
QCQTMUZ7add args to some functions - [47]
CTJ3IZGSadd args to some functions - [48]
SVJZZDC3snapshot - no, that's all wrong - [49]
UV4EWOLYadd args to some functions - [50]
K4OBZSHEadd args to some functions - [51]
5UG5PQ6Kundo commit 861c57b533 - [52]
CPZGQT72go through and fix similar issues - [53]
HOSPP2ANcrisp font rendering - [54]
62PZGSUCoptimization: moving cursor to next word - [55]
242L3OQXbugfix: ensure Cursor_line is always on a text line - [56]
EMRPLZPWdrop an arg from a function - [57]
GK47BBCYstart passing left/right margins everywhere - [58]
GGJEDJOOadd args to some functions - [59]
SPSW74Y5add state arg to Text.keychord_pressed - [60]
AIRIP35Zcleaner - [61]
ULKLJBN6couple of renames - [62]
CUIV2LE5some typos - [63]
WOXIYUTLbugfix: manage screen_top and cursor when resizing - [64]
CBPV5SSIstop handling nil screen_line_starting_pos everywhere - [65]
2ZYV7D3Whandle tab characters - [66]
LXTTOB33extract a couple of files - [67]
2L5MEZV3experiment: new edit namespace - [68]
ZPUQSPQPextract a few methods - [69]
IRCKL6VNextract scrolling logic out of insert_at_cursor - [70]
U7M4M2F7bugfix: don't rely on Screen_bottom1 while scrolling - [71]
MYC7XR5Qbugfix: lines that aren't drawn from the start - [72]
BOFNXP5Gclicking now moves the cursor even on long, wrapped lines - [73]
PR4KIAZDfirst stab at equally hacky cursor down support - [74]
ZZ2B5RPQextract variables for drawing padding - [75]
R22PA3XRfix a second BSOD in #4 :/ - [76]
LNUHQOGHstart passing in Editor_state explicitly - [77]
R53OF3ONone bug I've repeatedly run into while testing with Moby Dick - [78]
AMSESRTHmove some code - [79]
2H67P75Xswitch arg for a function - [80]
PHQPLJUQrename - [81]
K464QQR4more defensive resize handling - [82]
PTDO2SOTadd state arg to schedule_save - [83]
EGH7XDBKsupport non-text lines in Text.to2 - [84]
BULPIBEGbeginnings of a module for the text editor - [85]
TRNWIQN6more precise height calculation when scrolling up as much as possible while keeping cursor on screen - [86]
U52E2XZNfix a crash - [87]
DRFE3B3Zmouse buttons are integers, not strings - [88]
YLKLDF4R. - [89]
5FW7YOFThighlight selection while dragging - [90]
PLKNHYZ4extract a function - [*]
OTIBCAUJlove2d scaffold
Change contents
- replacement in text.lua at line 145
Text.snap_cursor_to_bottom_of_screen(State.margin_left, App.screen.width-State.margin_right)Text.snap_cursor_to_bottom_of_screen(State, State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 168
Text.snap_cursor_to_bottom_of_screen(State.margin_left, App.screen.width-State.margin_right)Text.snap_cursor_to_bottom_of_screen(State, State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 178
Text.snap_cursor_to_bottom_of_screen(State.margin_left, App.screen.width-State.margin_right)Text.snap_cursor_to_bottom_of_screen(State, State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 215
local top2 = Text.to2(State.screen_top1, State.margin_left, App.screen.width-State.margin_right)top2 = Text.previous_screen_line(top2, State.margin_left, App.screen.width-State.margin_right)State.screen_top1 = Text.to1(top2)Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leakslocal top2 = Text.to2(State, State.screen_top1, State.margin_left, App.screen.width-State.margin_right)top2 = Text.previous_screen_line(State, top2, State.margin_left, App.screen.width-State.margin_right)State.screen_top1 = Text.to1(State, top2)Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks - replacement in text.lua at line 357
local top2 = Text.to2(State.screen_top1, left, right)local top2 = Text.to2(State, State.screen_top1, left, right) - replacement in text.lua at line 368
top2 = Text.previous_screen_line(top2, left, right)top2 = Text.previous_screen_line(State, top2, left, right) - replacement in text.lua at line 370
State.screen_top1 = Text.to1(top2)State.screen_top1 = Text.to1(State, top2) - replacement in text.lua at line 373
Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(left, right)Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(State, left, right) - replacement in text.lua at line 383
local top2 = Text.to2(State.screen_bottom1, left, right)local top2 = Text.to2(State, State.screen_bottom1, left, right) - replacement in text.lua at line 387
local new_top1 = Text.to1(top2)local new_top1 = Text.to1(State, top2) - replacement in text.lua at line 397
Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(left, right)Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(State, left, right) - replacement in text.lua at line 399
Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaksText.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks - replacement in text.lua at line 457
if Text.cursor_at_final_screen_line(left, right) thenif Text.cursor_at_final_screen_line(State, left, right) then - replacement in text.lua at line 473
Text.snap_cursor_to_bottom_of_screen(left, right)Text.snap_cursor_to_bottom_of_screen(State, left, right) - replacement in text.lua at line 492
Text.snap_cursor_to_bottom_of_screen(left, right)Text.snap_cursor_to_bottom_of_screen(State, left, right) - replacement in text.lua at line 511
Text.snap_cursor_to_bottom_of_screen(left, right)Text.snap_cursor_to_bottom_of_screen(State, left, right) - replacement in text.lua at line 560
Text.snap_cursor_to_bottom_of_screen(left, right)Text.snap_cursor_to_bottom_of_screen(State, left, right) - replacement in text.lua at line 589[3.606]→[3.606:664](∅→∅),[3.246]→[3.150:206](∅→∅),[3.664]→[3.150:206](∅→∅),[3.73630]→[3.150:206](∅→∅),[3.6636]→[3.150:206](∅→∅),[3.206]→[3.665:704](∅→∅)
local top2 = Text.to2(State.screen_top1, left, right)top2 = Text.previous_screen_line(top2, left, right)State.screen_top1 = Text.to1(top2)local top2 = Text.to2(State, State.screen_top1, left, right)top2 = Text.previous_screen_line(State, top2, left, right)State.screen_top1 = Text.to1(State, top2) - replacement in text.lua at line 598
Text.snap_cursor_to_bottom_of_screen(left, right)Text.snap_cursor_to_bottom_of_screen(State, left, right) - replacement in text.lua at line 630
function Text.cursor_at_final_screen_line(left, right)Text.populate_screen_line_starting_pos(Editor_state.lines[Editor_state.cursor1.line], left, right)local screen_lines = Editor_state.lines[Editor_state.cursor1.line].screen_line_starting_pos--? print(screen_lines[#screen_lines], Editor_state.cursor1.pos)return screen_lines[#screen_lines] <= Editor_state.cursor1.posfunction Text.cursor_at_final_screen_line(State, left, right)Text.populate_screen_line_starting_pos(State.lines[State.cursor1.line], left, right)local screen_lines = State.lines[State.cursor1.line].screen_line_starting_pos--? print(screen_lines[#screen_lines], State.cursor1.pos)return screen_lines[#screen_lines] <= State.cursor1.pos - replacement in text.lua at line 637
function Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(left, right)local y = Editor_state.margin_topwhile Editor_state.cursor1.line <= #Editor_state.lines doif Editor_state.lines[Editor_state.cursor1.line].mode == 'text' thenfunction Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary(State, left, right)local y = State.margin_topwhile State.cursor1.line <= #State.lines doif State.lines[State.cursor1.line].mode == 'text' then - replacement in text.lua at line 643
--? print('cursor skips', Editor_state.cursor1.line)y = y + Editor_state.drawing_padding_height + Drawing.pixels(Editor_state.lines[Editor_state.cursor1.line].h)Editor_state.cursor1.line = Editor_state.cursor1.line + 1--? print('cursor skips', State.cursor1.line)y = y + State.drawing_padding_height + Drawing.pixels(State.lines[State.cursor1.line].h)State.cursor1.line = State.cursor1.line + 1 - replacement in text.lua at line 648
if Editor_state.cursor1.line > #Editor_state.lines thenassert(Editor_state.cursor1.line == #Editor_state.lines+1)table.insert(Editor_state.lines, {mode='text', data=''})if State.cursor1.line > #State.lines thenassert(State.cursor1.line == #State.lines+1)table.insert(State.lines, {mode='text', data=''}) - replacement in text.lua at line 652
--? print(y, App.screen.height, App.screen.height-Editor_state.line_height)if y > App.screen.height - Editor_state.line_height then--? print(y, App.screen.height, App.screen.height-State.line_height)if y > App.screen.height - State.line_height then - replacement in text.lua at line 655
Text.snap_cursor_to_bottom_of_screen(left, right)Text.snap_cursor_to_bottom_of_screen(State, left, right) - replacement in text.lua at line 659[3.540]→[3.75550:75594](∅→∅),[3.75594]→[3.599:658](∅→∅),[3.325]→[3.599:658](∅→∅),[3.658]→[3.75595:75654](∅→∅)
-- should never modify Editor_state.cursor1function Text.snap_cursor_to_bottom_of_screen(left, right)local top2 = Text.to2(Editor_state.cursor1, left, right)-- should never modify State.cursor1function Text.snap_cursor_to_bottom_of_screen(State, left, right)local top2 = Text.to2(State, State.cursor1, left, right) - replacement in text.lua at line 663
--? print('cursor pos '..tostring(Editor_state.cursor1.pos)..' is on the #'..tostring(top2.screen_line)..' screen line down')local y = App.screen.height - Editor_state.line_height--? print('cursor pos '..tostring(State.cursor1.pos)..' is on the #'..tostring(top2.screen_line)..' screen line down')local y = App.screen.height - State.line_height - replacement in text.lua at line 669
if top2.screen_line > 1 or Editor_state.lines[top2.line-1].mode == 'text' thenlocal h = Editor_state.line_heightif y - h < Editor_state.margin_top thenif top2.screen_line > 1 or State.lines[top2.line-1].mode == 'text' thenlocal h = State.line_heightif y - h < State.margin_top then - replacement in text.lua at line 677
assert(Editor_state.lines[top2.line-1].mode == 'drawing')assert(State.lines[top2.line-1].mode == 'drawing') - replacement in text.lua at line 680
local h = Editor_state.drawing_padding_height + Drawing.pixels(Editor_state.lines[top2.line-1].h)if y - h < Editor_state.margin_top thenlocal h = State.drawing_padding_height + Drawing.pixels(State.lines[top2.line-1].h)if y - h < State.margin_top then - replacement in text.lua at line 687
top2 = Text.previous_screen_line(top2, left, right)top2 = Text.previous_screen_line(State, top2, left, right) - replacement in text.lua at line 690
Editor_state.screen_top1 = Text.to1(top2)--? print('top1 finally:', Editor_state.screen_top1.line, Editor_state.screen_top1.pos)Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaksState.screen_top1 = Text.to1(State, top2)--? print('top1 finally:', State.screen_top1.line, State.screen_top1.pos)Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks - replacement in text.lua at line 695
function Text.in_line(line, x,y, left,right)function Text.in_line(State, line, x,y, left,right) - replacement in text.lua at line 700
return y < line.starty + Editor_state.line_height*(#line.screen_line_starting_pos - Text.screen_line_index(line, line.startpos) + 1)return y < line.starty + State.line_height*(#line.screen_line_starting_pos - Text.screen_line_index(line, line.startpos) + 1) - replacement in text.lua at line 704
function Text.to_pos_on_line(line, mx, my, left, right)function Text.to_pos_on_line(State, line, mx, my, left, right) - replacement in text.lua at line 716
local nexty = y + Editor_state.line_heightlocal nexty = y + State.line_height - edit in text.lua at line 733[3.468]→[3.1324:1502](∅→∅),[3.1502]→[3.76547:76592](∅→∅),[3.7701]→[3.1533:1643](∅→∅),[3.76592]→[3.1533:1643](∅→∅),[3.1533]→[3.1533:1643](∅→∅),[3.1643]→[3.76593:76638](∅→∅)
-- manual test:-- line: abc-- def-- gh-- fragments: abc, def, gh-- click inside e-- line_starting_pos = 1 + 3 = 4-- nearest_cursor_pos('defgh', mx) = 2-- Editor_state.cursor1.pos = 4 + 2 - 1 = 5-- manual test:-- click inside h-- line_starting_pos = 1 + 3 + 3 = 7-- nearest_cursor_pos('gh', mx) = 2-- Editor_state.cursor1.pos = 7 + 2 - 1 = 8 - replacement in text.lua at line 836
function Text.to2(pos1, left, right)if Editor_state.lines[pos1.line].mode == 'drawing' thenfunction Text.to2(State, pos1, left, right)if State.lines[pos1.line].mode == 'drawing' then - replacement in text.lua at line 841
Text.populate_screen_line_starting_pos(Editor_state.lines[pos1.line], left, right)for i=#Editor_state.lines[pos1.line].screen_line_starting_pos,1,-1 dolocal spos = Editor_state.lines[pos1.line].screen_line_starting_pos[i]Text.populate_screen_line_starting_pos(State.lines[pos1.line], left, right)for i=#State.lines[pos1.line].screen_line_starting_pos,1,-1 dolocal spos = State.lines[pos1.line].screen_line_starting_pos[i] - replacement in text.lua at line 854
function Text.to1(pos2)function Text.to1(State, pos2) - replacement in text.lua at line 857
result.pos = Editor_state.lines[pos2.line].screen_line_starting_pos[pos2.screen_line] + pos2.screen_pos - 1result.pos = State.lines[pos2.line].screen_line_starting_pos[pos2.screen_line] + pos2.screen_pos - 1 - edit in text.lua at line 890
print(Editor_state.cursor1.line, Editor_state.cursor1.pos, #Editor_state.lines[Editor_state.cursor1.line].data, Editor_state.lines[Editor_state.cursor1.line].data) - replacement in text.lua at line 896
function Text.previous_screen_line(pos2, left, right)function Text.previous_screen_line(State, pos2, left, right) - replacement in text.lua at line 901
elseif Editor_state.lines[pos2.line-1].mode == 'drawing' thenelseif State.lines[pos2.line-1].mode == 'drawing' then - replacement in text.lua at line 904
local l = Editor_state.lines[pos2.line-1]Text.populate_screen_line_starting_pos(Editor_state.lines[pos2.line-1], left, right)return {line=pos2.line-1, screen_line=#Editor_state.lines[pos2.line-1].screen_line_starting_pos, screen_pos=1}local l = State.lines[pos2.line-1]Text.populate_screen_line_starting_pos(State.lines[pos2.line-1], left, right)return {line=pos2.line-1, screen_line=#State.lines[pos2.line-1].screen_line_starting_pos, screen_pos=1} - replacement in text.lua at line 935
function Text.tweak_screen_top_and_cursor(left, right)--? print('a', Editor_state.selection1.line)if Editor_state.screen_top1.pos == 1 then return endlocal line = Editor_state.lines[Editor_state.screen_top1.line]-- resize helperfunction Text.tweak_screen_top_and_cursor(State, left, right)--? print('a', State.selection1.line)if State.screen_top1.pos == 1 then return endlocal line = State.lines[State.screen_top1.line] - replacement in text.lua at line 943
if pos == Editor_state.screen_top1.pos thenif pos == State.screen_top1.pos then - replacement in text.lua at line 946
if pos > Editor_state.screen_top1.pos thenif pos > State.screen_top1.pos then - replacement in text.lua at line 949
if Editor_state.screen_top1.pos - prev < pos - Editor_state.screen_top1.pos thenEditor_state.screen_top1.pos = previf State.screen_top1.pos - prev < pos - State.screen_top1.pos thenState.screen_top1.pos = prev - replacement in text.lua at line 952
Editor_state.screen_top1.pos = posState.screen_top1.pos = pos - replacement in text.lua at line 958
if Text.lt1(Editor_state.cursor1, Editor_state.screen_top1) thenEditor_state.cursor1 = {line=Editor_state.screen_top1.line, pos=Editor_state.screen_top1.pos}elseif Editor_state.cursor1.line >= Editor_state.screen_bottom1.line thenif Text.lt1(State.cursor1, State.screen_top1) thenState.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}elseif State.cursor1.line >= State.screen_bottom1.line then - replacement in text.lua at line 962
if Text.cursor_past_screen_bottom(Editor_state) thenif Text.cursor_past_screen_bottom(State) then - replacement in text.lua at line 964
local line = Editor_state.lines[Editor_state.screen_bottom1.line]Editor_state.cursor1 = {line=Editor_state.screen_bottom1.line,pos=Text.to_pos_on_line(line, App.screen.width-5, App.screen.height-5, left, right),local line = State.lines[State.screen_bottom1.line]State.cursor1 = {line=State.screen_bottom1.line,pos=Text.to_pos_on_line(State, line, App.screen.width-5, App.screen.height-5, left, right), - replacement in text.lua at line 984
function Text.redraw_all()function Text.redraw_all(State) - replacement in text.lua at line 986
for _,line in ipairs(Editor_state.lines) dofor _,line in ipairs(State.lines) do - replacement in select.lua at line 96
if Text.in_line(line, x,y, left, right) thenreturn line_index, Text.to_pos_on_line(line, x,y, left, right)if Text.in_line(State, line, x,y, left, right) thenreturn line_index, Text.to_pos_on_line(State, line, x,y, left, right) - replacement in main.lua at line 116
Text.redraw_all()Text.redraw_all(Editor_state) - replacement in main.lua at line 118
Text.tweak_screen_top_and_cursor(Editor_state.margin_left, App.screen.height-Editor_state.margin_right)Text.tweak_screen_top_and_cursor(Editor_state, Editor_state.margin_left, App.screen.height-Editor_state.margin_right) - replacement in edit.lua at line 206
if Text.in_line(line, x,y, State.margin_left, App.screen.width-State.margin_right) thenif Text.in_line(State, line, x,y, State.margin_left, App.screen.width-State.margin_right) then - replacement in edit.lua at line 221
pos=Text.to_pos_on_line(line, x, y, State.margin_left, App.screen.width-State.margin_right),pos=Text.to_pos_on_line(State, line, x, y, State.margin_left, App.screen.width-State.margin_right), - replacement in edit.lua at line 251
if Text.in_line(line, x,y, State.margin_left, App.screen.width-State.margin_right) thenif Text.in_line(State, line, x,y, State.margin_left, App.screen.width-State.margin_right) then - replacement in edit.lua at line 255
pos=Text.to_pos_on_line(line, x, y, State.margin_left, App.screen.width-State.margin_right),pos=Text.to_pos_on_line(State, line, x, y, State.margin_left, App.screen.width-State.margin_right), - replacement in edit.lua at line 311
Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaksText.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks - replacement in edit.lua at line 334
Text.redraw_all()Text.redraw_all(State) - replacement in edit.lua at line 337
Text.redraw_all()Text.redraw_all(State) - replacement in edit.lua at line 340
Text.redraw_all()Text.redraw_all(State) - replacement in edit.lua at line 350
Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaksText.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks - replacement in edit.lua at line 362
Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaksText.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks