Skip to content

Commit 86fe0e1

Browse files
committed
restore cursor clipboards
1 parent d6477ed commit 86fe0e1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lua/multicursor-nvim/cursor-manager.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,7 @@ local function clearCursorContext()
17741774
state.errors = {}
17751775
state.jumpIdx = 0
17761776
state.yankedWhileDisabled = false
1777+
state.yankedWhileActive = false
17771778
unsetOptions()
17781779
unsetHlsearch()
17791780
state.yanked = false
@@ -2292,6 +2293,7 @@ function CursorManager:action(callback, opts)
22922293
end
22932294

22942295
if state.yanked then
2296+
state.yankedWhileActive = true
22952297
state.yanked = false
22962298
state.cursors[#state.cursors + 1] = state.mainCursor
22972299
table.sort(state.cursors, compareCursorsPosition)
@@ -2310,6 +2312,25 @@ function CursorManager:action(callback, opts)
23102312
then
23112313
state.yankedWhileDisabled = true
23122314
end
2315+
elseif not state.yankedWhileActive then
2316+
--- @type mc.StateHistoryItem
2317+
local item = state.stateHistory[historyItemId()]
2318+
if item then
2319+
local oldCursors = tbl.shallow_copy(item.cursors)
2320+
local newCursors = tbl.shallow_copy(state.cursors)
2321+
newCursors[#newCursors + 1] = state.mainCursor
2322+
oldCursors[#oldCursors + 1] = item.cursor
2323+
table.sort(newCursors, compareCursorsPosition)
2324+
table.sort(oldCursors, compareCursorsPosition)
2325+
for i, oldCursor in ipairs(oldCursors) do
2326+
local newCursor = newCursors[i]
2327+
if not newCursor then
2328+
break
2329+
end
2330+
newCursor._register = oldCursor._register
2331+
end
2332+
vim.fn.setreg("", state.mainCursor._register)
2333+
end
23132334
end
23142335

23152336
cursorContextUpdate(not opts.excludeMainCursor)

0 commit comments

Comments
 (0)