Correct paste after 'Cut/copy whole line'

This commit is contained in:
Jipok 2021-12-06 17:48:30 +05:00
parent 93d9e61a03
commit acc7ceefd4
2 changed files with 18 additions and 7 deletions

View File

@ -52,12 +52,15 @@ local function cut_or_copy(delete)
if line1 ~= line2 or col1 ~= col2 then
text = doc():get_text(line1, col1, line2, col2)
full_text = full_text == "" and text or (full_text .. "\n" .. text)
doc().cursor_clipboard_whole_line[idx] = false
if delete then
doc():delete_to_cursor(idx, 0)
end
else
text = "\n" .. doc().lines[line1]:gsub("\n", "")
else -- Cut/copy whole line
text = doc().lines[line1]
full_text = full_text == "" and text or (full_text .. text)
doc().cursor_clipboard_whole_line[idx] = true
core.lines_in_clipboard = full_text
if delete then
if line1 < #doc().lines then
doc():remove(line1, 1, line1 + 1, 1)
@ -122,11 +125,18 @@ local commands = {
-- If the clipboard has changed since our last look, use that instead
if doc().cursor_clipboard["full"] ~= clipboard then
doc().cursor_clipboard = {}
doc().cursor_clipboard_whole_line = {}
end
for idx, line1, col1, line2, col2 in doc():get_selections() do
local value = doc().cursor_clipboard[idx] or clipboard
if doc().cursor_clipboard_whole_line[idx] == true then
doc():insert(line1, 1, value:gsub("\r", ""))
elseif (core.lines_in_clipboard == clipboard) and (not doc().cursor_clipboard[idx]) then
doc():insert(line1, 1, clipboard:gsub("\r", ""))
else
doc():text_input(value:gsub("\r", ""), idx)
end
end
end,
["doc:newline"] = function()

View File

@ -34,6 +34,7 @@ function Doc:reset()
self.lines = { "\n" }
self.selections = { 1, 1, 1, 1 }
self.cursor_clipboard = {}
self.cursor_clipboard_whole_line = {}
self.undo_stack = { idx = 1 }
self.redo_stack = { idx = 1 }
self.clean_change_id = 1