support undo of paste button

This commit is contained in:
Kartik K. Agaram 2023-12-01 20:22:27 -08:00
parent 2ff2692bb4
commit a3fdbaad6d
1 changed files with 15 additions and 2 deletions

View File

@ -1,7 +1,20 @@
paste_button = function(x, y, r)
return overflowable_button('paste', x, y, r,
function()
local state = Current_pane.editor_state
-- initial state for recording undo operation
local before_line = state.cursor1.line
local before = snapshot(state, before_line)
-- paste
local s = App.get_clipboard()
Text.insert_text(Current_pane.editor_state, s)
Text.insert_text(state, s)
-- record undo operation
record_undo_event(state,
{
before=before,
after=snapshot(
state, before_line,
state.cursor1.line)
})
end)
end
end