vi-mode: 'dd' now handles single line or multiline buffers consistently (#1694)

This commit is contained in:
Maxime Labelle
2020-07-26 10:25:14 -07:00
committed by GitHub
parent b1736f67d9
commit 8d74e42664
2 changed files with 25 additions and 32 deletions
+17 -28
View File
@@ -722,36 +722,25 @@ namespace Microsoft.PowerShell
/// </summary>
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();
}
/// <summary>
+8 -4
View File
@@ -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"
));
}