add state arg to Text.keychord_pressed
[?]
Jul 12, 2022, 11:23 PM
SPSW74Y5OJ54Y7VQ3SJFCJR5CYDKTR4A3TOEVZODDZLUSDDU2GZACDependencies
- [2]
LNUHQOGHstart passing in Editor_state explicitly - [3]
7LVK4KRDfix a failing test - [4]
OYXDYPGSget rid of debug variables - [5]
PHFWIFYKscroll on enter - [6]
GN3IF4WFbugfix: pasting newlines - [7]
2ZYV7D3Whandle tab characters - [8]
V5MJRFOZbugfix: down arrow doesn't scroll up unnecessarily - [9]
73OCE2MCafter much struggle, a brute-force undo - [10]
ZHLO7K3Madd args to some functions - [11]
PX7DDEMOautosave slightly less aggressively - [12]
AYE2VEGJextract a couple of methods - [13]
VJ77YABHmore efficient undo/redo - [14]
3TDOZESEextract scrolling logic out of insert_return - [15]
2L5MEZV3experiment: new edit namespace - [16]
LF7BWEG4group all editor globals - [17]
DHI6IJCNselecting text and deleting selections - [18]
MP2TBKU6bugfix: crash in Text.up() after return - [19]
DAENUOGVeliminate assumptions that line length == size in bytes - [20]
HTWAM4NZbugfix: scrolling in left/right movements - [21]
FYS7TCDWbugfix - [22]
537TQ2QNsome more logging - [23]
2RXZ3PGObeginning of a new approach to scroll+wrap - [24]
OGUV4HSAremove some memory leaks from rendered fragments - [25]
IRCKL6VNextract scrolling logic out of insert_at_cursor - [26]
4KOI3E6Rremove some redundant checks - [27]
AOIRVVJArevert selection logic to before commit 3ffc2ed8f - [28]
PLKNHYZ4extract a function - [29]
NZKYPBSKcheck for scroll when just typing - [30]
X75QPYVWmove Selection1 clearing past business logic - [31]
AMSESRTHmove some code - [32]
DLQMM265scroll past first page - [33]
EMHRPJ3Rno, that's not right - [34]
EBBFOW4Xbugfix: clear selection in a couple more places - [35]
XNFTJHC4split keyboard handling between Text and Drawing - [36]
SQLVYKVJrename - [37]
KOYAJWE4extract a couple more methods - [38]
JY4VK7L2rename - [39]
H2DPLWMVsnapshot: wrapping long lines at word boundaries - [40]
VA2ZYFFFbetter fix for commit 3ffc2ed8f - [41]
CG3264MMmove - [42]
ZPUQSPQPextract a few methods - [43]
2POFQQLWkeep cursor on screen when pressing 'down' - [44]
HMODUNJEscroll on backspace - [45]
SVJZZDC3snapshot - no, that's all wrong - [46]
AVLAYODPmuch simpler - [*]
BULPIBEGbeginnings of a module for the text editor
Change contents
- replacement in text.lua at line 159
function Text.keychord_pressed(chord)--? print('chord', chord, Editor_state.selection1.line, Editor_state.selection1.pos)function Text.keychord_pressed(State, chord)--? print('chord', chord, State.selection1.line, State.selection1.pos) - replacement in text.lua at line 163
local before_line = Editor_state.cursor1.linelocal before_line = State.cursor1.line - replacement in text.lua at line 166
Editor_state.selection1 = {}if (Editor_state.cursor_y + Editor_state.line_height) > App.screen.height thenText.snap_cursor_to_bottom_of_screen(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)State.selection1 = {}if (State.cursor_y + State.line_height) > App.screen.height thenText.snap_cursor_to_bottom_of_screen(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 171
record_undo_event({before=before, after=snapshot(before_line, Editor_state.cursor1.line)})record_undo_event({before=before, after=snapshot(before_line, State.cursor1.line)}) - replacement in text.lua at line 173
local before = snapshot(Editor_state.cursor1.line)--? print(Editor_state.screen_top1.line, Editor_state.screen_top1.pos, Editor_state.cursor1.line, Editor_state.cursor1.pos, Editor_state.screen_bottom1.line, Editor_state.screen_bottom1.pos)local before = snapshot(State.cursor1.line)--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos) - replacement in text.lua at line 176
if Editor_state.cursor_y >= App.screen.height - Editor_state.line_height thenText.populate_screen_line_starting_pos(Editor_state.lines[Editor_state.cursor1.line], Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Text.snap_cursor_to_bottom_of_screen(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)--? print('=>', Editor_state.screen_top1.line, Editor_state.screen_top1.pos, Editor_state.cursor1.line, Editor_state.cursor1.pos, Editor_state.screen_bottom1.line, Editor_state.screen_bottom1.pos)if State.cursor_y >= App.screen.height - State.line_height thenText.populate_screen_line_starting_pos(State.lines[State.cursor1.line], State.margin_left, App.screen.width-State.margin_right)Text.snap_cursor_to_bottom_of_screen(State.margin_left, App.screen.width-State.margin_right)--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos) - replacement in text.lua at line 182
record_undo_event({before=before, after=snapshot(Editor_state.cursor1.line)})record_undo_event({before=before, after=snapshot(State.cursor1.line)}) - replacement in text.lua at line 184
if Editor_state.selection1.line thenText.delete_selection(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)if State.selection1.line thenText.delete_selection(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 190
if Editor_state.cursor1.pos > 1 thenbefore = snapshot(Editor_state.cursor1.line)local byte_start = utf8.offset(Editor_state.lines[Editor_state.cursor1.line].data, Editor_state.cursor1.pos-1)local byte_end = utf8.offset(Editor_state.lines[Editor_state.cursor1.line].data, Editor_state.cursor1.pos)if State.cursor1.pos > 1 thenbefore = snapshot(State.cursor1.line)local byte_start = utf8.offset(State.lines[State.cursor1.line].data, State.cursor1.pos-1)local byte_end = utf8.offset(State.lines[State.cursor1.line].data, State.cursor1.pos) - replacement in text.lua at line 196
Editor_state.lines[Editor_state.cursor1.line].data = string.sub(Editor_state.lines[Editor_state.cursor1.line].data, 1, byte_start-1)..string.sub(Editor_state.lines[Editor_state.cursor1.line].data, byte_end)State.lines[State.cursor1.line].data = string.sub(State.lines[State.cursor1.line].data, 1, byte_start-1)..string.sub(State.lines[State.cursor1.line].data, byte_end) - replacement in text.lua at line 198
Editor_state.lines[Editor_state.cursor1.line].data = string.sub(Editor_state.lines[Editor_state.cursor1.line].data, 1, byte_start-1)State.lines[State.cursor1.line].data = string.sub(State.lines[State.cursor1.line].data, 1, byte_start-1) - replacement in text.lua at line 200
Editor_state.cursor1.pos = Editor_state.cursor1.pos-1State.cursor1.pos = State.cursor1.pos-1 - replacement in text.lua at line 202
elseif Editor_state.cursor1.line > 1 thenbefore = snapshot(Editor_state.cursor1.line-1, Editor_state.cursor1.line)if Editor_state.lines[Editor_state.cursor1.line-1].mode == 'drawing' thentable.remove(Editor_state.lines, Editor_state.cursor1.line-1)elseif State.cursor1.line > 1 thenbefore = snapshot(State.cursor1.line-1, State.cursor1.line)if State.lines[State.cursor1.line-1].mode == 'drawing' thentable.remove(State.lines, State.cursor1.line-1) - replacement in text.lua at line 208
Editor_state.cursor1.pos = utf8.len(Editor_state.lines[Editor_state.cursor1.line-1].data)+1Editor_state.lines[Editor_state.cursor1.line-1].data = Editor_state.lines[Editor_state.cursor1.line-1].data..Editor_state.lines[Editor_state.cursor1.line].datatable.remove(Editor_state.lines, Editor_state.cursor1.line)State.cursor1.pos = utf8.len(State.lines[State.cursor1.line-1].data)+1State.lines[State.cursor1.line-1].data = State.lines[State.cursor1.line-1].data..State.lines[State.cursor1.line].datatable.remove(State.lines, State.cursor1.line) - replacement in text.lua at line 212
Editor_state.cursor1.line = Editor_state.cursor1.line-1State.cursor1.line = State.cursor1.line-1 - replacement in text.lua at line 214
if Text.lt1(Editor_state.cursor1, Editor_state.screen_top1) thenlocal top2 = Text.to2(Editor_state.screen_top1, Editor_state.margin_left, App.screen.width-Editor_state.margin_right)top2 = Text.previous_screen_line(top2, Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Editor_state.screen_top1 = Text.to1(top2)if Text.lt1(State.cursor1, State.screen_top1) thenlocal 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) - replacement in text.lua at line 220
Text.clear_cache(Editor_state.lines[Editor_state.cursor1.line])assert(Text.le1(Editor_state.screen_top1, Editor_state.cursor1))Text.clear_cache(State.lines[State.cursor1.line])assert(Text.le1(State.screen_top1, State.cursor1)) - replacement in text.lua at line 223
record_undo_event({before=before, after=snapshot(Editor_state.cursor1.line)})record_undo_event({before=before, after=snapshot(State.cursor1.line)}) - replacement in text.lua at line 225
if Editor_state.selection1.line thenText.delete_selection(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)if State.selection1.line thenText.delete_selection(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 231
if Editor_state.cursor1.pos <= utf8.len(Editor_state.lines[Editor_state.cursor1.line].data) thenbefore = snapshot(Editor_state.cursor1.line)if State.cursor1.pos <= utf8.len(State.lines[State.cursor1.line].data) thenbefore = snapshot(State.cursor1.line) - replacement in text.lua at line 234
before = snapshot(Editor_state.cursor1.line, Editor_state.cursor1.line+1)before = snapshot(State.cursor1.line, State.cursor1.line+1) - replacement in text.lua at line 236
if Editor_state.cursor1.pos <= utf8.len(Editor_state.lines[Editor_state.cursor1.line].data) thenlocal byte_start = utf8.offset(Editor_state.lines[Editor_state.cursor1.line].data, Editor_state.cursor1.pos)local byte_end = utf8.offset(Editor_state.lines[Editor_state.cursor1.line].data, Editor_state.cursor1.pos+1)if State.cursor1.pos <= utf8.len(State.lines[State.cursor1.line].data) thenlocal byte_start = utf8.offset(State.lines[State.cursor1.line].data, State.cursor1.pos)local byte_end = utf8.offset(State.lines[State.cursor1.line].data, State.cursor1.pos+1) - replacement in text.lua at line 241
Editor_state.lines[Editor_state.cursor1.line].data = string.sub(Editor_state.lines[Editor_state.cursor1.line].data, 1, byte_start-1)..string.sub(Editor_state.lines[Editor_state.cursor1.line].data, byte_end)State.lines[State.cursor1.line].data = string.sub(State.lines[State.cursor1.line].data, 1, byte_start-1)..string.sub(State.lines[State.cursor1.line].data, byte_end) - replacement in text.lua at line 243
Editor_state.lines[Editor_state.cursor1.line].data = string.sub(Editor_state.lines[Editor_state.cursor1.line].data, 1, byte_start-1)State.lines[State.cursor1.line].data = string.sub(State.lines[State.cursor1.line].data, 1, byte_start-1) - replacement in text.lua at line 245
-- no change to Editor_state.cursor1.pos-- no change to State.cursor1.pos - replacement in text.lua at line 247
elseif Editor_state.cursor1.line < #Editor_state.lines thenif Editor_state.lines[Editor_state.cursor1.line+1].mode == 'drawing' thentable.remove(Editor_state.lines, Editor_state.cursor1.line+1)elseif State.cursor1.line < #State.lines thenif State.lines[State.cursor1.line+1].mode == 'drawing' thentable.remove(State.lines, State.cursor1.line+1) - replacement in text.lua at line 252
Editor_state.lines[Editor_state.cursor1.line].data = Editor_state.lines[Editor_state.cursor1.line].data..Editor_state.lines[Editor_state.cursor1.line+1].datatable.remove(Editor_state.lines, Editor_state.cursor1.line+1)State.lines[State.cursor1.line].data = State.lines[State.cursor1.line].data..State.lines[State.cursor1.line+1].datatable.remove(State.lines, State.cursor1.line+1) - replacement in text.lua at line 256
Text.clear_cache(Editor_state.lines[Editor_state.cursor1.line])Text.clear_cache(State.lines[State.cursor1.line]) - replacement in text.lua at line 258
record_undo_event({before=before, after=snapshot(Editor_state.cursor1.line)})record_undo_event({before=before, after=snapshot(State.cursor1.line)}) - replacement in text.lua at line 261
Text.left(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Editor_state.selection1 = {}Text.left(State.margin_left, App.screen.width-State.margin_right)State.selection1 = {} - replacement in text.lua at line 264
Text.right(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Editor_state.selection1 = {}Text.right(State.margin_left, App.screen.width-State.margin_right)State.selection1 = {} - replacement in text.lua at line 267
if Editor_state.selection1.line == nil thenEditor_state.selection1 = {line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}if State.selection1.line == nil thenState.selection1 = {line=State.cursor1.line, pos=State.cursor1.pos} - replacement in text.lua at line 270
Text.left(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Text.left(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 272
if Editor_state.selection1.line == nil thenEditor_state.selection1 = {line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}if State.selection1.line == nil thenState.selection1 = {line=State.cursor1.line, pos=State.cursor1.pos} - replacement in text.lua at line 275
Text.right(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Text.right(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 278
Text.word_left(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Editor_state.selection1 = {}Text.word_left(State.margin_left, App.screen.width-State.margin_right)State.selection1 = {} - replacement in text.lua at line 281
Text.word_right(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Editor_state.selection1 = {}Text.word_right(State.margin_left, App.screen.width-State.margin_right)State.selection1 = {} - replacement in text.lua at line 284
if Editor_state.selection1.line == nil thenEditor_state.selection1 = {line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}if State.selection1.line == nil thenState.selection1 = {line=State.cursor1.line, pos=State.cursor1.pos} - replacement in text.lua at line 287
Text.word_left(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Text.word_left(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 289
if Editor_state.selection1.line == nil thenEditor_state.selection1 = {line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}if State.selection1.line == nil thenState.selection1 = {line=State.cursor1.line, pos=State.cursor1.pos} - replacement in text.lua at line 292
Text.word_right(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Text.word_right(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 295
Editor_state.selection1 = {}State.selection1 = {} - replacement in text.lua at line 297
Text.end_of_line(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Editor_state.selection1 = {}Text.end_of_line(State.margin_left, App.screen.width-State.margin_right)State.selection1 = {} - replacement in text.lua at line 300
if Editor_state.selection1.line == nil thenEditor_state.selection1 = {line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}if State.selection1.line == nil thenState.selection1 = {line=State.cursor1.line, pos=State.cursor1.pos} - replacement in text.lua at line 305
if Editor_state.selection1.line == nil thenEditor_state.selection1 = {line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}if State.selection1.line == nil thenState.selection1 = {line=State.cursor1.line, pos=State.cursor1.pos} - replacement in text.lua at line 308
Text.end_of_line(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Text.end_of_line(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 310
Text.up(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Editor_state.selection1 = {}Text.up(State.margin_left, App.screen.width-State.margin_right)State.selection1 = {} - replacement in text.lua at line 313
Text.down(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Editor_state.selection1 = {}Text.down(State.margin_left, App.screen.width-State.margin_right)State.selection1 = {} - replacement in text.lua at line 316
if Editor_state.selection1.line == nil thenEditor_state.selection1 = {line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}if State.selection1.line == nil thenState.selection1 = {line=State.cursor1.line, pos=State.cursor1.pos} - replacement in text.lua at line 319
Text.up(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Text.up(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 321
if Editor_state.selection1.line == nil thenEditor_state.selection1 = {line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}if State.selection1.line == nil thenState.selection1 = {line=State.cursor1.line, pos=State.cursor1.pos} - replacement in text.lua at line 324
Text.down(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Text.down(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 326
Text.pageup(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Editor_state.selection1 = {}Text.pageup(State.margin_left, App.screen.width-State.margin_right)State.selection1 = {} - replacement in text.lua at line 329
Text.pagedown(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Editor_state.selection1 = {}Text.pagedown(State.margin_left, App.screen.width-State.margin_right)State.selection1 = {} - replacement in text.lua at line 332
if Editor_state.selection1.line == nil thenEditor_state.selection1 = {line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}if State.selection1.line == nil thenState.selection1 = {line=State.cursor1.line, pos=State.cursor1.pos} - replacement in text.lua at line 335
Text.pageup(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Text.pageup(State.margin_left, App.screen.width-State.margin_right) - replacement in text.lua at line 337
if Editor_state.selection1.line == nil thenEditor_state.selection1 = {line=Editor_state.cursor1.line, pos=Editor_state.cursor1.pos}if State.selection1.line == nil thenState.selection1 = {line=State.cursor1.line, pos=State.cursor1.pos} - replacement in text.lua at line 340
Text.pagedown(Editor_state.margin_left, App.screen.width-Editor_state.margin_right)Text.pagedown(State.margin_left, App.screen.width-State.margin_right) - replacement in edit.lua at line 437
Text.keychord_pressed(chord)Text.keychord_pressed(State, chord)