Skip to content

Commit 1db4656

Browse files
committed
Add bindings for {Beginning|End}OfHistory
1 parent acf98b0 commit 1db4656

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

PSReadLine/Keys.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ public class Keys
112112
public static ConsoleKeyInfo AltEquals = new ConsoleKeyInfo('=', ConsoleKey.OemPlus, false, true, false);
113113
public static ConsoleKeyInfo Space = new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false);
114114
// Useless because it's caught by the console to bring up the system menu.
115-
public static ConsoleKeyInfo AltSpace = new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, true, false);
116-
public static ConsoleKeyInfo CtrlSpace = new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, true);
115+
public static ConsoleKeyInfo AltSpace = new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, true, false);
116+
public static ConsoleKeyInfo CtrlSpace = new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, true);
117+
public static ConsoleKeyInfo AltLess = new ConsoleKeyInfo('<', ConsoleKey.OemComma, true, true, false);
118+
public static ConsoleKeyInfo AltGreater = new ConsoleKeyInfo('>', ConsoleKey.OemPeriod, true, true, false);
117119

118120
public static ConsoleKeyInfo AltA = new ConsoleKeyInfo((char)97, ConsoleKey.A, false, true, false);
119121
public static ConsoleKeyInfo AltB = new ConsoleKeyInfo((char)98, ConsoleKey.B, false, true, false);

PSReadLine/PSReadLineResources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PSReadLine/PSReadLineResources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@
138138
<data name="BackwordWordDescription" xml:space="preserve">
139139
<value>Move the cursor to the beginning of the current or previous token or start of the line</value>
140140
</data>
141+
<data name="BeginningOfHistoryDescription" xml:space="preserve">
142+
<value>Move to the first item in the history</value>
143+
</data>
141144
<data name="BeginningOfLineDescription" xml:space="preserve">
142145
<value>Move the cursor to the beginning of the line</value>
143146
</data>
@@ -168,6 +171,9 @@
168171
<data name="EmacsMetaDescription" xml:space="preserve">
169172
<value>String is not used in the UI</value>
170173
</data>
174+
<data name="EndOfHistoryDescription" xml:space="preserve">
175+
<value>Move to the last item (the current input) in the history</value>
176+
</data>
171177
<data name="EndOfLineDescription" xml:space="preserve">
172178
<value>Move the cursor to the end of the line</value>
173179
</data>

PSReadLine/ReadLine.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ static PSConsoleReadLine()
444444
{ Keys.RightArrow, MakeKeyHandler(ForwardChar, "ForwardChar") },
445445
{ Keys.UpArrow, MakeKeyHandler(PreviousHistory, "PreviousHistory") },
446446
{ Keys.DownArrow, MakeKeyHandler(NextHistory, "NextHistory") },
447+
{ Keys.AltLess, MakeKeyHandler(BeginningOfHistory, "BeginningOfHistory") },
448+
{ Keys.AltGreater, MakeKeyHandler(EndOfHistory, "EndOfHistory") },
447449
{ Keys.Home, MakeKeyHandler(BeginningOfLine, "BeginningOfLine") },
448450
{ Keys.End, MakeKeyHandler(EndOfLine, "EndOfLine") },
449451
{ Keys.Escape, MakeKeyHandler(Chord, "ChordFirstKey") },
@@ -967,6 +969,25 @@ private void HistorySearch(bool backward)
967969
}
968970
}
969971

972+
/// <summary>
973+
/// Move to the first item in the history.
974+
/// </summary>
975+
public static void BeginningOfHistory(ConsoleKeyInfo? key = null, object arg = null)
976+
{
977+
_singleton.SaveCurrentLine();
978+
_singleton._currentHistoryIndex = 0;
979+
_singleton.UpdateFromHistory(moveCursor: _singleton._historySearchCursorMovesToEnd);
980+
}
981+
982+
/// <summary>
983+
/// Move to the last item (the current input) in the history.
984+
/// </summary>
985+
public static void EndOfHistory(ConsoleKeyInfo? key = null, object arg = null)
986+
{
987+
_singleton._currentHistoryIndex = _singleton._history.Count;
988+
_singleton.UpdateFromHistory(moveCursor: _singleton._historySearchCursorMovesToEnd);
989+
}
990+
970991
/// <summary>
971992
/// Replace the current input with the 'previous' item from PSReadline history
972993
/// that matches the characters between the start and the input and the cursor.
@@ -987,6 +1008,10 @@ public static void HistorySearchForward(ConsoleKeyInfo? key = null, object arg =
9871008
_singleton.HistorySearch(backward: false);
9881009
}
9891010

1011+
#endregion History
1012+
1013+
#region Completion
1014+
9901015
/// <summary>
9911016
/// Attempt to complete the text surrounding the cursor with the next
9921017
/// available completion.
@@ -1230,7 +1255,7 @@ public static void PossibleCompletions(ConsoleKeyInfo? key = null, object arg =
12301255
_singleton.Render();
12311256
}
12321257

1233-
#endregion History
1258+
#endregion Completion
12341259

12351260
#region Kill/Yank
12361261

0 commit comments

Comments
 (0)