Skip to content

Fix visual-block delete clobbering the unnamed register - #57

Merged
ernestrc merged 5 commits into
unstablebuild:mainfrom
ikshantshukla123:fix-visual-block-delete-paste
Sep 15, 2026
Merged

ernestrc merged 5 commits into
unstablebuild:mainfrom
ikshantshukla123:fix-visual-block-delete-paste

Conversation

@ikshantshukla123

Copy link
Copy Markdown
Contributor

Visual-block d/x followed by p/P reinserted only the last row of
the block.

copySelectionForDelete writes the full block correctly, but the delete
runs one edit per row and each edit notifies the copy-on-delete
subscriber, which overwrites the register per row. The visual d/x
path now re-asserts the copied block once the delete completes, scoped
to block selections only. This also stops "_d on a block from touching
unnamed.

Fixes #1.

Regression test TestVisualBlockDeleteThenPaste (full-Vi level, where
the subscriber is installed): d then P, x then p, a ragged
block, and black-hole preservation : each checks register text, block
mode metadata, and the pasted buffer. The test fails on main with only
the last row in the register.

A block delete runs one edit per row, so re-assert the copied block after it completes.

Signed-off-by: ikshantshukla123 <[email protected]>
@codecov

codecov Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

A failing clipboard must not break the delete; it only skips the restore.

Signed-off-by: ikshantshukla123 <[email protected]>
@ikshantshukla123

ikshantshukla123 commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Note on scope: this resolves the two writer conflict in the visual d/x path (the explicit copy wins over the per row copyon delete writes) rather than restructuring the per row notifications in DeleteBlockContext/delClip. that keeps the blast radius to vi flows the structural fix (block transactions for usage subscribers) would also touch Repeater and fits better as a follow up if you want it? @ernestrc

@ernestrc

Copy link
Copy Markdown
Contributor

Thanks for taking this! I gave you the green light on your approach but upon reviewing your PR, I saw an approach that avoids the need to correct the contents of the unnamedRegister. delClip is installed with *Vi as a clipboard implementation, allowing us to intercept calls and it's currently used to make sure undo/redo deletes are not copied to the clipboard, as well as backspace deletes in insert mode.

We can add a new method to viHandler that then we can call in Vi.Copy:

type viHandler interface {
        ...
>>	copySuppressed() bool
}

Then set a boolean in viHandler that changes the return value of this new method, so while we're doing block operations in s/c visual selection, in handleVisualBlockChangeStart and d/x visual selection we don't call the underlying clipboard's Copy, preventing the clobbering.

From a maintainability's point of view, I'd rather avoid an undesired behavior than amending the outcome of it.

Suppress per-row clipboard writes so the explicit block copy is the only one that lands.

Signed-off-by: ikshantshukla123 <[email protected]>
@ikshantshukla123

Copy link
Copy Markdown
Contributor Author

Thanks for taking this! I gave you the green light on your approach but upon reviewing your PR, I saw an approach that avoids the need to correct the contents of the unnamedRegister. delClip is installed with *Vi as a clipboard implementation, allowing us to intercept calls and it's currently used to make sure undo/redo deletes are not copied to the clipboard, as well as backspace deletes in insert mode.

We can add a new method to viHandler that then we can call in Vi.Copy:

type viHandler interface {
        ...
>>	copySuppressed() bool
}

Then set a boolean in viHandler that changes the return value of this new method, so while we're doing block operations in s/c visual selection, in handleVisualBlockChangeStart and d/x visual selection we don't call the underlying clipboard's Copy, preventing the clobbering.

From a maintainability's point of view, I'd rather avoid an undesired behavior than amending the outcome of it.

Thanks for more clarity on requirment @ernestrc
Done switched to suppression as suggested copySuppressed() on the viHandler interface, held during the block deletes in visual d/x (block-scoped) and handleVisualBlockChangeStart, gated in Vi.Copy next to the existing guards. The save/restore and its error path test are gone; the regression test is unchanged and green, plus a small test pinning that block c leaves unnamed alone.

@ernestrc
ernestrc enabled auto-merge (squash) September 15, 2026 20:35
@ernestrc
ernestrc merged commit e34d2bc into unstablebuild:main Sep 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vi: visual-block delete then paste only reinserts the last row

2 participants