Skip to content

Commit

Permalink
Use 'd^' to delete from the first non-blank character of a logical li…
Browse files Browse the repository at this point in the history
…ne (#2001)
  • Loading branch information
springcomp authored Dec 7, 2020
1 parent a7fd34f commit 352edb9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion PSReadLine/PSReadLineResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ If there are other parse errors, unresolved commands, or incorrect parameters, s
<value>Switches to insert mode after positioning the cursor past the end of the line.</value>
</data>
<data name="DeleteLineToFirstCharDescription" xml:space="preserve">
<value>Deletes all of the line except for leading whitespace.</value>
<value>Deletes from the first non blank character of the current logical line in a multiline buffer.</value>
</data>
<data name="BackwardReplaceCharDescription" xml:space="preserve">
<value>Replaces the character in front of the cursor.</value>
Expand Down
9 changes: 1 addition & 8 deletions PSReadLine/ReadLine.vi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
19 changes: 19 additions & 0 deletions test/BasicEditingTest.VI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 352edb9

Please sign in to comment.