From 6a064766594e4960226eb610e1f3b3742959a1f5 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Wed, 13 May 2020 13:01:42 -0600 Subject: [PATCH] ENTER now moves to list if on filter (#98) * Fixed #58: Multi-line commands rendering wrong * Fixed #58 - Newlines in commands render incorrectly * Added debug instructions to readme * Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs Co-Authored-By: Tyler James Leonhardt * simplified stripping of newline/linefeed * ENTER now moves to list if on filter Co-authored-by: Tyler James Leonhardt --- .../ConsoleGui.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs index 736dcc7..e62e23d 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs @@ -16,6 +16,7 @@ internal class ConsoleGui : IDisposable private const string FILTER_LABEL = "Filter"; private bool _cancelled; private GridViewDataSource _itemSource; + private TextField _filterField; private ListView _listView; private ApplicationData _applicationData; private GridViewDetails _gridViewDetails; @@ -100,7 +101,14 @@ private void AddStatusBar() // Use Key.Unknown for SPACE with no delegate because ListView already // handles SPACE new StatusItem(Key.Unknown, "~SPACE~ Mark Item", null), - new StatusItem(Key.Enter, "~ENTER~ Accept", () => Accept()), + new StatusItem(Key.Enter, "~ENTER~ Accept", () => { + if (Application.Top.MostFocused == _listView){ + Accept(); + } + else if (Application.Top.MostFocused == _filterField){ + Application.Top.SetFocus(_listView); + } + }), new StatusItem(Key.Esc, "~ESC~ Close", () => Close()) } : new StatusItem [] @@ -169,7 +177,7 @@ private void AddFilter(Window win) X = 2 }; - var filterField = new TextField(string.Empty) + _filterField = new TextField(string.Empty) { X = Pos.Right(filterLabel) + 1, Y = Pos.Top(filterLabel), @@ -185,7 +193,7 @@ private void AddFilter(Window win) Width = Dim.Fill() - filterLabel.Text.Length }; - filterField.Changed += (object sender, ustring e) => + _filterField.Changed += (object sender, ustring e) => { // NOTE: `ustring e` seems to contain the text _before_ the added character... // so we convert the `sender` into a TextField and grab the text from that. @@ -208,7 +216,7 @@ private void AddFilter(Window win) } }; - win.Add(filterLabel, filterField, filterErrorLabel); + win.Add(filterLabel, _filterField, filterErrorLabel); } private void AddHeaders(Window win, List gridHeaders)