Skip to content

Commit 63e56b9

Browse files
committed
exclusive selection fixes
1 parent 537ac4f commit 63e56b9

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lua/multicursor-nvim/cursor-manager.lua

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,11 +1411,18 @@ function Cursor:getVisualLines()
14111411
type = info.enterVisualKey,
14121412
exclusive = exclusive
14131413
})
1414-
if info.type == "c" and not exclusive then
1415-
local lastPos = compareMarkPos(pos, vPos) and vPos or pos
1416-
local lastCol = vim.fn.col({lastPos[2], "$"})
1417-
if lastCol == lastPos[3] then
1418-
table.insert(lines, "")
1414+
if info.type == "c" then
1415+
if exclusive then
1416+
local vs, ve = self:getVisual()
1417+
if vs[1] < ve[1] and ve[2] == 1 then
1418+
table.insert(lines, "")
1419+
end
1420+
else
1421+
local lastPos = compareMarkPos(pos, vPos) and vPos or pos
1422+
local lastCol = vim.fn.col({lastPos[2], "$"})
1423+
if lastCol == lastPos[3] then
1424+
table.insert(lines, "")
1425+
end
14191426
end
14201427
end
14211428
return lines

lua/multicursor-nvim/examples.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ local function addCursor(ctx, motion, opts)
236236
local startCol = vs[2] + colDiff
237237
local endRow = ve[1] + rowDiff
238238
local endCol = ve[2] + colDiff
239+
local lastLine = vim.fn.line("$")
240+
if endRow > lastLine then
241+
endRow = lastLine
242+
endCol = vim.fn.col({lastLine, "$"})
243+
end
239244
if oldMode == "V" or oldMode == "S" then
240245
startCol = vs[2]
241246
endCol = ve[2]
@@ -571,17 +576,15 @@ local function matchAddCursor(direction, add)
571576
searchWord = true
572577
mainCursor:feedkeys('"_yiw')
573578
end
574-
elseif vim.o.selection == "exclusive" then
575-
local vs, ve = mainCursor:getVisual()
576-
if vs[1] < ve[1] and ve[2] == 1 then
577-
mainCursor:feedkeys(TERM_CODES.BS)
578-
end
579579
end
580580
addCursor(ctx, function(cursor)
581581
local regex
582582
local hasSelection = cursor:hasSelection()
583583
if hasSelection then
584584
regex = "\\C\\V" .. escapeRegex(table.concat(cursor:getVisualLines(), "\n"))
585+
if vim.o.selection == "exclusive" then
586+
regex = regex .. "\\v.*\\n"
587+
end
585588
if cursor:mode() == "V" or cursor:mode() == "S" then
586589
cursor:feedkeys(cursor:atVisualStart() and "0" or "o0")
587590
elseif not cursor:atVisualStart() then

0 commit comments

Comments
 (0)