From 5c6e89c3dac82ab5c3adf8ec633097e16b001d4d Mon Sep 17 00:00:00 2001 From: springcomp Date: Tue, 1 Dec 2020 13:26:07 +0100 Subject: [PATCH 01/14] Fixes #1750 - 'd0' deletes to start of current logical line --- PSReadLine/BasicEditing.cs | 14 +++++++++----- PSReadLine/PSReadLineResources.resx | 2 +- test/BasicEditingTest.VI.cs | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/PSReadLine/BasicEditing.cs b/PSReadLine/BasicEditing.cs index e7236a21..91dcefc0 100644 --- a/PSReadLine/BasicEditing.cs +++ b/PSReadLine/BasicEditing.cs @@ -120,12 +120,16 @@ public static void ForwardDeleteLine(ConsoleKeyInfo? key = null, object arg = nu /// public static void BackwardDeleteLine(ConsoleKeyInfo? key = null, object arg = null) { - if (_singleton._current > 0) + var position = GetBeginningOfLinePos(_singleton._current); + + if (_singleton._current > position) { - _clipboard.Record(_singleton._buffer, 0, _singleton._current); - _singleton.SaveEditItem(EditItemDelete.Create(_clipboard, 0)); - _singleton._buffer.Remove(0, _singleton._current); - _singleton._current = 0; + var count = _singleton._current - position; + + _clipboard.Record(_singleton._buffer, position, count); + _singleton.SaveEditItem(EditItemDelete.Create(_clipboard, position, BackwardDeleteLine)); + _singleton._buffer.Remove(position, count); + _singleton._current = position; _singleton.Render(); } } diff --git a/PSReadLine/PSReadLineResources.resx b/PSReadLine/PSReadLineResources.resx index 76f70996..920a7ab3 100644 --- a/PSReadLine/PSReadLineResources.resx +++ b/PSReadLine/PSReadLineResources.resx @@ -130,7 +130,7 @@ Delete the character before the cursor - Delete text from the cursor to the start of the line + Delete text from the cursor to the start of the current logical line Move the text from the cursor to the beginning of the line to the kill ring diff --git a/test/BasicEditingTest.VI.cs b/test/BasicEditingTest.VI.cs index 42b66b74..c725ee49 100644 --- a/test/BasicEditingTest.VI.cs +++ b/test/BasicEditingTest.VI.cs @@ -570,6 +570,26 @@ public void ViDeleteToEnd() )); } + [SkippableFact] + public void ViBackwardDeleteLine() + { + TestSetup(KeyMode.Vi); + + int continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length; + + Test("\"\nsome words\n\"", Keys( + + _.DQuote, _.Enter, + " this is a line with some words", _.Enter, + _.DQuote, _.Escape, + "k6W", + CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 23)), + // delete from first non blank of line + "d0", + CheckThat(() => AssertCursorLeftIs(continuationPrefixLength)) + )); + } + [SkippableFact] public void ViDeleteLineToFirstChar() { From 032a2980a1b28d99ed072d9947294182ca81ff62 Mon Sep 17 00:00:00 2001 From: springcomp Date: Tue, 1 Dec 2020 13:53:04 +0100 Subject: [PATCH 02/14] New method BackwardDeleteBuffer as prev BackwardDeleteLine impl. --- PSReadLine/BasicEditing.cs | 16 ++++++++++++++-- PSReadLine/KeyBindings.cs | 3 ++- PSReadLine/KeyBindings.vi.cs | 8 ++++---- PSReadLine/PSReadLineResources.resx | 3 +++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/PSReadLine/BasicEditing.cs b/PSReadLine/BasicEditing.cs index 91dcefc0..2af9dccd 100644 --- a/PSReadLine/BasicEditing.cs +++ b/PSReadLine/BasicEditing.cs @@ -115,19 +115,31 @@ public static void ForwardDeleteLine(ConsoleKeyInfo? key = null, object arg = nu } /// - /// Like BackwardKillLine - deletes text from the point to the start of the line, + /// Like BackwardKillLine - deletes text from the point to the start of the buffer, + /// but does not put the deleted text in the kill ring. + public static void BackwardDeleteBuffer(ConsoleKeyInfo? key = null, object arg = null) + { + BackwardDeleteSubstring(0, BackwardDeleteBuffer); + } + + /// + /// Like BackwardKillLine - deletes text from the point to the start of the logical line, /// but does not put the deleted text in the kill ring. /// public static void BackwardDeleteLine(ConsoleKeyInfo? key = null, object arg = null) { var position = GetBeginningOfLinePos(_singleton._current); + BackwardDeleteSubstring(position, BackwardDeleteLine); + } + private static void BackwardDeleteSubstring(int position, Action instigator = null) + { if (_singleton._current > position) { var count = _singleton._current - position; _clipboard.Record(_singleton._buffer, position, count); - _singleton.SaveEditItem(EditItemDelete.Create(_clipboard, position, BackwardDeleteLine)); + _singleton.SaveEditItem(EditItemDelete.Create(_clipboard, position, instigator)); _singleton._buffer.Remove(position, count); _singleton._current = position; _singleton.Render(); diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index edd049a5..80f7af28 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -209,7 +209,7 @@ void SetDefaultWindowsBindings() { Keys.CtrlY, MakeKeyHandler(Redo, "Redo") }, { Keys.CtrlZ, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlBackspace, MakeKeyHandler(BackwardKillWord, "BackwardKillWord") }, - { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteLine, "BackwardDeleteLine") }, + { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteBuffer, "BackwardDeleteBuffer") }, { Keys.CtrlRBracket, MakeKeyHandler(GotoBrace, "GotoBrace") }, { Keys.CtrlAltQuestion, MakeKeyHandler(ShowKeyBindings, "ShowKeyBindings") }, { Keys.AltPeriod, MakeKeyHandler(YankLastArg, "YankLastArg") }, @@ -388,6 +388,7 @@ public static KeyHandlerGroup GetDisplayGrouping(string function) case nameof(AcceptAndGetNext): case nameof(AcceptLine): case nameof(AddLine): + case nameof(BackwardDeleteBuffer): case nameof(BackwardDeleteChar): case nameof(BackwardDeleteLine): case nameof(BackwardDeleteWord): diff --git a/PSReadLine/KeyBindings.vi.cs b/PSReadLine/KeyBindings.vi.cs index e7772955..34fe959a 100644 --- a/PSReadLine/KeyBindings.vi.cs +++ b/PSReadLine/KeyBindings.vi.cs @@ -72,7 +72,7 @@ private void SetDefaultViBindings() { Keys.CtrlSpace, MakeKeyHandler(PossibleCompletions, "PossibleCompletions") }, { Keys.Tab, MakeKeyHandler(ViTabCompleteNext, "ViTabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(ViTabCompletePrevious, "ViTabCompletePrevious") }, - { Keys.CtrlU, MakeKeyHandler(BackwardDeleteLine, "BackwardDeleteLine") }, + { Keys.CtrlU, MakeKeyHandler(BackwardDeleteBuffer, "BackwardDeleteBuffer") }, { Keys.CtrlV, MakeKeyHandler(Paste, "Paste") }, { Keys.CtrlC, MakeKeyHandler(CancelLine, "CancelLine") }, { Keys.CtrlL, MakeKeyHandler(ClearScreen, "ClearScreen") }, @@ -81,7 +81,7 @@ private void SetDefaultViBindings() { Keys.CtrlZ, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlBackspace, MakeKeyHandler(BackwardKillWord, "BackwardKillWord") }, { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteLine, "ForwardDeleteLine") }, - { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteLine, "BackwardDeleteLine") }, + { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteBuffer, "BackwardDeleteBuffer") }, { Keys.CtrlRBracket, MakeKeyHandler(GotoBrace, "GotoBrace") }, { Keys.F3, MakeKeyHandler(CharacterSearch, "CharacterSearch") }, { Keys.ShiftF3, MakeKeyHandler(CharacterSearchBackward,"CharacterSearchBackward") }, @@ -120,13 +120,13 @@ private void SetDefaultViBindings() { Keys.CtrlC, MakeKeyHandler(CancelLine, "CancelLine") }, { Keys.CtrlL, MakeKeyHandler(ClearScreen, "ClearScreen") }, { Keys.CtrlT, MakeKeyHandler(SwapCharacters, "SwapCharacters") }, - { Keys.CtrlU, MakeKeyHandler(BackwardDeleteLine, "BackwardDeleteLine") }, + { Keys.CtrlU, MakeKeyHandler(BackwardDeleteBuffer, "BackwardDeleteBuffer") }, { Keys.CtrlW, MakeKeyHandler(BackwardDeleteWord, "BackwardDeleteWord") }, { Keys.CtrlY, MakeKeyHandler(Redo, "Redo") }, { Keys.CtrlZ, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlBackspace, MakeKeyHandler(BackwardKillWord, "BackwardKillWord") }, { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteLine, "ForwardDeleteLine") }, - { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteLine, "BackwardDeleteLine") }, + { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteBuffer, "BackwardDeleteBuffer") }, { Keys.CtrlRBracket, MakeKeyHandler(GotoBrace, "GotoBrace") }, { Keys.F3, MakeKeyHandler(CharacterSearch, "CharacterSearch") }, { Keys.ShiftF3, MakeKeyHandler(CharacterSearchBackward, "CharacterSearchBackward") }, diff --git a/PSReadLine/PSReadLineResources.resx b/PSReadLine/PSReadLineResources.resx index 920a7ab3..60174699 100644 --- a/PSReadLine/PSReadLineResources.resx +++ b/PSReadLine/PSReadLineResources.resx @@ -126,6 +126,9 @@ Move the cursor back one character + + Delete text from the cursor to the start of the input + Delete the character before the cursor From 6934462d008c412b5112011360de634510be3535 Mon Sep 17 00:00:00 2001 From: springcomp Date: Tue, 19 Jan 2021 16:57:31 +0100 Subject: [PATCH 03/14] Renamed BackwardDeleteBuffer to BackwardDeleteInput. --- PSReadLine/BasicEditing.cs | 6 +++--- PSReadLine/KeyBindings.cs | 4 ++-- PSReadLine/KeyBindings.vi.cs | 8 ++++---- PSReadLine/PSReadLineResources.Designer.cs | 11 ++++++++++- PSReadLine/PSReadLineResources.resx | 6 +++--- test/BasicEditingTest.cs | 2 +- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/PSReadLine/BasicEditing.cs b/PSReadLine/BasicEditing.cs index 2af9dccd..8a478b6a 100644 --- a/PSReadLine/BasicEditing.cs +++ b/PSReadLine/BasicEditing.cs @@ -115,11 +115,11 @@ public static void ForwardDeleteLine(ConsoleKeyInfo? key = null, object arg = nu } /// - /// Like BackwardKillLine - deletes text from the point to the start of the buffer, + /// Like BackwardKillInput - deletes text from the point to the start of the input, /// but does not put the deleted text in the kill ring. - public static void BackwardDeleteBuffer(ConsoleKeyInfo? key = null, object arg = null) + public static void BackwardDeleteInput(ConsoleKeyInfo? key = null, object arg = null) { - BackwardDeleteSubstring(0, BackwardDeleteBuffer); + BackwardDeleteSubstring(0, BackwardDeleteInput); } /// diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 80f7af28..26b4d652 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -209,7 +209,7 @@ void SetDefaultWindowsBindings() { Keys.CtrlY, MakeKeyHandler(Redo, "Redo") }, { Keys.CtrlZ, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlBackspace, MakeKeyHandler(BackwardKillWord, "BackwardKillWord") }, - { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteBuffer, "BackwardDeleteBuffer") }, + { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteInput, "BackwardDeleteInput") }, { Keys.CtrlRBracket, MakeKeyHandler(GotoBrace, "GotoBrace") }, { Keys.CtrlAltQuestion, MakeKeyHandler(ShowKeyBindings, "ShowKeyBindings") }, { Keys.AltPeriod, MakeKeyHandler(YankLastArg, "YankLastArg") }, @@ -388,7 +388,7 @@ public static KeyHandlerGroup GetDisplayGrouping(string function) case nameof(AcceptAndGetNext): case nameof(AcceptLine): case nameof(AddLine): - case nameof(BackwardDeleteBuffer): + case nameof(BackwardDeleteInput): case nameof(BackwardDeleteChar): case nameof(BackwardDeleteLine): case nameof(BackwardDeleteWord): diff --git a/PSReadLine/KeyBindings.vi.cs b/PSReadLine/KeyBindings.vi.cs index 34fe959a..69192528 100644 --- a/PSReadLine/KeyBindings.vi.cs +++ b/PSReadLine/KeyBindings.vi.cs @@ -72,7 +72,7 @@ private void SetDefaultViBindings() { Keys.CtrlSpace, MakeKeyHandler(PossibleCompletions, "PossibleCompletions") }, { Keys.Tab, MakeKeyHandler(ViTabCompleteNext, "ViTabCompleteNext") }, { Keys.ShiftTab, MakeKeyHandler(ViTabCompletePrevious, "ViTabCompletePrevious") }, - { Keys.CtrlU, MakeKeyHandler(BackwardDeleteBuffer, "BackwardDeleteBuffer") }, + { Keys.CtrlU, MakeKeyHandler(BackwardDeleteInput, "BackwardDeleteInput") }, { Keys.CtrlV, MakeKeyHandler(Paste, "Paste") }, { Keys.CtrlC, MakeKeyHandler(CancelLine, "CancelLine") }, { Keys.CtrlL, MakeKeyHandler(ClearScreen, "ClearScreen") }, @@ -81,7 +81,7 @@ private void SetDefaultViBindings() { Keys.CtrlZ, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlBackspace, MakeKeyHandler(BackwardKillWord, "BackwardKillWord") }, { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteLine, "ForwardDeleteLine") }, - { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteBuffer, "BackwardDeleteBuffer") }, + { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteInput, "BackwardDeleteInput") }, { Keys.CtrlRBracket, MakeKeyHandler(GotoBrace, "GotoBrace") }, { Keys.F3, MakeKeyHandler(CharacterSearch, "CharacterSearch") }, { Keys.ShiftF3, MakeKeyHandler(CharacterSearchBackward,"CharacterSearchBackward") }, @@ -120,13 +120,13 @@ private void SetDefaultViBindings() { Keys.CtrlC, MakeKeyHandler(CancelLine, "CancelLine") }, { Keys.CtrlL, MakeKeyHandler(ClearScreen, "ClearScreen") }, { Keys.CtrlT, MakeKeyHandler(SwapCharacters, "SwapCharacters") }, - { Keys.CtrlU, MakeKeyHandler(BackwardDeleteBuffer, "BackwardDeleteBuffer") }, + { Keys.CtrlU, MakeKeyHandler(BackwardDeleteInput, "BackwardDeleteInput") }, { Keys.CtrlW, MakeKeyHandler(BackwardDeleteWord, "BackwardDeleteWord") }, { Keys.CtrlY, MakeKeyHandler(Redo, "Redo") }, { Keys.CtrlZ, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlBackspace, MakeKeyHandler(BackwardKillWord, "BackwardKillWord") }, { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteLine, "ForwardDeleteLine") }, - { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteBuffer, "BackwardDeleteBuffer") }, + { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteInput, "BackwardDeleteInput") }, { Keys.CtrlRBracket, MakeKeyHandler(GotoBrace, "GotoBrace") }, { Keys.F3, MakeKeyHandler(CharacterSearch, "CharacterSearch") }, { Keys.ShiftF3, MakeKeyHandler(CharacterSearchBackward, "CharacterSearchBackward") }, diff --git a/PSReadLine/PSReadLineResources.Designer.cs b/PSReadLine/PSReadLineResources.Designer.cs index d26a5e4b..8b79df13 100644 --- a/PSReadLine/PSReadLineResources.Designer.cs +++ b/PSReadLine/PSReadLineResources.Designer.cs @@ -115,7 +115,16 @@ internal static string BackwardDeleteCharDescription { } /// - /// Looks up a localized string similar to Delete text from the cursor to the start of the line. + /// Looks up a localized string similar to Delete text from the cursor to the start of the input. + /// + internal static string BackwardDeleteInputDescription { + get { + return ResourceManager.GetString("BackwardDeleteInputDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Delete text from the cursor to the start of the current logical line. /// internal static string BackwardDeleteLineDescription { get { diff --git a/PSReadLine/PSReadLineResources.resx b/PSReadLine/PSReadLineResources.resx index 60174699..776f5fcb 100644 --- a/PSReadLine/PSReadLineResources.resx +++ b/PSReadLine/PSReadLineResources.resx @@ -126,12 +126,12 @@ Move the cursor back one character - - Delete text from the cursor to the start of the input - Delete the character before the cursor + + Delete text from the cursor to the start of the input + Delete text from the cursor to the start of the current logical line diff --git a/test/BasicEditingTest.cs b/test/BasicEditingTest.cs index de9fd7f2..fab6210d 100644 --- a/test/BasicEditingTest.cs +++ b/test/BasicEditingTest.cs @@ -98,7 +98,7 @@ public void ForwardDeleteLine() } [SkippableFact] - public void BackwardDeleteLine() + public void BackwardDeleteInput() { TestSetup(KeyMode.Cmd); From a97dba1d39da902ad3dab1501f8445947414f1e7 Mon Sep 17 00:00:00 2001 From: springcomp Date: Tue, 19 Jan 2021 17:22:56 +0100 Subject: [PATCH 04/14] Renamed BackwardKillLine into the more consistent BackwardKillInput, --- PSReadLine/KeyBindings.cs | 6 +++--- PSReadLine/KillYank.cs | 2 +- PSReadLine/PSReadLineResources.Designer.cs | 4 ++-- PSReadLine/PSReadLineResources.resx | 4 ++-- test/KillYankTest.cs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 26b4d652..fe916c21 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -294,7 +294,7 @@ void SetDefaultEmacsBindings() { Keys.CtrlR, MakeKeyHandler(ReverseSearchHistory, "ReverseSearchHistory") }, { Keys.CtrlS, MakeKeyHandler(ForwardSearchHistory, "ForwardSearchHistory") }, { Keys.CtrlT, MakeKeyHandler(SwapCharacters, "SwapCharacters") }, - { Keys.CtrlU, MakeKeyHandler(BackwardKillLine, "BackwardKillLine") }, + { Keys.CtrlU, MakeKeyHandler(BackwardKillInput, "BackwardKillLine") }, { Keys.CtrlX, MakeKeyHandler(Chord, "ChordFirstKey") }, { Keys.CtrlW, MakeKeyHandler(UnixWordRubout, "UnixWordRubout") }, { Keys.CtrlY, MakeKeyHandler(Yank, "Yank") }, @@ -369,7 +369,7 @@ void SetDefaultEmacsBindings() // Ctrl+X, table [Keys.CtrlX] = new Dictionary { - { Keys.Backspace, MakeKeyHandler(BackwardKillLine, "BackwardKillLine") }, + { Keys.Backspace, MakeKeyHandler(BackwardKillInput, "BackwardKillLine") }, { Keys.CtrlE, MakeKeyHandler(ViEditVisually, "ViEditVisually") }, { Keys.CtrlU, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlX, MakeKeyHandler(ExchangePointAndMark, "ExchangePointAndMark") }, @@ -392,7 +392,7 @@ public static KeyHandlerGroup GetDisplayGrouping(string function) case nameof(BackwardDeleteChar): case nameof(BackwardDeleteLine): case nameof(BackwardDeleteWord): - case nameof(BackwardKillLine): + case nameof(BackwardKillInput): case nameof(BackwardKillWord): case nameof(CancelLine): case nameof(Copy): diff --git a/PSReadLine/KillYank.cs b/PSReadLine/KillYank.cs index aa20e178..b5e6e1ed 100644 --- a/PSReadLine/KillYank.cs +++ b/PSReadLine/KillYank.cs @@ -117,7 +117,7 @@ public static void KillLine(ConsoleKeyInfo? key = null, object arg = null) /// Clear the input from the start of the input to the cursor. The cleared text is placed /// in the kill ring. /// - public static void BackwardKillLine(ConsoleKeyInfo? key = null, object arg = null) + public static void BackwardKillInput(ConsoleKeyInfo? key = null, object arg = null) { _singleton.Kill(0, _singleton._current, true); } diff --git a/PSReadLine/PSReadLineResources.Designer.cs b/PSReadLine/PSReadLineResources.Designer.cs index 8b79df13..d07270f7 100644 --- a/PSReadLine/PSReadLineResources.Designer.cs +++ b/PSReadLine/PSReadLineResources.Designer.cs @@ -144,9 +144,9 @@ internal static string BackwardDeleteWordDescription { /// /// Looks up a localized string similar to Move the text from the cursor to the beginning of the line to the kill ring. /// - internal static string BackwardKillLineDescription { + internal static string BackwardKillInputDescription { get { - return ResourceManager.GetString("BackwardKillLineDescription", resourceCulture); + return ResourceManager.GetString("BackwardKillInputDescription", resourceCulture); } } diff --git a/PSReadLine/PSReadLineResources.resx b/PSReadLine/PSReadLineResources.resx index 776f5fcb..5f17cd3b 100644 --- a/PSReadLine/PSReadLineResources.resx +++ b/PSReadLine/PSReadLineResources.resx @@ -135,8 +135,8 @@ Delete text from the cursor to the start of the current logical line - - Move the text from the cursor to the beginning of the line to the kill ring + + Move the text from the cursor to the beginning of the input to the kill ring Move to the first item in the history diff --git a/test/KillYankTest.cs b/test/KillYankTest.cs index 72677d51..ffc4e4de 100644 --- a/test/KillYankTest.cs +++ b/test/KillYankTest.cs @@ -112,7 +112,7 @@ public void KillLine() } [SkippableFact] - public void BackwardKillLine() + public void BackwardKillInput() { TestSetup(KeyMode.Emacs); From 0f75d6f667140f9bdcd968a933aaf79affd313df Mon Sep 17 00:00:00 2001 From: springcomp Date: Tue, 19 Jan 2021 18:30:19 +0100 Subject: [PATCH 05/14] New BackwardKillLine to remove text from the start of the current logical line. --- PSReadLine/KillYank.cs | 10 ++++++++++ PSReadLine/PSReadLineResources.Designer.cs | 9 +++++++++ PSReadLine/PSReadLineResources.resx | 3 +++ test/KillYankTest.cs | 10 ++++++++++ 4 files changed, 32 insertions(+) diff --git a/PSReadLine/KillYank.cs b/PSReadLine/KillYank.cs index b5e6e1ed..179bb360 100644 --- a/PSReadLine/KillYank.cs +++ b/PSReadLine/KillYank.cs @@ -122,6 +122,16 @@ public static void BackwardKillInput(ConsoleKeyInfo? key = null, object arg = nu _singleton.Kill(0, _singleton._current, true); } + /// + /// Clear the input from the start of the current logical line to the cursor. The cleared text is placed + /// in the kill ring. + /// + public static void BackwardKillLine(ConsoleKeyInfo? key = null, object arg = null) + { + var start = GetBeginningOfLinePos(_singleton._current); + _singleton.Kill(start, _singleton._current, true); + } + /// /// Clear the input from the cursor to the end of the current word. If the cursor /// is between words, the input is cleared from the cursor to the end of the next word. diff --git a/PSReadLine/PSReadLineResources.Designer.cs b/PSReadLine/PSReadLineResources.Designer.cs index d07270f7..f82695b0 100644 --- a/PSReadLine/PSReadLineResources.Designer.cs +++ b/PSReadLine/PSReadLineResources.Designer.cs @@ -150,6 +150,15 @@ internal static string BackwardKillInputDescription { } } + /// + /// Looks up a localized string similar to Move the text from the start of the current logical line to the cursor to the kill ring. + /// + internal static string BackwardKillLineDescription { + get { + return ResourceManager.GetString("BackwardKillLineDescription", resourceCulture); + } + } + /// /// Looks up a localized string similar to Move the text from the start of the current or previous word to the cursor to the kill ring. /// diff --git a/PSReadLine/PSReadLineResources.resx b/PSReadLine/PSReadLineResources.resx index 5f17cd3b..8568170d 100644 --- a/PSReadLine/PSReadLineResources.resx +++ b/PSReadLine/PSReadLineResources.resx @@ -138,6 +138,9 @@ Move the text from the cursor to the beginning of the input to the kill ring + + Move the text from the start of the current logical line to the cursor to the kill ring + Move to the first item in the history diff --git a/test/KillYankTest.cs b/test/KillYankTest.cs index ffc4e4de..1612e7ce 100644 --- a/test/KillYankTest.cs +++ b/test/KillYankTest.cs @@ -111,6 +111,16 @@ public void KillLine() Test("foo", Keys(_.Ctrl_y)); } + [SkippableFact] + public void BackwardKillLine() + { + TestSetup(KeyMode.Emacs); + + PSConsoleReadLine.SetKeyHandler(new[] { "Shift+Tab" }, PSConsoleReadLine.BackwardKillLine, "", ""); + + Test("", Keys("dir", _.Shift_Tab)); + } + [SkippableFact] public void BackwardKillInput() { From a51289691d5f2efedffaa0fae56ab1d2386d8324 Mon Sep 17 00:00:00 2001 From: springcomp Date: Tue, 19 Jan 2021 18:36:11 +0100 Subject: [PATCH 06/14] Renamed ForwardDeleteLine to the more consistent ForwardDeleteInput --- PSReadLine/BasicEditing.cs | 4 ++-- PSReadLine/KeyBindings.cs | 4 ++-- PSReadLine/KeyBindings.vi.cs | 4 ++-- PSReadLine/PSReadLineResources.Designer.cs | 4 ++-- PSReadLine/PSReadLineResources.resx | 4 ++-- test/BasicEditingTest.cs | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/PSReadLine/BasicEditing.cs b/PSReadLine/BasicEditing.cs index 8a478b6a..d6a0edfb 100644 --- a/PSReadLine/BasicEditing.cs +++ b/PSReadLine/BasicEditing.cs @@ -97,10 +97,10 @@ public static void CancelLine(ConsoleKeyInfo? key = null, object arg = null) } /// - /// Like ForwardKillLine - deletes text from the point to the end of the line, + /// Like ForwardKillLine - deletes text from the point to the end of the input, /// but does not put the deleted text in the kill ring. /// - public static void ForwardDeleteLine(ConsoleKeyInfo? key = null, object arg = null) + public static void ForwardDeleteInput(ConsoleKeyInfo? key = null, object arg = null) { var current = _singleton._current; var buffer = _singleton._buffer; diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index fe916c21..02998eef 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -242,7 +242,7 @@ void SetDefaultWindowsBindings() _dispatchTable.Add(Keys.CtrlSpace, MakeKeyHandler(MenuComplete, "MenuComplete")); _dispatchTable.Add(Keys.AltF7, MakeKeyHandler(ClearHistory, "ClearHistory")); _dispatchTable.Add(Keys.CtrlDelete, MakeKeyHandler(KillWord, "KillWord")); - _dispatchTable.Add(Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteLine, "ForwardDeleteLine")); + _dispatchTable.Add(Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteInput, "ForwardDeleteLine")); _dispatchTable.Add(Keys.CtrlH, MakeKeyHandler(BackwardDeleteChar,"BackwardDeleteChar")); // PageUp/PageDown and CtrlPageUp/CtrlPageDown bindings are supported on Windows only because they depend on the @@ -409,7 +409,7 @@ public static KeyHandlerGroup GetDisplayGrouping(string function) case nameof(DeletePreviousLines): case nameof(DeleteToEnd): case nameof(DeleteWord): - case nameof(ForwardDeleteLine): + case nameof(ForwardDeleteInput): case nameof(InsertLineAbove): case nameof(InsertLineBelow): case nameof(InvertCase): diff --git a/PSReadLine/KeyBindings.vi.cs b/PSReadLine/KeyBindings.vi.cs index 69192528..71781ad2 100644 --- a/PSReadLine/KeyBindings.vi.cs +++ b/PSReadLine/KeyBindings.vi.cs @@ -80,7 +80,7 @@ private void SetDefaultViBindings() { Keys.CtrlY, MakeKeyHandler(Redo, "Redo") }, { Keys.CtrlZ, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlBackspace, MakeKeyHandler(BackwardKillWord, "BackwardKillWord") }, - { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteLine, "ForwardDeleteLine") }, + { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteInput, "ForwardDeleteLine") }, { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteInput, "BackwardDeleteInput") }, { Keys.CtrlRBracket, MakeKeyHandler(GotoBrace, "GotoBrace") }, { Keys.F3, MakeKeyHandler(CharacterSearch, "CharacterSearch") }, @@ -125,7 +125,7 @@ private void SetDefaultViBindings() { Keys.CtrlY, MakeKeyHandler(Redo, "Redo") }, { Keys.CtrlZ, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlBackspace, MakeKeyHandler(BackwardKillWord, "BackwardKillWord") }, - { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteLine, "ForwardDeleteLine") }, + { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteInput, "ForwardDeleteLine") }, { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteInput, "BackwardDeleteInput") }, { Keys.CtrlRBracket, MakeKeyHandler(GotoBrace, "GotoBrace") }, { Keys.F3, MakeKeyHandler(CharacterSearch, "CharacterSearch") }, diff --git a/PSReadLine/PSReadLineResources.Designer.cs b/PSReadLine/PSReadLineResources.Designer.cs index f82695b0..72e07708 100644 --- a/PSReadLine/PSReadLineResources.Designer.cs +++ b/PSReadLine/PSReadLineResources.Designer.cs @@ -522,9 +522,9 @@ internal static string ForwardCharDescription { /// /// Looks up a localized string similar to Delete text from the cursor to the end of the line. /// - internal static string ForwardDeleteLineDescription { + internal static string ForwardDeleteInputDescription { get { - return ResourceManager.GetString("ForwardDeleteLineDescription", resourceCulture); + return ResourceManager.GetString("ForwardDeleteInputDescription", resourceCulture); } } diff --git a/PSReadLine/PSReadLineResources.resx b/PSReadLine/PSReadLineResources.resx index 8568170d..75d160ff 100644 --- a/PSReadLine/PSReadLineResources.resx +++ b/PSReadLine/PSReadLineResources.resx @@ -186,8 +186,8 @@ Move the cursor forward one character - - Delete text from the cursor to the end of the line + + Delete text from the cursor to the end of the input Move the cursor to the beginning of the next token or end of line diff --git a/test/BasicEditingTest.cs b/test/BasicEditingTest.cs index fab6210d..09ba543b 100644 --- a/test/BasicEditingTest.cs +++ b/test/BasicEditingTest.cs @@ -73,7 +73,7 @@ public void CancelLine() } [SkippableFact] - public void ForwardDeleteLine() + public void ForwardDeleteInput() { ConsoleKeyInfo deleteToEnd; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) From 80dac1b404101630df73606695d80dc5f6c892df Mon Sep 17 00:00:00 2001 From: springcomp Date: Tue, 19 Jan 2021 19:47:40 +0100 Subject: [PATCH 07/14] New ForwardDeleteLine to remove the text to the end of the current logical line, --- PSReadLine/BasicEditing.cs | 26 +++++++++++++++++++--- PSReadLine/PSReadLineResources.Designer.cs | 9 ++++++++ PSReadLine/PSReadLineResources.resx | 3 +++ test/BasicEditingTest.cs | 15 +++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/PSReadLine/BasicEditing.cs b/PSReadLine/BasicEditing.cs index d6a0edfb..33405a88 100644 --- a/PSReadLine/BasicEditing.cs +++ b/PSReadLine/BasicEditing.cs @@ -97,16 +97,36 @@ public static void CancelLine(ConsoleKeyInfo? key = null, object arg = null) } /// - /// Like ForwardKillLine - deletes text from the point to the end of the input, + /// Like KillLine - deletes text from the point to the end of the input, /// but does not put the deleted text in the kill ring. /// public static void ForwardDeleteInput(ConsoleKeyInfo? key = null, object arg = null) + { + ForwardDeleteImpl(_singleton._buffer.Length); + } + + /// + /// Deletes text from the point to the end of the current logical line, + /// but does not put the deleted text in the kill ring. + /// + public static void ForwardDeleteLine(ConsoleKeyInfo? key = null, object arg = null) + { + ForwardDeleteImpl(GetEndOfLogicalLinePos(_singleton._current) + 1); + } + + /// + /// Deletes text from the cursor position to the specified end position + /// but does not put the deleted text in the kill ring. + /// + /// 0-based offset to one character past the end of the text. + private static void ForwardDeleteImpl(int endPosition) { var current = _singleton._current; var buffer = _singleton._buffer; - if (buffer.Length > 0 && current < buffer.Length) + + if (buffer.Length > 0 && current < endPosition) { - int length = buffer.Length - current; + int length = endPosition - current; var str = buffer.ToString(current, length); _singleton.SaveEditItem(EditItemDelete.Create(str, current)); buffer.Remove(current, length); diff --git a/PSReadLine/PSReadLineResources.Designer.cs b/PSReadLine/PSReadLineResources.Designer.cs index 72e07708..ac7ce268 100644 --- a/PSReadLine/PSReadLineResources.Designer.cs +++ b/PSReadLine/PSReadLineResources.Designer.cs @@ -528,6 +528,15 @@ internal static string ForwardDeleteInputDescription { } } + /// + /// Looks up a localized string similar to Delete text from the cursor to the end of the current logical line. + /// + internal static string ForwardDeleteLineDescription { + get { + return ResourceManager.GetString("ForwardDeleteLineDescription", resourceCulture); + } + } + /// /// Looks up a localized string similar to Search history forward interactively. /// diff --git a/PSReadLine/PSReadLineResources.resx b/PSReadLine/PSReadLineResources.resx index 75d160ff..fbc6ae0b 100644 --- a/PSReadLine/PSReadLineResources.resx +++ b/PSReadLine/PSReadLineResources.resx @@ -189,6 +189,9 @@ Delete text from the cursor to the end of the input + + Delete text from the cursor to the end of the current logical line + Move the cursor to the beginning of the next token or end of line diff --git a/test/BasicEditingTest.cs b/test/BasicEditingTest.cs index 09ba543b..6710181c 100644 --- a/test/BasicEditingTest.cs +++ b/test/BasicEditingTest.cs @@ -97,6 +97,21 @@ public void ForwardDeleteInput() Test("a", Keys("abc", _.LeftArrow, _.LeftArrow, deleteToEnd)); } + [SkippableFact] + public void ForwardDeleteLine() + { + TestSetup(KeyMode.Emacs); + + PSConsoleReadLine.SetKeyHandler(new[] { "Shift+Tab" }, PSConsoleReadLine.ForwardDeleteLine, "", ""); + + Test("\"H\nWorld\"", Keys( + _.DQuote, "Hello", _.Enter, + "World", _.DQuote, + _.Home, _.Home, _.RightArrow, _.RightArrow, + _.Shift_Tab // delete to the end of the current logical line + )); + } + [SkippableFact] public void BackwardDeleteInput() { From 4e555bec0000996ccd9a065c91832e9f6dbe17c4 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 9 Feb 2021 21:20:12 -0800 Subject: [PATCH 08/14] Update PSReadLine/KeyBindings.cs --- PSReadLine/KeyBindings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 02998eef..6ba37b85 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -242,7 +242,7 @@ void SetDefaultWindowsBindings() _dispatchTable.Add(Keys.CtrlSpace, MakeKeyHandler(MenuComplete, "MenuComplete")); _dispatchTable.Add(Keys.AltF7, MakeKeyHandler(ClearHistory, "ClearHistory")); _dispatchTable.Add(Keys.CtrlDelete, MakeKeyHandler(KillWord, "KillWord")); - _dispatchTable.Add(Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteInput, "ForwardDeleteLine")); + _dispatchTable.Add(Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteInput, "ForwardDeleteInput")); _dispatchTable.Add(Keys.CtrlH, MakeKeyHandler(BackwardDeleteChar,"BackwardDeleteChar")); // PageUp/PageDown and CtrlPageUp/CtrlPageDown bindings are supported on Windows only because they depend on the From 92b55c073915e73b75f901b19cdd59c0726b0e8a Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 9 Feb 2021 21:20:32 -0800 Subject: [PATCH 09/14] Update PSReadLine/KeyBindings.cs --- PSReadLine/KeyBindings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 6ba37b85..74800ee5 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -294,7 +294,7 @@ void SetDefaultEmacsBindings() { Keys.CtrlR, MakeKeyHandler(ReverseSearchHistory, "ReverseSearchHistory") }, { Keys.CtrlS, MakeKeyHandler(ForwardSearchHistory, "ForwardSearchHistory") }, { Keys.CtrlT, MakeKeyHandler(SwapCharacters, "SwapCharacters") }, - { Keys.CtrlU, MakeKeyHandler(BackwardKillInput, "BackwardKillLine") }, + { Keys.CtrlU, MakeKeyHandler(BackwardKillInput, "BackwardKillInput") }, { Keys.CtrlX, MakeKeyHandler(Chord, "ChordFirstKey") }, { Keys.CtrlW, MakeKeyHandler(UnixWordRubout, "UnixWordRubout") }, { Keys.CtrlY, MakeKeyHandler(Yank, "Yank") }, From b36590371a24f1e45933bb78b5dd0515fae3c417 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 9 Feb 2021 21:20:50 -0800 Subject: [PATCH 10/14] Update PSReadLine/KeyBindings.cs --- PSReadLine/KeyBindings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 74800ee5..6573c0ee 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -369,7 +369,7 @@ void SetDefaultEmacsBindings() // Ctrl+X, table [Keys.CtrlX] = new Dictionary { - { Keys.Backspace, MakeKeyHandler(BackwardKillInput, "BackwardKillLine") }, + { Keys.Backspace, MakeKeyHandler(BackwardKillInput, "BackwardKillInput") }, { Keys.CtrlE, MakeKeyHandler(ViEditVisually, "ViEditVisually") }, { Keys.CtrlU, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlX, MakeKeyHandler(ExchangePointAndMark, "ExchangePointAndMark") }, From a984b5959eeef61b3db947a3cea6afa8c3b71b4c Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 9 Feb 2021 21:21:11 -0800 Subject: [PATCH 11/14] Update PSReadLine/KeyBindings.vi.cs --- PSReadLine/KeyBindings.vi.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSReadLine/KeyBindings.vi.cs b/PSReadLine/KeyBindings.vi.cs index 71781ad2..3e1a5c58 100644 --- a/PSReadLine/KeyBindings.vi.cs +++ b/PSReadLine/KeyBindings.vi.cs @@ -80,7 +80,7 @@ private void SetDefaultViBindings() { Keys.CtrlY, MakeKeyHandler(Redo, "Redo") }, { Keys.CtrlZ, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlBackspace, MakeKeyHandler(BackwardKillWord, "BackwardKillWord") }, - { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteInput, "ForwardDeleteLine") }, + { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteInput, "ForwardDeleteInput") }, { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteInput, "BackwardDeleteInput") }, { Keys.CtrlRBracket, MakeKeyHandler(GotoBrace, "GotoBrace") }, { Keys.F3, MakeKeyHandler(CharacterSearch, "CharacterSearch") }, From e4de4bdfa69dac85d0226a16e57c78c944796837 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 9 Feb 2021 21:21:34 -0800 Subject: [PATCH 12/14] Update PSReadLine/KeyBindings.vi.cs --- PSReadLine/KeyBindings.vi.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSReadLine/KeyBindings.vi.cs b/PSReadLine/KeyBindings.vi.cs index 3e1a5c58..8f4beb07 100644 --- a/PSReadLine/KeyBindings.vi.cs +++ b/PSReadLine/KeyBindings.vi.cs @@ -125,7 +125,7 @@ private void SetDefaultViBindings() { Keys.CtrlY, MakeKeyHandler(Redo, "Redo") }, { Keys.CtrlZ, MakeKeyHandler(Undo, "Undo") }, { Keys.CtrlBackspace, MakeKeyHandler(BackwardKillWord, "BackwardKillWord") }, - { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteInput, "ForwardDeleteLine") }, + { Keys.CtrlEnd, MakeKeyHandler(ForwardDeleteInput, "ForwardDeleteInput") }, { Keys.CtrlHome, MakeKeyHandler(BackwardDeleteInput, "BackwardDeleteInput") }, { Keys.CtrlRBracket, MakeKeyHandler(GotoBrace, "GotoBrace") }, { Keys.F3, MakeKeyHandler(CharacterSearch, "CharacterSearch") }, From c457cc7c536f428a48767073a11283a95a463390 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 9 Feb 2021 21:21:54 -0800 Subject: [PATCH 13/14] Update PSReadLine/KeyBindings.cs --- PSReadLine/KeyBindings.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 6573c0ee..8d0d0105 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -393,6 +393,7 @@ public static KeyHandlerGroup GetDisplayGrouping(string function) case nameof(BackwardDeleteLine): case nameof(BackwardDeleteWord): case nameof(BackwardKillInput): + case nameof(BackwardKillLine): case nameof(BackwardKillWord): case nameof(CancelLine): case nameof(Copy): From 238eec8ccb2fc41e1650065afc673ec0c1a11693 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 9 Feb 2021 21:22:02 -0800 Subject: [PATCH 14/14] Update PSReadLine/KeyBindings.cs --- PSReadLine/KeyBindings.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PSReadLine/KeyBindings.cs b/PSReadLine/KeyBindings.cs index 8d0d0105..b9691d2b 100644 --- a/PSReadLine/KeyBindings.cs +++ b/PSReadLine/KeyBindings.cs @@ -411,6 +411,7 @@ public static KeyHandlerGroup GetDisplayGrouping(string function) case nameof(DeleteToEnd): case nameof(DeleteWord): case nameof(ForwardDeleteInput): + case nameof(ForwardDeleteLine): case nameof(InsertLineAbove): case nameof(InsertLineBelow): case nameof(InvertCase):