From 352edb9c6278959579272fa6ab4c794f35b92527 Mon Sep 17 00:00:00 2001 From: Maxime Labelle Date: Mon, 7 Dec 2020 20:37:10 +0100 Subject: [PATCH] Use 'd^' to delete from the first non-blank character of a logical line (#2001) --- PSReadLine/PSReadLineResources.resx | 2 +- PSReadLine/ReadLine.vi.cs | 9 +-------- test/BasicEditingTest.VI.cs | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/PSReadLine/PSReadLineResources.resx b/PSReadLine/PSReadLineResources.resx index 5cf93c53..76f70996 100644 --- a/PSReadLine/PSReadLineResources.resx +++ b/PSReadLine/PSReadLineResources.resx @@ -476,7 +476,7 @@ If there are other parse errors, unresolved commands, or incorrect parameters, s Switches to insert mode after positioning the cursor past the end of the line. - Deletes all of the line except for leading whitespace. + Deletes from the first non blank character of the current logical line in a multiline buffer. Replaces the character in front of the cursor. diff --git a/PSReadLine/ReadLine.vi.cs b/PSReadLine/ReadLine.vi.cs index fc3c20de..c4093e3f 100644 --- a/PSReadLine/ReadLine.vi.cs +++ b/PSReadLine/ReadLine.vi.cs @@ -722,14 +722,7 @@ public static void DeleteLineToFirstChar(ConsoleKeyInfo? key = null, object arg { if (_singleton._current > 0) { - int i = 0; - for (; i < _singleton._current; i++) - { - if (!Char.IsWhiteSpace(_singleton._buffer[i])) - { - break; - } - } + var i = GetFirstNonBlankOfLogicalLinePos(_singleton._current); _singleton.SaveToClipboard(i, _singleton._current - i); _singleton.SaveEditItem(EditItemDelete.Create(_clipboard, i, DeleteLineToFirstChar)); diff --git a/test/BasicEditingTest.VI.cs b/test/BasicEditingTest.VI.cs index c68bac26..96719a0f 100644 --- a/test/BasicEditingTest.VI.cs +++ b/test/BasicEditingTest.VI.cs @@ -549,6 +549,25 @@ public void ViDeleteToEnd() )); } + [SkippableFact] + public void ViDeleteLineToFirstChar() + { + TestSetup(KeyMode.Vi); + + int continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length; + + Test("\"\n some spaces\n\"", Keys( + _.DQuote, _.Enter, + " this is a line with some spaces", _.Enter, + _.DQuote, _.Escape, + "k6W", + CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 23)), + // delete from first non blank of line + "d^", + CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 3)) + )); + } + [SkippableFact] public void ViDeleteNextLines() {