Skip to content

Commit 8d74e42

Browse files
authored
vi-mode: 'dd' now handles single line or multiline buffers consistently (#1694)
1 parent b1736f6 commit 8d74e42

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

PSReadLine/ReadLine.vi.cs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -722,36 +722,25 @@ public static void DeleteLineToFirstChar(ConsoleKeyInfo? key = null, object arg
722722
/// </summary>
723723
public static void DeleteLine(ConsoleKeyInfo? key = null, object arg = null)
724724
{
725-
if (_singleton.LineIsMultiLine())
726-
{
727-
var lineCount = _singleton.GetLogicalLineCount();
728-
var lineIndex = _singleton.GetLogicalLineNumber() - 1;
729-
730-
TryGetArgAsInt(arg, out var requestedLineCount, 1);
725+
var lineCount = _singleton.GetLogicalLineCount();
726+
var lineIndex = _singleton.GetLogicalLineNumber() - 1;
731727

732-
var deletePosition = DeleteLineImpl(lineIndex, requestedLineCount);
728+
TryGetArgAsInt(arg, out var requestedLineCount, 1);
733729

734-
// goto the first character of the first remaining logical line
735-
var newCurrent = deletePosition + 1;
730+
var deletePosition = DeleteLineImpl(lineIndex, requestedLineCount);
736731

737-
if (lineIndex + requestedLineCount >= lineCount)
738-
{
739-
// if the delete operation has removed all the remaining lines
740-
// goto the first character of the previous logical line
741-
newCurrent = GetBeginningOfLinePos(deletePosition);
742-
}
732+
// goto the first character of the first remaining logical line
733+
var newCurrent = deletePosition + 1;
743734

744-
_singleton._current = newCurrent;
745-
_singleton.Render();
746-
}
747-
else
735+
if (lineIndex + requestedLineCount >= lineCount)
748736
{
749-
_clipboard.Record(_singleton._buffer);
750-
_singleton.SaveEditItem(EditItemDelete.Create(_clipboard, 0));
751-
_singleton._current = 0;
752-
_singleton._buffer.Remove(0, _singleton._buffer.Length);
753-
_singleton.Render();
737+
// if the delete operation has removed all the remaining lines
738+
// goto the first character of the previous logical line
739+
newCurrent = GetBeginningOfLinePos(deletePosition);
754740
}
741+
742+
_singleton._current = newCurrent;
743+
_singleton.Render();
755744
}
756745

757746
/// <summary>

test/YankPasteTest.VI.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ public void ViPasteAfterDelete()
4848
{
4949
TestSetup(KeyMode.Vi);
5050

51+
var continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;
52+
5153
Test("abcd", Keys(
5254
"abcd", _.Escape,
5355
"dd", CheckThat(() => AssertLineIs("")), CheckThat(() => AssertCursorLeftIs(0)),
54-
'p', CheckThat(() => AssertLineIs("abcd")), CheckThat(() => AssertCursorLeftIs(3)),
55-
'P', CheckThat(() => AssertLineIs("abcabcdd")), CheckThat(() => AssertCursorLeftIs(6)),
56+
'p', CheckThat(() => AssertLineIs("\nabcd")), CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0)),
57+
'P', CheckThat(() => AssertLineIs("\nabcd\nabcd")), CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0)),
5658
"uuu"
5759
));
5860

@@ -204,12 +206,14 @@ public void ViPasteAfterDeleteLine()
204206
{
205207
TestSetup(KeyMode.Vi);
206208

209+
var continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;
210+
207211
Test("abc def", Keys(
208212
"abc def", _.Escape,
209213
"dd", CheckThat(() => AssertLineIs("")), CheckThat(() => AssertCursorLeftIs(0)),
210-
'p', CheckThat(() => AssertLineIs("abc def")), CheckThat(() => AssertCursorLeftIs(6)),
214+
'p', CheckThat(() => AssertLineIs("\nabc def")), CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0)),
211215
"dd", CheckThat(() => AssertLineIs("")), CheckThat(() => AssertCursorLeftIs(0)),
212-
'P', CheckThat(() => AssertLineIs("abc def")), CheckThat(() => AssertCursorLeftIs(6)),
216+
'P', CheckThat(() => AssertLineIs("abc def\n")), CheckThat(() => AssertCursorLeftIs(0)),
213217
"uuuu"
214218
));
215219
}

0 commit comments

Comments
 (0)