From 5c8e3e96c8b852394cd2b0956d6e9bb0b6cc543d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 31 Aug 2024 18:34:03 -0700 Subject: clean up Drawing.before after creating undo event This isn't a bug here, but it led to a bug in lines 2. --- edit.lua | 1 + source_edit.lua | 1 + 2 files changed, 2 insertions(+) diff --git a/edit.lua b/edit.lua index 118e0ea..9a223bf 100644 --- a/edit.lua +++ b/edit.lua @@ -184,6 +184,7 @@ function edit.draw(State) State.cursor1.line = State.cursor1.line+1 end record_undo_event(State, {before=Drawing.before, after=snapshot(State, line_index-1, line_index+1)}) + Drawing.before = nil schedule_save(State) end, }) diff --git a/source_edit.lua b/source_edit.lua index fead6c5..f92ca0f 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -190,6 +190,7 @@ function edit.draw(State, hide_cursor, show_line_numbers) State.cursor1.line = State.cursor1.line+1 end record_undo_event(State, {before=Drawing.before, after=snapshot(State, line_index-1, line_index+1)}) + Drawing.before = nil schedule_save(State) end, }) -- cgit 1.4.1-2-gfad0 From f98cdd14fd876f57a8dc753316fc27994242828f Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 31 Aug 2024 18:59:23 -0700 Subject: explicitly state when operations manage undo --- edit.lua | 4 ++-- select.lua | 6 +++--- source_edit.lua | 4 ++-- source_select.lua | 6 +++--- source_text.lua | 4 ++-- text.lua | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/edit.lua b/edit.lua index 9a223bf..f65486c 100644 --- a/edit.lua +++ b/edit.lua @@ -386,7 +386,7 @@ function edit.keychord_press(State, chord, key) -- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys) (not App.shift_down() or utf8.len(key) == 1) and chord ~= 'C-a' and chord ~= 'C-c' and chord ~= 'C-x' and chord ~= 'backspace' and chord ~= 'delete' and chord ~= 'C-z' and chord ~= 'C-y' and not App.is_cursor_movement(key) then - Text.delete_selection(State, State.left, State.right) + Text.delete_selection_and_record_undo_event(State) end if State.search_term then if chord == 'escape' then @@ -467,7 +467,7 @@ function edit.keychord_press(State, chord, key) App.set_clipboard(s) end elseif chord == 'C-x' then - local s = Text.cut_selection(State, State.left, State.right) + local s = Text.cut_selection_and_record_undo_event(State) if s then App.set_clipboard(s) end diff --git a/select.lua b/select.lua index 7e48274..6e16bd4 100644 --- a/select.lua +++ b/select.lua @@ -81,14 +81,14 @@ function Text.mouse_pos(State) return screen_bottom1.line, Text.pos_at_end_of_screen_line(State, screen_bottom1) end -function Text.cut_selection(State) +function Text.cut_selection_and_record_undo_event(State) if State.selection1.line == nil then return end local result = Text.selection(State) - Text.delete_selection(State) + Text.delete_selection_and_record_undo_event(State) return result end -function Text.delete_selection(State) +function Text.delete_selection_and_record_undo_event(State) if State.selection1.line == nil then return end local minl,maxl = minmax(State.selection1.line, State.cursor1.line) local before = snapshot(State, minl, maxl) diff --git a/source_edit.lua b/source_edit.lua index f92ca0f..2dca05d 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -392,7 +392,7 @@ function edit.keychord_press(State, chord, key) -- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys) (not App.shift_down() or utf8.len(key) == 1) and chord ~= 'C-a' and chord ~= 'C-c' and chord ~= 'C-x' and chord ~= 'backspace' and chord ~= 'delete' and chord ~= 'C-z' and chord ~= 'C-y' and not App.is_cursor_movement(key) then - Text.delete_selection(State, State.left, State.right) + Text.delete_selection_and_record_undo_event(State) end if State.search_term then if chord == 'escape' then @@ -470,7 +470,7 @@ function edit.keychord_press(State, chord, key) App.set_clipboard(s) end elseif chord == 'C-x' then - local s = Text.cut_selection(State, State.left, State.right) + local s = Text.cut_selection_and_record_undo_event(State) if s then App.set_clipboard(s) end diff --git a/source_select.lua b/source_select.lua index b67dd16..a223b80 100644 --- a/source_select.lua +++ b/source_select.lua @@ -83,14 +83,14 @@ function Text.mouse_pos(State) return screen_bottom1.line, Text.pos_at_end_of_screen_line(State, screen_bottom1) end -function Text.cut_selection(State) +function Text.cut_selection_and_record_undo_event(State) if State.selection1.line == nil then return end local result = Text.selection(State) - Text.delete_selection(State) + Text.delete_selection_and_record_undo_event(State) return result end -function Text.delete_selection(State) +function Text.delete_selection_and_record_undo_event(State) if State.selection1.line == nil then return end local minl,maxl = minmax(State.selection1.line, State.cursor1.line) local before = snapshot(State, minl, maxl) diff --git a/source_text.lua b/source_text.lua index 76e9045..9125cb0 100644 --- a/source_text.lua +++ b/source_text.lua @@ -248,7 +248,7 @@ function Text.keychord_press(State, chord) schedule_save(State) elseif chord == 'backspace' then if State.selection1.line then - Text.delete_selection(State, State.left, State.right) + Text.delete_selection_and_record_undo_event(State) schedule_save(State) return end @@ -296,7 +296,7 @@ function Text.keychord_press(State, chord) schedule_save(State) elseif chord == 'delete' then if State.selection1.line then - Text.delete_selection(State, State.left, State.right) + Text.delete_selection_and_record_undo_event(State) schedule_save(State) return end diff --git a/text.lua b/text.lua index ac07903..14eb4b1 100644 --- a/text.lua +++ b/text.lua @@ -174,7 +174,7 @@ function Text.keychord_press(State, chord) schedule_save(State) elseif chord == 'backspace' then if State.selection1.line then - Text.delete_selection(State, State.left, State.right) + Text.delete_selection_and_record_undo_event(State) schedule_save(State) return end @@ -222,7 +222,7 @@ function Text.keychord_press(State, chord) schedule_save(State) elseif chord == 'delete' then if State.selection1.line then - Text.delete_selection(State, State.left, State.right) + Text.delete_selection_and_record_undo_event(State) schedule_save(State) return end -- cgit 1.4.1-2-gfad0 From 52f876302f7e6da1f8f418d9dc85f0698c494e15 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 31 Aug 2024 19:16:20 -0700 Subject: clean up some issues I now feel confident about --- README.md | 7 ------- undo.lua | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/README.md b/README.md index de57872..7e9ac31 100644 --- a/README.md +++ b/README.md @@ -51,13 +51,6 @@ found anything amiss: http://akkartik.name/contact * No support yet for right-to-left languages. -* Undo/redo may be sluggish in large files. Large files may grow sluggish in - other ways. lines.love works well in all circumstances with files under - 50KB. - -* If you kill the process, say by force-quitting because things things get - sluggish, you can lose data. - * The text cursor will always stay on the screen. This can have some strange implications: diff --git a/undo.lua b/undo.lua index d91fecd..59ca481 100644 --- a/undo.lua +++ b/undo.lua @@ -1,8 +1,7 @@ -- undo/redo by managing the sequence of events in the current session -- based on https://github.com/akkartik/mu1/blob/master/edit/012-editor-undo.mu --- Incredibly inefficient; we make a copy of lines on every single keystroke. --- The hope here is that we're either editing small files or just reading large files. +-- makes a copy of lines on every single keystroke; will be inefficient with really long lines. -- TODO: highlight stuff inserted by any undo/redo operation -- TODO: coalesce multiple similar operations -- cgit 1.4.1-2-gfad0