Skip to content

Commit 0e00ce4

Browse files
committed
simplify
1 parent a9dc308 commit 0e00ce4

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

lua/multicursor-nvim/examples.lua

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -712,26 +712,15 @@ end
712712
--- @param regex string
713713
local function regexAddAllCursors(ctx, regex)
714714
local mainCursor = ctx:mainCursor()
715-
if mainCursor:hasSelection() then
716-
mainCursor:feedkeys(TERM_CODES.ESC)
717-
end
718-
local positions = {}
719-
local nPositions = 0
720-
while true do
715+
mainCursor:setMode("n")
716+
vim.fn.search(regex)
717+
local firstPos = vim.fn.getcurpos()
718+
local pos = firstPos
719+
repeat
720+
mainCursor:clone():setPos({ pos[2], pos[3] })
721721
vim.fn.search(regex)
722-
local pos = vim.fn.getcurpos()
723-
nPositions = nPositions + 1
724-
positions[nPositions] = { pos[2], pos[3] }
725-
if nPositions > 1
726-
and positions[1][1] == positions[nPositions][1]
727-
and positions[1][2] == positions[nPositions][2]
728-
then
729-
break
730-
end
731-
end
732-
for _, position in ipairs(positions) do
733-
mainCursor:clone():setPos(position)
734-
end
722+
pos = vim.fn.getcurpos()
723+
until firstPos[2] == pos[2] and firstPos[3] == pos[3]
735724
mainCursor:delete()
736725
end
737726

@@ -755,9 +744,6 @@ function examples.searchAllAddCursors()
755744
return
756745
end
757746
mc.action(function(ctx)
758-
if ctx:mainCursor():hasSelection() then
759-
ctx:mainCursor():feedkeys(TERM_CODES.ESC)
760-
end
761747
regexAddAllCursors(ctx, regex)
762748
end)
763749
end

0 commit comments

Comments
 (0)