Added in missing boolean.
This commit is contained in:
parent
75658b4f3f
commit
858f7a2a50
|
@ -55,7 +55,7 @@ local function cut_or_copy(delete)
|
||||||
if line1 ~= line2 or col1 ~= col2 then
|
if line1 ~= line2 or col1 ~= col2 then
|
||||||
local text = doc():get_text(line1, col1, line2, col2)
|
local text = doc():get_text(line1, col1, line2, col2)
|
||||||
if delete then
|
if delete then
|
||||||
doc():delete_to(idx, 0)
|
doc():delete_to(0)
|
||||||
end
|
end
|
||||||
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[idx] = text
|
doc().cursor_clipboard[idx] = text
|
||||||
|
@ -66,6 +66,25 @@ local function cut_or_copy(delete)
|
||||||
system.set_clipboard(full_text)
|
system.set_clipboard(full_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function split_cursor(direction)
|
||||||
|
local new_cursors = {}
|
||||||
|
for _, line1, col1 in doc():get_selections() do
|
||||||
|
local exists = false
|
||||||
|
for _, line2, col2 in doc():get_selections() do
|
||||||
|
if line1+direction == line2 and col1 == col2 then
|
||||||
|
exists = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not exists and line1 > 1 and line1 < #doc().lines then
|
||||||
|
table.insert(new_cursors, { line1 - 1, col1 })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i,v in ipairs(new_cursors) do
|
||||||
|
doc():set_selections(#doc().selections/4 + 1, v[1], v[2])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local commands = {
|
local commands = {
|
||||||
["doc:undo"] = function()
|
["doc:undo"] = function()
|
||||||
doc():undo()
|
doc():undo()
|
||||||
|
@ -121,7 +140,7 @@ local commands = {
|
||||||
if line1 == line2 and col1 == col2 and doc().lines[line1]:find("^%s*$", col1) then
|
if line1 == line2 and col1 == col2 and doc().lines[line1]:find("^%s*$", col1) then
|
||||||
doc():remove(line1, col1, line1, math.huge)
|
doc():remove(line1, col1, line1, math.huge)
|
||||||
end
|
end
|
||||||
doc():delete_to(idx, translate.next_char)
|
doc():delete_to_cursor(idx, translate.next_char)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
@ -130,11 +149,11 @@ local commands = {
|
||||||
if line1 == line2 and col1 == col2 then
|
if line1 == line2 and col1 == col2 then
|
||||||
local text = doc():get_text(line1, 1, line1, col1)
|
local text = doc():get_text(line1, 1, line1, col1)
|
||||||
if #text >= config.indent_size and text:find("^ *$") then
|
if #text >= config.indent_size and text:find("^ *$") then
|
||||||
doc():delete_to(idx, 0, -config.indent_size)
|
doc():delete_to_cursor(idx, 0, -config.indent_size)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
doc():delete_to(idx, translate.previous_char)
|
doc():delete_to_cursor(idx, translate.previous_char)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
@ -146,6 +165,16 @@ local commands = {
|
||||||
local line, col = doc():get_selection()
|
local line, col = doc():get_selection()
|
||||||
doc():set_selection(line, col)
|
doc():set_selection(line, col)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
||||||
|
["doc:indent"] = function()
|
||||||
|
for idx, line1, col1, line2, col2 in doc_multiline_selections(true) do
|
||||||
|
local l1, c1, l2, c2 = doc():indent_text(false, line1, col1, line2, col2)
|
||||||
|
if l1 then
|
||||||
|
doc():set_selections(idx, l1, c1, l2, c2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
["doc:select-lines"] = function()
|
["doc:select-lines"] = function()
|
||||||
for idx, line1, _, line2 in doc():get_selections(true) do
|
for idx, line1, _, line2 in doc():get_selections(true) do
|
||||||
|
@ -366,6 +395,15 @@ local commands = {
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
core.log("Removed \"%s\"", filename)
|
core.log("Removed \"%s\"", filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
["doc:create-cursor-previous-line"] = function()
|
||||||
|
split_cursor(-1)
|
||||||
|
end,
|
||||||
|
|
||||||
|
["doc:create-cursor-next-line"] = function()
|
||||||
|
split_cursor(1)
|
||||||
|
end,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -389,9 +427,9 @@ local translations = {
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, fn in pairs(translations) do
|
for name, fn in pairs(translations) do
|
||||||
commands["doc:move-to-" .. name] = function() doc():move_to(nil, fn, dv()) end
|
commands["doc:move-to-" .. name] = function() doc():move_to(fn, dv()) end
|
||||||
commands["doc:select-to-" .. name] = function() doc():select_to(nil, fn, dv()) end
|
commands["doc:select-to-" .. name] = function() doc():select_to(fn, dv()) end
|
||||||
commands["doc:delete-to-" .. name] = function() doc():delete_to(nil, fn, dv()) end
|
commands["doc:delete-to-" .. name] = function() doc():delete_to(fn, dv()) end
|
||||||
end
|
end
|
||||||
|
|
||||||
commands["doc:move-to-previous-char"] = function()
|
commands["doc:move-to-previous-char"] = function()
|
||||||
|
@ -400,7 +438,7 @@ commands["doc:move-to-previous-char"] = function()
|
||||||
doc():set_selections(idx, line1, col1)
|
doc():set_selections(idx, line1, col1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
doc():move_to(nil, translate.previous_char)
|
doc():move_to(translate.previous_char)
|
||||||
end
|
end
|
||||||
|
|
||||||
commands["doc:move-to-next-char"] = function()
|
commands["doc:move-to-next-char"] = function()
|
||||||
|
@ -409,7 +447,7 @@ commands["doc:move-to-next-char"] = function()
|
||||||
doc():set_selections(idx, line2, col2)
|
doc():set_selections(idx, line2, col2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
doc():move_to(nil, translate.next_char)
|
doc():move_to(translate.next_char)
|
||||||
end
|
end
|
||||||
|
|
||||||
command.add("core.docview", commands)
|
command.add("core.docview", commands)
|
||||||
|
|
|
@ -130,7 +130,7 @@ end
|
||||||
|
|
||||||
function Doc:get_selection(sort)
|
function Doc:get_selection(sort)
|
||||||
local idx, line1, col1, line2, col2 = self:get_selections(sort)(self.selections, 0)
|
local idx, line1, col1, line2, col2 = self:get_selections(sort)(self.selections, 0)
|
||||||
return line1, col1, line2, col2
|
return line1, col1, line2, col2, sort
|
||||||
end
|
end
|
||||||
|
|
||||||
function Doc:get_selections(sort)
|
function Doc:get_selections(sort)
|
||||||
|
@ -342,10 +342,10 @@ function Doc:text_input(text, idx)
|
||||||
for sidx, line1, col1, line2, col2 in self:get_selections() do
|
for sidx, line1, col1, line2, col2 in self:get_selections() do
|
||||||
if not idx or idx == sidx then
|
if not idx or idx == sidx then
|
||||||
if line1 ~= line2 or col1 ~= col2 then
|
if line1 ~= line2 or col1 ~= col2 then
|
||||||
self:delete_to(sidx)
|
self:delete_to_cursor(sidx)
|
||||||
end
|
end
|
||||||
self:insert(line1, col1, text)
|
self:insert(line1, col1, text)
|
||||||
self:move_to(sidx, #text)
|
self:move_to_cursor(sidx, #text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -370,7 +370,7 @@ function Doc:replace(fn)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function Doc:delete_to(idx, ...)
|
function Doc:delete_to_cursor(idx, ...)
|
||||||
for sidx, line1, col1, line2, col2 in self:get_selections(true) do
|
for sidx, line1, col1, line2, col2 in self:get_selections(true) do
|
||||||
if not idx or sidx == idx then
|
if not idx or sidx == idx then
|
||||||
if line1 ~= line2 or col1 ~= col2 then
|
if line1 ~= line2 or col1 ~= col2 then
|
||||||
|
@ -384,18 +384,19 @@ function Doc:delete_to(idx, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function Doc:delete_to(...) return self:delete_to(nil, ...) end
|
||||||
|
|
||||||
|
function Doc:move_to_cursor(idx, ...)
|
||||||
function Doc:move_to(idx, ...)
|
|
||||||
for sidx, line, col in self:get_selections() do
|
for sidx, line, col in self:get_selections() do
|
||||||
if not idx or sidx == idx then
|
if not idx or sidx == idx then
|
||||||
self:set_selections(sidx, self:position_offset(line, col, ...))
|
self:set_selections(sidx, self:position_offset(line, col, ...))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function Doc:move_to(...) return self:move_to_cursor(nil, ...) end
|
||||||
|
|
||||||
|
|
||||||
function Doc:select_to(idx, ...)
|
function Doc:select_to_cursor(idx, ...)
|
||||||
for sidx, line, col, line2, col2 in self:get_selections() do
|
for sidx, line, col, line2, col2 in self:get_selections() do
|
||||||
if not idx or idx == sidx then
|
if not idx or idx == sidx then
|
||||||
line, col = self:position_offset(line, col, ...)
|
line, col = self:position_offset(line, col, ...)
|
||||||
|
@ -403,6 +404,7 @@ function Doc:select_to(idx, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function Doc:select_to(...) return self:select_to_cursor(nil, ...) end
|
||||||
|
|
||||||
|
|
||||||
local function get_indent_string()
|
local function get_indent_string()
|
||||||
|
|
|
@ -101,6 +101,8 @@ local function keymap_macos(keymap)
|
||||||
["cmd+shift+end"] = "doc:select-to-end-of-doc",
|
["cmd+shift+end"] = "doc:select-to-end-of-doc",
|
||||||
["shift+pageup"] = "doc:select-to-previous-page",
|
["shift+pageup"] = "doc:select-to-previous-page",
|
||||||
["shift+pagedown"] = "doc:select-to-next-page",
|
["shift+pagedown"] = "doc:select-to-next-page",
|
||||||
|
["cmd+shift+up"] = "doc:create-cursor-previous-line",
|
||||||
|
["cmd+shift+down"] = "doc:create-cursor-next-line"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -202,6 +202,8 @@ keymap.add_direct {
|
||||||
["ctrl+shift+end"] = "doc:select-to-end-of-doc",
|
["ctrl+shift+end"] = "doc:select-to-end-of-doc",
|
||||||
["shift+pageup"] = "doc:select-to-previous-page",
|
["shift+pageup"] = "doc:select-to-previous-page",
|
||||||
["shift+pagedown"] = "doc:select-to-next-page",
|
["shift+pagedown"] = "doc:select-to-next-page",
|
||||||
|
["ctrl+shift+up"] = "doc:create-cursor-previous-line",
|
||||||
|
["ctrl+shift+down"] = "doc:create-cursor-next-line"
|
||||||
}
|
}
|
||||||
|
|
||||||
return keymap
|
return keymap
|
||||||
|
|
Loading…
Reference in New Issue