Added in the ability to iterate through cursors backwards.

This commit is contained in:
Adam Harrison 2021-06-11 18:14:24 -04:00
parent dfc57bd884
commit b5cbe3a2fb
2 changed files with 7 additions and 7 deletions

View File

@ -118,7 +118,7 @@ local commands = {
end,
["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 ]*")
doc():insert(line, math.huge, "\n" .. indent)
doc():set_selections(idx, line + 1, math.huge)
@ -126,7 +126,7 @@ local commands = {
end,
["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 ]*")
doc():insert(line, 1, indent .. "\n")
doc():set_selections(idx, line, math.huge)

View File

@ -172,17 +172,17 @@ function Doc:merge_cursors(idx)
end
local function selection_iterator(invariant, idx)
local target = invariant[3] and (#invariant[1] - 3 - idx * 4) or (idx*4 + 1)
if idx * 4 >= #invariant[1] then return end
local target = invariant[3] and (idx*4 - 7) or (idx*4 + 1)
if target > #invariant[1] or target <= 0 then return end
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
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
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 of cursor seciton.