explicitly state when operations manage undo

This commit is contained in:
Kartik K. Agaram 2024-08-31 19:01:33 -07:00
parent 95837a50f6
commit 2f2eeff1dd
3 changed files with 7 additions and 7 deletions

View File

@ -361,7 +361,7 @@ function edit.keychord_press(editor, chord, key)
-- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys)
(not 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 is_cursor_movement(key) then
Text.delete_selection(editor, editor.left, editor.right)
Text.delete_selection_and_record_undo_event(editor)
end
if editor.search_term then
if chord == 'escape' then
@ -432,7 +432,7 @@ function edit.keychord_press(editor, chord, key)
love.system.setClipboardText(s)
end
elseif chord == 'C-x' and cursor_on_screen then
local s = Text.cut_selection(editor, editor.left, editor.right)
local s = Text.cut_selection_and_record_undo_event(editor)
if s then
love.system.setClipboardText(s)
end

View File

@ -5,14 +5,14 @@ function edit.mouse_loc(editor)
return edit.to_loc(editor, mx, my)
end
function Text.cut_selection(editor)
function Text.cut_selection_and_record_undo_event(editor)
if editor.selection1.line == nil then return end
local result = Text.selection(editor)
Text.delete_selection(editor)
Text.delete_selection_and_record_undo_event(editor)
return result
end
function Text.delete_selection(editor)
function Text.delete_selection_and_record_undo_event(editor)
if editor.selection1.line == nil then return end
local minl,maxl = minmax(editor.selection1.line, editor.cursor.line)
local before = snapshot(editor, minl, maxl)

View File

@ -54,7 +54,7 @@ function Text.keychord_press(editor, chord)
elseif chord == 'backspace' then
if editor.cursor.mode == 'text' then
if editor.selection1.line then
Text.delete_selection(editor, editor.left, editor.right)
Text.delete_selection_and_record_undo_event(editor)
schedule_save(editor)
return
end
@ -114,7 +114,7 @@ function Text.keychord_press(editor, chord)
else
-- cursor in text line
if editor.selection1.line then
Text.delete_selection(editor, editor.left, editor.right)
Text.delete_selection_and_record_undo_event(editor)
schedule_save(editor)
return
end