mirror of
https://github.com/PowerShell/PSReadLine
synced 2026-06-08 12:12:13 +00:00
vi-mode: 'dd' now handles single line or multiline buffers consistently (#1694)
This commit is contained in:
+17
-28
@@ -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>
|
||||
|
||||
@@ -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"
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user