Skip to content

Commit 06aec2c

Browse files
springcompdaxian-dbw
authored andcommitted
Fix y$ to yank to the end of the logical line instead of to the end of the whole buffer. (#1168)
1 parent 4576a77 commit 06aec2c

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

PSReadLine/YankPaste.vi.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,13 @@ public static void ViYankLeft(ConsoleKeyInfo? key = null, object arg = null)
137137
/// </summary>
138138
public static void ViYankToEndOfLine(ConsoleKeyInfo? key = null, object arg = null)
139139
{
140-
int start = _singleton._current;
141-
int length = _singleton._buffer.Length - _singleton._current;
142-
_singleton.SaveToClipboard(start, length);
140+
var start = _singleton._current;
141+
var end = GetEndOfLogicalLinePos(_singleton._current);
142+
var length = end - start + 1;
143+
if (length > 0)
144+
{
145+
_clipboard.Record(_singleton._buffer, start, length);
146+
}
143147
}
144148

145149
/// <summary>

test/YankPasteTest.VI.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,24 @@ public void ViPasteAfterYankBeginningOfLine()
337337
));
338338
}
339339

340+
[SkippableFact]
341+
public void ViPasteAfterYankEndOfLine()
342+
{
343+
TestSetup(KeyMode.Vi);
344+
345+
var continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;
346+
347+
Test("\"\nHello\nWorld!\n\"", Keys(
348+
_.DQuote, _.Enter,
349+
"Hello", _.Enter,
350+
"World!", _.Enter,
351+
_.DQuote, _.Escape,
352+
_.k, _.l, // move to the 'o' character of 'World!'
353+
"y$P", CheckThat(() => AssertLineIs("\"\nHello\nWorld!orld!\n\"")), CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 5)),
354+
"u"
355+
));
356+
}
357+
340358
[SkippableFact]
341359
public void ViPasteAfterYankFirstNoneBlank()
342360
{

0 commit comments

Comments
 (0)