Skip to content

Commit c117b3f

Browse files
committed
select match with match cursors
1 parent 29f5290 commit c117b3f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lua/multicursor-nvim/examples.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ function examples.splitCursors(pattern)
5050
return
5151
end
5252
local vs, ve = cursor:getVisual()
53+
if cursor:mode() == "V" or cursor:mode() == "S" then
54+
vs[2] = 1
55+
ve[2] = vim.fn.col({ ve[1], "$" })
56+
end
5357
local last = vs
58+
cursor:setMode("v")
5459
for _, match in ipairs(matches) do
5560
local lines = vim.split(match.text, "\n", { plain = true })
5661
local startPos = {
@@ -101,14 +106,13 @@ function examples.matchCursors(pattern)
101106
})
102107
local vs = cursor:getVisual()
103108
for _, match in ipairs(matches) do
104-
if #match.text > 0 then
105-
local newCursor = cursor:clone()
106-
newCursor:setVisual(
107-
{ vs[1], vs[2] + match.byteidx + #match.text - 1 },
108-
{ vs[1], vs[2] + match.byteidx }
109-
)
110-
newCursor:setMode("n")
111-
end
109+
local newCursor = cursor:clone()
110+
newCursor:setMode("v")
111+
newCursor:setVisual(
112+
{ vs[1], vs[2] + match.byteidx },
113+
{ vs[1], vs[2] + match.byteidx
114+
+ math.max(0, #match.text - 1) }
115+
)
112116
end
113117
cursor:delete()
114118
end

0 commit comments

Comments
 (0)