Correct paste after 'Cut/copy whole line'
This commit is contained in:
parent
93d9e61a03
commit
acc7ceefd4
|
@ -52,12 +52,15 @@ local function cut_or_copy(delete)
|
||||||
if line1 ~= line2 or col1 ~= col2 then
|
if line1 ~= line2 or col1 ~= col2 then
|
||||||
text = doc():get_text(line1, col1, line2, col2)
|
text = doc():get_text(line1, col1, line2, col2)
|
||||||
full_text = full_text == "" and text or (full_text .. "\n" .. text)
|
full_text = full_text == "" and text or (full_text .. "\n" .. text)
|
||||||
|
doc().cursor_clipboard_whole_line[idx] = false
|
||||||
if delete then
|
if delete then
|
||||||
doc():delete_to_cursor(idx, 0)
|
doc():delete_to_cursor(idx, 0)
|
||||||
end
|
end
|
||||||
else
|
else -- Cut/copy whole line
|
||||||
text = "\n" .. doc().lines[line1]:gsub("\n", "")
|
text = doc().lines[line1]
|
||||||
full_text = full_text == "" and text or (full_text .. text)
|
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 delete then
|
||||||
if line1 < #doc().lines then
|
if line1 < #doc().lines then
|
||||||
doc():remove(line1, 1, line1 + 1, 1)
|
doc():remove(line1, 1, line1 + 1, 1)
|
||||||
|
@ -122,10 +125,17 @@ local commands = {
|
||||||
-- If the clipboard has changed since our last look, use that instead
|
-- If the clipboard has changed since our last look, use that instead
|
||||||
if doc().cursor_clipboard["full"] ~= clipboard then
|
if doc().cursor_clipboard["full"] ~= clipboard then
|
||||||
doc().cursor_clipboard = {}
|
doc().cursor_clipboard = {}
|
||||||
|
doc().cursor_clipboard_whole_line = {}
|
||||||
end
|
end
|
||||||
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
||||||
local value = doc().cursor_clipboard[idx] or clipboard
|
local value = doc().cursor_clipboard[idx] or clipboard
|
||||||
doc():text_input(value:gsub("\r", ""), idx)
|
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
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ function Doc:reset()
|
||||||
self.lines = { "\n" }
|
self.lines = { "\n" }
|
||||||
self.selections = { 1, 1, 1, 1 }
|
self.selections = { 1, 1, 1, 1 }
|
||||||
self.cursor_clipboard = {}
|
self.cursor_clipboard = {}
|
||||||
|
self.cursor_clipboard_whole_line = {}
|
||||||
self.undo_stack = { idx = 1 }
|
self.undo_stack = { idx = 1 }
|
||||||
self.redo_stack = { idx = 1 }
|
self.redo_stack = { idx = 1 }
|
||||||
self.clean_change_id = 1
|
self.clean_change_id = 1
|
||||||
|
@ -356,7 +357,7 @@ function Doc:raw_insert(line, col, text, undo_stack, time)
|
||||||
|
|
||||||
-- splice lines into line array
|
-- splice lines into line array
|
||||||
common.splice(self.lines, line, 1, lines)
|
common.splice(self.lines, line, 1, lines)
|
||||||
|
|
||||||
-- keep cursors where they should be
|
-- keep cursors where they should be
|
||||||
for idx, cline1, ccol1, cline2, ccol2 in self:get_selections(true, true) do
|
for idx, cline1, ccol1, cline2, ccol2 in self:get_selections(true, true) do
|
||||||
if cline1 < line then break end
|
if cline1 < line then break end
|
||||||
|
@ -388,7 +389,7 @@ function Doc:raw_remove(line1, col1, line2, col2, undo_stack, time)
|
||||||
|
|
||||||
-- splice line into line array
|
-- splice line into line array
|
||||||
common.splice(self.lines, line1, line2 - line1 + 1, { before .. after })
|
common.splice(self.lines, line1, line2 - line1 + 1, { before .. after })
|
||||||
|
|
||||||
-- move all cursors back if they share a line with the removed text
|
-- move all cursors back if they share a line with the removed text
|
||||||
for idx, cline1, ccol1, cline2, ccol2 in self:get_selections(true, true) do
|
for idx, cline1, ccol1, cline2, ccol2 in self:get_selections(true, true) do
|
||||||
if cline1 < line2 then break end
|
if cline1 < line2 then break end
|
||||||
|
@ -458,7 +459,7 @@ end
|
||||||
function Doc:replace(fn)
|
function Doc:replace(fn)
|
||||||
local has_selection, n = false, 0
|
local has_selection, n = false, 0
|
||||||
for idx, line1, col1, line2, col2 in self:get_selections(true) do
|
for idx, line1, col1, line2, col2 in self:get_selections(true) do
|
||||||
if line1 ~= line2 or col1 ~= col2 then
|
if line1 ~= line2 or col1 ~= col2 then
|
||||||
n = n + self:replace_cursor(idx, line1, col1, line2, col2, fn)
|
n = n + self:replace_cursor(idx, line1, col1, line2, col2, fn)
|
||||||
has_selection = true
|
has_selection = true
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue