more efficient undo/redo
[?]
Jun 3, 2022, 12:46 AM
VJ77YABHVJZWJKLHAGIPC562GYM73AUGRLCP4JLKP5JPWPT2RIHACDependencies
- [2]
4QQBMWLLregression: typing uppercase letters in text - [3]
N6V6UJ3Pthis implementation undo load-tests quite poorly - [4]
SQLVYKVJrename - [5]
XNFTJHC4split keyboard handling between Text and Drawing - [6]
2ZYV7D3Whandle tab characters - [7]
CG3264MMmove - [8]
HMODUNJEscroll on backspace - [9]
2RXZ3PGObeginning of a new approach to scroll+wrap - [10]
PHFWIFYKscroll on enter - [11]
A2TQYJ6J. - [12]
2POFQQLWkeep cursor on screen when pressing 'down' - [13]
DAENUOGVeliminate assumptions that line length == size in bytes - [14]
DHI6IJCNselecting text and deleting selections - [15]
73OCE2MCafter much struggle, a brute-force undo - [16]
G6OYAYHUpaste in text with M-v - [17]
WY3JD6W6bugfix - [18]
537TQ2QNsome more logging - [19]
SLLR6KKIbugfix for non-ASCII - [20]
QVDQMJXVavoid scrolling down if possible - [21]
AYE2VEGJextract a couple of methods - [22]
JY4VK7L2rename - [23]
IDGP4BJZnew known issue with drawings - [*]
BULPIBEGbeginnings of a module for the text editor - [*]
FS2ITYYHrecord a known issue
Change contents
- edit in undo.lua at line 35
-- Copy all relevant global state. - replacement in undo.lua at line 37
function snapshot()function snapshot(s,e)-- Snapshot everything by default, but subset if requested.if s == nil and e == nil thens = 1e = #Lineselseif e == nil thene = send - edit in undo.lua at line 54
start_line=s,end_line=e, - replacement in undo.lua at line 59
for _,line in ipairs(Lines) dofor i=s,e dolocal line = Lines[i] - edit in undo.lua at line 78
function patch(lines, from, to)--? if #from.lines == 1 and #to.lines == 1 then--? assert(from.start_line == from.end_line)--? assert(to.start_line == to.end_line)--? assert(from.start_line == to.start_line)--? lines[from.start_line] = to.lines[1]--? return--? endassert(from.start_line == to.start_line)for i=from.end_line,from.start_line,-1 dotable.remove(lines, i)endassert(#to.lines == to.end_line-to.start_line+1)for i=1,#to.lines dotable.insert(lines, to.start_line+i-1, to.lines[i])endend - edit in undo.lua at line 108[5.2739]
function minmax(a, b)return math.min(a,b), math.max(a,b)end - edit in text.lua at line 135
local minl,maxl = minmax(Selection1.line, Cursor1.line)local before = snapshot(minl, maxl)Text.delete_selection_without_undo()record_undo_event({before=before, after=snapshot(Cursor1.line)})endfunction Text.delete_selection_without_undo() - edit in text.lua at line 1178
endfunction test_zzz_undo_load_test()print('\n\nTesting a 10KB file')-- create a large list of lineslocal lines = {}-- 10k characters, hundred lines, 2k wordsfor i=1,100 dolocal line = ''for c=1,20 doline = line..'abcd 'endendLines = load_array(lines)-- perform 1000 mutationsprint('are the dots printing quickly and without any pauses?')for i=1,1000 doif i%50 == 0 thenApp.run_after_keychord('return')elseApp.run_after_textinput('a')endif i%10 == 0 thenio.write(i)io.write(' ')io.flush()endend - replacement in text.lua at line 1225
local down = love.keyboard.isDownif Selection1.line thenText.delete_selection()endlocal before = snapshot(Cursor1.line) - edit in text.lua at line 1230
record_undo_event({before=before, after=snapshot(Cursor1.line)}) - edit in text.lua at line 1234
if Selection1.line then Text.delete_selection() end-- Collect what you did in an event that can be undone.local before = snapshot() - edit in text.lua at line 1244
-- finalize undo eventrecord_undo_event({before=before, after=snapshot()}) - replacement in text.lua at line 1251
local before = snapshot()local before_line = Cursor1.linelocal before = snapshot(before_line) - replacement in text.lua at line 1265
record_undo_event({before=before, after=snapshot()})record_undo_event({before=before, after=snapshot(before_line, Cursor1.line)}) - replacement in text.lua at line 1267
local before = snapshot()local before = snapshot(Cursor1.line) - replacement in text.lua at line 1270
record_undo_event({before=before, after=snapshot()})record_undo_event({before=before, after=snapshot(Cursor1.line)}) - edit in text.lua at line 1272
local before = snapshot() - edit in text.lua at line 1275
record_undo_event({before=before, after=snapshot()}) - edit in text.lua at line 1277
local before - edit in text.lua at line 1279
before = snapshot(Cursor1.line)elsebefore = snapshot(Cursor1.line-1, Cursor1.line)endif Cursor1.pos > 1 then - replacement in text.lua at line 1314
record_undo_event({before=before, after=snapshot()})record_undo_event({before=before, after=snapshot(Cursor1.line)}) - edit in text.lua at line 1316
local before = snapshot() - edit in text.lua at line 1319
record_undo_event({before=before, after=snapshot()}) - edit in text.lua at line 1320
endlocal beforeif Cursor1.pos <= utf8.len(Lines[Cursor1.line].data) thenbefore = snapshot(Cursor1.line)elsebefore = snapshot(Cursor1.line, Cursor1.line+1) - replacement in text.lua at line 1350
record_undo_event({before=before, after=snapshot()})record_undo_event({before=before, after=snapshot(Cursor1.line)}) - replacement in text.lua at line 1360
if src.lines thenLines = deepcopy(src.lines)endpatch(Lines, event.after, event.before) - replacement in text.lua at line 1369
if src.lines thenLines = deepcopy(src.lines)--? for _,line in ipairs(Lines) do--? if line.mode == 'drawing' then--? print('restoring', line.points, 'with', #line.points, 'points')--? print('restoring', line.shapes, 'with', #line.shapes, 'shapes')--? end--? endendpatch(Lines, event.before, event.after) - edit in text.lua at line 1383
local before_line = Cursor1.linelocal before = snapshot(before_line) - edit in text.lua at line 1389
record_undo_event({before=before, after=snapshot(before_line, Cursor1.line)}) - replacement in README.md at line 9
* Undo is extremely inefficient in space. While this app is extremely unlikelyto lose the current state of a file at any moment, undo history is volatileand should be considered unstable.* Undo/redo can be sluggish in large files. If things get sluggish, killingthe process can lose data.