diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 95919a70..7787054c 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -67,6 +67,7 @@ local function cut_or_copy(delete) doc().cursor_clipboard[idx] = "" end end + doc().cursor_clipboard["full"] = full_text system.set_clipboard(full_text) end @@ -99,8 +100,13 @@ local commands = { end, ["doc:paste"] = function() + local clipboard = system.get_clipboard() + -- If the clipboard has changed since our last look, use that instead + if doc().cursor_clipboard["full"] ~= clipboard then + doc().cursor_clipboard = {} + end for idx, line1, col1, line2, col2 in doc():get_selections() do - local value = doc().cursor_clipboard[idx] or system.get_clipboard() + local value = doc().cursor_clipboard[idx] or clipboard doc():text_input(value:gsub("\r", ""), idx) end end, diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 52f2113c..d05d9d45 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -173,10 +173,12 @@ function Doc:merge_cursors(idx) if self.selections[i] == self.selections[j] and self.selections[i+1] == self.selections[j+1] then common.splice(self.selections, i, 4) + common.splice(self.cursor_clipboard, i, 1) break end end end + if #self.selections <= 4 then self.cursor_clipboard = {} end end local function selection_iterator(invariant, idx)