diff --git a/PSReadLine/ReadLine.vi.cs b/PSReadLine/ReadLine.vi.cs index 4d304a7..ccb52e7 100644 --- a/PSReadLine/ReadLine.vi.cs +++ b/PSReadLine/ReadLine.vi.cs @@ -722,36 +722,25 @@ namespace Microsoft.PowerShell /// public static void DeleteLine(ConsoleKeyInfo? key = null, object arg = null) { - if (_singleton.LineIsMultiLine()) + var lineCount = _singleton.GetLogicalLineCount(); + var lineIndex = _singleton.GetLogicalLineNumber() - 1; + + TryGetArgAsInt(arg, out var requestedLineCount, 1); + + var deletePosition = DeleteLineImpl(lineIndex, requestedLineCount); + + // goto the first character of the first remaining logical line + var newCurrent = deletePosition + 1; + + if (lineIndex + requestedLineCount >= lineCount) { - var lineCount = _singleton.GetLogicalLineCount(); - var lineIndex = _singleton.GetLogicalLineNumber() - 1; - - TryGetArgAsInt(arg, out var requestedLineCount, 1); - - var deletePosition = DeleteLineImpl(lineIndex, requestedLineCount); - - // goto the first character of the first remaining logical line - var newCurrent = deletePosition + 1; - - if (lineIndex + requestedLineCount >= lineCount) - { - // if the delete operation has removed all the remaining lines - // goto the first character of the previous logical line - newCurrent = GetBeginningOfLinePos(deletePosition); - } - - _singleton._current = newCurrent; - _singleton.Render(); - } - else - { - _clipboard.Record(_singleton._buffer); - _singleton.SaveEditItem(EditItemDelete.Create(_clipboard, 0)); - _singleton._current = 0; - _singleton._buffer.Remove(0, _singleton._buffer.Length); - _singleton.Render(); + // if the delete operation has removed all the remaining lines + // goto the first character of the previous logical line + newCurrent = GetBeginningOfLinePos(deletePosition); } + + _singleton._current = newCurrent; + _singleton.Render(); } /// diff --git a/test/YankPasteTest.VI.cs b/test/YankPasteTest.VI.cs index 0a2850a..590f04b 100644 --- a/test/YankPasteTest.VI.cs +++ b/test/YankPasteTest.VI.cs @@ -48,11 +48,13 @@ namespace Test { TestSetup(KeyMode.Vi); + var continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length; + Test("abcd", Keys( "abcd", _.Escape, "dd", CheckThat(() => AssertLineIs("")), CheckThat(() => AssertCursorLeftIs(0)), - 'p', CheckThat(() => AssertLineIs("abcd")), CheckThat(() => AssertCursorLeftIs(3)), - 'P', CheckThat(() => AssertLineIs("abcabcdd")), CheckThat(() => AssertCursorLeftIs(6)), + 'p', CheckThat(() => AssertLineIs("\nabcd")), CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0)), + 'P', CheckThat(() => AssertLineIs("\nabcd\nabcd")), CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0)), "uuu" )); @@ -204,12 +206,14 @@ namespace Test { TestSetup(KeyMode.Vi); + var continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length; + Test("abc def", Keys( "abc def", _.Escape, "dd", CheckThat(() => AssertLineIs("")), CheckThat(() => AssertCursorLeftIs(0)), - 'p', CheckThat(() => AssertLineIs("abc def")), CheckThat(() => AssertCursorLeftIs(6)), + 'p', CheckThat(() => AssertLineIs("\nabc def")), CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0)), "dd", CheckThat(() => AssertLineIs("")), CheckThat(() => AssertCursorLeftIs(0)), - 'P', CheckThat(() => AssertLineIs("abc def")), CheckThat(() => AssertCursorLeftIs(6)), + 'P', CheckThat(() => AssertLineIs("abc def\n")), CheckThat(() => AssertCursorLeftIs(0)), "uuuu" )); }