Added in multiple clipboard line buffers.
This commit is contained in:
parent
a7f39017ff
commit
08ab6cba05
|
@ -45,7 +45,6 @@ local function append_line_if_last_line(line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function save(filename)
|
local function save(filename)
|
||||||
doc():save(filename and core.normalize_to_project_dir(filename))
|
doc():save(filename and core.normalize_to_project_dir(filename))
|
||||||
local saved_filename = doc().filename
|
local saved_filename = doc().filename
|
||||||
|
@ -63,22 +62,39 @@ local commands = {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:cut"] = function()
|
["doc:cut"] = function()
|
||||||
if doc():has_selection() then
|
local full_text = ""
|
||||||
local text = doc():get_text(doc():get_selection())
|
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
||||||
system.set_clipboard(text)
|
if line1 ~= line2 or col1 ~= col2 then
|
||||||
doc():delete_to(0)
|
local text = doc():get_text(line1, col1, line2, col2)
|
||||||
|
doc():delete_to(idx, 0)
|
||||||
|
full_text = full_text == "" and text or (full_text .. "\n" .. text)
|
||||||
|
doc():set_cursor_clipboard(idx, text)
|
||||||
|
else
|
||||||
|
doc():set_cursor_clipboard(idx, "")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
system.set_clipboard(full_text)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:copy"] = function()
|
["doc:copy"] = function()
|
||||||
if doc():has_selection() then
|
local full_text = ""
|
||||||
local text = doc():get_text(doc():get_selection())
|
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
||||||
system.set_clipboard(text)
|
if line1 ~= line2 or col1 ~= col2 then
|
||||||
|
local text = doc():get_text(line1, col1, line2, col2)
|
||||||
|
full_text = full_text == "" and text or (full_text .. "\n" .. text)
|
||||||
|
doc():set_cursor_clipboard(idx, text)
|
||||||
|
else
|
||||||
|
doc():set_cursor_clipboard(idx, "")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
system.set_clipboard(full_text)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:paste"] = function()
|
["doc:paste"] = function()
|
||||||
doc():text_input(system.get_clipboard():gsub("\r", ""))
|
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
||||||
|
local value = doc():get_cursor_clipboard(idx) or system.get_clipboard()
|
||||||
|
doc():text_input(value:gsub("\r", ""), idx)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:newline"] = function()
|
["doc:newline"] = function()
|
||||||
|
|
|
@ -47,6 +47,7 @@ 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.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
|
||||||
|
@ -126,6 +127,12 @@ function Doc:get_change_id()
|
||||||
return self.undo_stack.idx
|
return self.undo_stack.idx
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Doc:get_cursor_clipboard(idx)
|
||||||
|
return self.cursor_clipboard[idx]
|
||||||
|
end
|
||||||
|
function Doc:set_cursor_clipboard(idx, value)
|
||||||
|
self.cursor_clipboard[idx] = value
|
||||||
|
end
|
||||||
|
|
||||||
function Doc:set_selection(line1, col1, line2, col2, swap)
|
function Doc:set_selection(line1, col1, line2, col2, swap)
|
||||||
assert(not line2 == not col2, "expected 2 or 4 arguments")
|
assert(not line2 == not col2, "expected 2 or 4 arguments")
|
||||||
|
@ -133,6 +140,7 @@ function Doc:set_selection(line1, col1, line2, col2, swap)
|
||||||
line1, col1 = self:sanitize_position(line1, col1)
|
line1, col1 = self:sanitize_position(line1, col1)
|
||||||
line2, col2 = self:sanitize_position(line2 or line1, col2 or col1)
|
line2, col2 = self:sanitize_position(line2 or line1, col2 or col1)
|
||||||
self.selections = { line1, col1, line2, col2 }
|
self.selections = { line1, col1, line2, col2 }
|
||||||
|
self.cursor_clipboard = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Doc:set_selections(idx, line1, col1, line2, col2, swap)
|
function Doc:set_selections(idx, line1, col1, line2, col2, swap)
|
||||||
|
@ -171,7 +179,7 @@ function Doc:get_selection(sort)
|
||||||
return unpack(self.selections)
|
return unpack(self.selections)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Doc:get_selection_count()
|
function Doc:get_cursor_count()
|
||||||
return #self.selections / 4
|
return #self.selections / 4
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue