Added in a hash check to the system clipboard.
This commit is contained in:
+21
-12
@@ -53,6 +53,18 @@ local function save(filename)
|
||||
core.log("Saved \"%s\"", saved_filename)
|
||||
end
|
||||
|
||||
|
||||
local function split_cursor(direction)
|
||||
local new_cursors = {}
|
||||
for _, line1, col1 in doc():get_selections() do
|
||||
if line1 > 1 and line1 < #doc().lines then
|
||||
table.insert(new_cursors, { line1 + direction, col1 })
|
||||
end
|
||||
end
|
||||
for i,v in ipairs(new_cursors) do doc():add_selection(v[1], v[2]) end
|
||||
core.blink_reset()
|
||||
end
|
||||
|
||||
local function cut_or_copy(delete)
|
||||
local full_text = ""
|
||||
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
||||
@@ -67,18 +79,10 @@ local function cut_or_copy(delete)
|
||||
doc().cursor_clipboard[idx] = ""
|
||||
end
|
||||
end
|
||||
system.set_clipboard(full_text)
|
||||
end
|
||||
|
||||
local function split_cursor(direction)
|
||||
local new_cursors = {}
|
||||
for _, line1, col1 in doc():get_selections() do
|
||||
if line1 > 1 and line1 < #doc().lines then
|
||||
table.insert(new_cursors, { line1 + direction, col1 })
|
||||
end
|
||||
if #doc().cursor_clipboard > 1 then
|
||||
doc().cursor_clipboard["hash"] = system.hash(system.get_clipboard())
|
||||
end
|
||||
for i,v in ipairs(new_cursors) do doc():add_selection(v[1], v[2]) end
|
||||
core.blink_reset()
|
||||
system.set_clipboard(full_text)
|
||||
end
|
||||
|
||||
local commands = {
|
||||
@@ -99,8 +103,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["hash"] ~= system.hash(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,
|
||||
|
||||
@@ -173,6 +173,7 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user