Repository navigation
Keep register changes the user makes while a snippet is active - #1697
Merged
Merged
Conversation
The registers cached at the first tabstop jump were restored on every InsertLeave and at snippet teardown regardless of who last wrote them. Leaving a snippet with <Esc>, deleting a line with dd and then moving the cursor away tore the snippet down and reverted @" (and @1) to the yank from before the expansion. VimState now tracks the texts of the placeholders the snippet selected since the cache was taken. Only when @" holds one of them, i.e. when a select-mode placeholder replacement is what last wrote it, are the cached registers restored; anything else in @" was put there by the user and wins. The same check replaces the single "expected text" comparison that decided whether to refresh the cache at a jump. Fixes #1695
…er-register-changes # Conflicts: # ChangeLog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since #1636 the registers
@",@0,@-and@1-@9are cached at the first tabstop jump and restored on everyInsertLeaveand again at snippet teardown, so that a select-mode placeholder replacement (which deletes the placeholder text into@"and@-/@1) does not leak into the user's registers. The restore ran unconditionally. A user who yanked a line, expanded a snippet, left it with<Esc>, deleted a line withddand then moved the cursor away saw the teardown revert@"to the yank from before the expansion, throwing theddaway. The same happened on theInsertLeavepath for any register change made in normal mode while the snippet was still active.VimStatenow keeps the texts of the placeholders the snippet has selected since the cache was taken. Registers are restored only when@"currently holds one of those texts, i.e. when a placeholder replacement is what last wrote it. Anything else in@"was put there by the user and wins; the restore is skipped and teardown drops the cache as before. The comparison happens inside Vim (index([...], @")) so binary register contents never cross the Python boundary, and it is exact and case-sensitive, unlike the!=the old code used.The same check replaces the old single "text to expect" comparison that decided whether to refresh the cache at a jump. That comparison only knew the most recently selected placeholder, so typing over tabstop 1, jumping to tabstop 2 and back again re-cached the placeholder text as the "original" register state. Tracking every selected placeholder text closes that gap too.
Fixes #1695.