Fix doc:create-cursor-previous/next-line with tabs (#1697)
* use DocView.translate to split cursor on previous/next line * use dv.doc instead of doc()
This commit is contained in:
parent
97717b4511
commit
2755117e2d
|
@ -93,11 +93,14 @@ local function cut_or_copy(delete)
|
||||||
system.set_clipboard(full_text)
|
system.set_clipboard(full_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function split_cursor(direction)
|
local function split_cursor(dv, direction)
|
||||||
local new_cursors = {}
|
local new_cursors = {}
|
||||||
for _, line1, col1 in doc():get_selections() do
|
local dv_translate = direction < 0
|
||||||
if line1 + direction >= 1 and line1 + direction <= #doc().lines then
|
and DocView.translate.previous_line
|
||||||
table.insert(new_cursors, { line1 + direction, col1 })
|
or DocView.translate.next_line
|
||||||
|
for _, line1, col1 in dv.doc:get_selections() do
|
||||||
|
if line1 + direction >= 1 and line1 + direction <= #dv.doc.lines then
|
||||||
|
table.insert(new_cursors, { dv_translate(dv.doc, line1, col1, dv) })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- add selections in the order that will leave the "last" added one as doc.last_selection
|
-- add selections in the order that will leave the "last" added one as doc.last_selection
|
||||||
|
@ -107,7 +110,7 @@ local function split_cursor(direction)
|
||||||
end
|
end
|
||||||
for i = start, stop, direction do
|
for i = start, stop, direction do
|
||||||
local v = new_cursors[i]
|
local v = new_cursors[i]
|
||||||
doc():add_selection(v[1], v[2])
|
dv.doc:add_selection(v[1], v[2])
|
||||||
end
|
end
|
||||||
core.blink_reset()
|
core.blink_reset()
|
||||||
end
|
end
|
||||||
|
@ -626,12 +629,12 @@ local commands = {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:create-cursor-previous-line"] = function(dv)
|
["doc:create-cursor-previous-line"] = function(dv)
|
||||||
split_cursor(-1)
|
split_cursor(dv, -1)
|
||||||
dv.doc:merge_cursors()
|
dv.doc:merge_cursors()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:create-cursor-next-line"] = function(dv)
|
["doc:create-cursor-next-line"] = function(dv)
|
||||||
split_cursor(1)
|
split_cursor(dv, 1)
|
||||||
dv.doc:merge_cursors()
|
dv.doc:merge_cursors()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue