Added in the ability to iterate through cursors backwards.
This commit is contained in:
parent
dfc57bd884
commit
b5cbe3a2fb
|
@ -118,7 +118,7 @@ local commands = {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:newline-below"] = function()
|
["doc:newline-below"] = function()
|
||||||
for idx, line in doc():get_selections() do
|
for idx, line in doc():get_selections(false, true) do
|
||||||
local indent = doc().lines[line]:match("^[\t ]*")
|
local indent = doc().lines[line]:match("^[\t ]*")
|
||||||
doc():insert(line, math.huge, "\n" .. indent)
|
doc():insert(line, math.huge, "\n" .. indent)
|
||||||
doc():set_selections(idx, line + 1, math.huge)
|
doc():set_selections(idx, line + 1, math.huge)
|
||||||
|
@ -126,7 +126,7 @@ local commands = {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:newline-above"] = function()
|
["doc:newline-above"] = function()
|
||||||
for idx, line in doc():get_selections() do
|
for idx, line in doc():get_selections(false, true) do
|
||||||
local indent = doc().lines[line]:match("^[\t ]*")
|
local indent = doc().lines[line]:match("^[\t ]*")
|
||||||
doc():insert(line, 1, indent .. "\n")
|
doc():insert(line, 1, indent .. "\n")
|
||||||
doc():set_selections(idx, line, math.huge)
|
doc():set_selections(idx, line, math.huge)
|
||||||
|
|
|
@ -172,17 +172,17 @@ function Doc:merge_cursors(idx)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function selection_iterator(invariant, idx)
|
local function selection_iterator(invariant, idx)
|
||||||
local target = invariant[3] and (#invariant[1] - 3 - idx * 4) or (idx*4 + 1)
|
local target = invariant[3] and (idx*4 - 7) or (idx*4 + 1)
|
||||||
if idx * 4 >= #invariant[1] then return end
|
if target > #invariant[1] or target <= 0 then return end
|
||||||
if invariant[2] then
|
if invariant[2] then
|
||||||
return idx+1, sort_positions(unpack(invariant[1], target, target+4))
|
return idx+(invariant[3] and -1 or 1), sort_positions(unpack(invariant[1], target, target+4))
|
||||||
else
|
else
|
||||||
return idx+1, unpack(invariant[1], target, target+4)
|
return idx+(invariant[3] and -1 or 1), unpack(invariant[1], target, target+4)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Doc:get_selections(sort_intra, reverse)
|
function Doc:get_selections(sort_intra, reverse)
|
||||||
return selection_iterator, { self.selections, sort_intra, reverse }, 0
|
return selection_iterator, { self.selections, sort_intra, reverse }, reverse and (#self.selections / 4) + 1 or 0
|
||||||
end
|
end
|
||||||
-- End of cursor seciton.
|
-- End of cursor seciton.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue