Make cursor_clipboard globa, not per doc
This commit is contained in:
parent
acc7ceefd4
commit
4eee123eff
|
@ -48,19 +48,20 @@ end
|
||||||
local function cut_or_copy(delete)
|
local function cut_or_copy(delete)
|
||||||
local full_text = ""
|
local full_text = ""
|
||||||
local text = ""
|
local text = ""
|
||||||
|
core.cursor_clipboard = {}
|
||||||
|
core.cursor_clipboard_whole_line = {}
|
||||||
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
||||||
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 .. " " .. text)
|
||||||
doc().cursor_clipboard_whole_line[idx] = false
|
core.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 -- Cut/copy whole line
|
else -- Cut/copy whole line
|
||||||
text = doc().lines[line1]
|
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.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)
|
||||||
|
@ -69,9 +70,9 @@ local function cut_or_copy(delete)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
doc().cursor_clipboard[idx] = text
|
core.cursor_clipboard[idx] = text
|
||||||
end
|
end
|
||||||
doc().cursor_clipboard["full"] = full_text
|
core.cursor_clipboard["full"] = full_text
|
||||||
system.set_clipboard(full_text)
|
system.set_clipboard(full_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -123,16 +124,24 @@ local commands = {
|
||||||
["doc:paste"] = function()
|
["doc:paste"] = function()
|
||||||
local clipboard = system.get_clipboard()
|
local clipboard = system.get_clipboard()
|
||||||
-- 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 core.cursor_clipboard["full"] ~= clipboard then
|
||||||
doc().cursor_clipboard = {}
|
core.cursor_clipboard = {}
|
||||||
doc().cursor_clipboard_whole_line = {}
|
core.cursor_clipboard_whole_line = {}
|
||||||
end
|
end
|
||||||
|
local value, whole_line
|
||||||
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
|
if #core.cursor_clipboard_whole_line == (#doc().selections/4) then
|
||||||
if doc().cursor_clipboard_whole_line[idx] == true then
|
value = core.cursor_clipboard[idx]
|
||||||
|
whole_line = core.cursor_clipboard_whole_line[idx] == true
|
||||||
|
else
|
||||||
|
value = clipboard
|
||||||
|
whole_line = clipboard:find("\n") ~= nil
|
||||||
|
end
|
||||||
|
if whole_line then
|
||||||
doc():insert(line1, 1, value:gsub("\r", ""))
|
doc():insert(line1, 1, value:gsub("\r", ""))
|
||||||
elseif (core.lines_in_clipboard == clipboard) and (not doc().cursor_clipboard[idx]) then
|
if col1 == 1 then
|
||||||
doc():insert(line1, 1, clipboard:gsub("\r", ""))
|
doc():move_to_cursor(idx, #value)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
doc():text_input(value:gsub("\r", ""), idx)
|
doc():text_input(value:gsub("\r", ""), idx)
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,8 +33,6 @@ end
|
||||||
function Doc:reset()
|
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_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
|
||||||
|
@ -199,7 +197,7 @@ function Doc:add_selection(line1, col1, line2, col2, swap)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Doc:set_selection(line1, col1, line2, col2, swap)
|
function Doc:set_selection(line1, col1, line2, col2, swap)
|
||||||
self.selections, self.cursor_clipboard = {}, {}
|
self.selections = {}
|
||||||
self:set_selections(1, line1, col1, line2, col2, swap)
|
self:set_selections(1, line1, col1, line2, col2, swap)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -648,6 +648,8 @@ function core.init()
|
||||||
core.clip_rect_stack = {{ 0,0,0,0 }}
|
core.clip_rect_stack = {{ 0,0,0,0 }}
|
||||||
core.log_items = {}
|
core.log_items = {}
|
||||||
core.docs = {}
|
core.docs = {}
|
||||||
|
core.cursor_clipboard = {}
|
||||||
|
core.cursor_clipboard_whole_line = {}
|
||||||
core.window_mode = "normal"
|
core.window_mode = "normal"
|
||||||
core.threads = setmetatable({}, { __mode = "k" })
|
core.threads = setmetatable({}, { __mode = "k" })
|
||||||
core.blink_start = system.get_time()
|
core.blink_start = system.get_time()
|
||||||
|
|
Loading…
Reference in New Issue