Skip to content

Marked are now at top; simplified code; fixed margin #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class ConsoleGui : IDisposable
{
private const string FILTER_LABEL = "Filter";
// This adjusts the left margin of all controls
private const int MARGIN_LEFT = 2;
private const int MARGIN_LEFT = 1;
// Width of Terminal.Gui ListView selection/check UI elements (old == 4, new == 2)
private const int CHECK_WIDTH = 2;
private bool _cancelled;
Expand Down Expand Up @@ -302,7 +302,7 @@ private void AddFilter(Window win)
X = Pos.Right(_filterLabel) + 1,
Y = Pos.Top(_filterLabel),
CanFocus = true,
Width = Dim.Fill() - _filterLabel.Text.Length
Width = Dim.Fill() - 1
};

// TextField captures Ctrl-A (select all text) and Ctrl-D (delete backwards)
Expand Down Expand Up @@ -338,7 +338,6 @@ private void AddFilter(Window win)
filterErrorLabel.Text = ex.Message;
filterErrorLabel.ColorScheme = Colors.Error;
filterErrorLabel.Redraw(filterErrorLabel.Bounds);
_listView.Source = _inputSource;
}
};

Expand Down Expand Up @@ -403,7 +402,7 @@ private void AddListView(Window win)
{
_listView.Y = 1; // 1 for space, 1 for header, 1 for header underline
}
_listView.Width = Dim.Fill(2);
_listView.Width = Dim.Fill(1);
_listView.Height = Dim.Fill();
_listView.AllowsMarking = _applicationData.OutputMode != OutputModeOption.None;
_listView.AllowsMultipleSelection = _applicationData.OutputMode == OutputModeOption.Multiple;
Expand Down
19 changes: 8 additions & 11 deletions src/Microsoft.PowerShell.ConsoleGuiTools/GridViewHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@ namespace OutGridView.Cmdlet
{
internal class GridViewHelpers
{
public static List<GridViewRow> FilterData(List<GridViewRow> list, string filter)
// Add all items already selected plus any that match the filter
// The selected items should be at the top of the list, in their original order
public static List<GridViewRow> FilterData(List<GridViewRow> listToFilter, string filter)
{
var items = new List<GridViewRow>();
var filteredList = new List<GridViewRow>();
if (string.IsNullOrEmpty(filter))
{
filter = ".*";
return listToFilter;
}

foreach (GridViewRow gvr in list)
{
if (gvr.IsMarked || Regex.IsMatch(gvr.DisplayString, filter, RegexOptions.IgnoreCase))
{
items.Add(gvr);
}
}
filteredList.AddRange(listToFilter.Where(gvr => gvr.IsMarked));
filteredList.AddRange(listToFilter.Where(gvr => !gvr.IsMarked && Regex.IsMatch(gvr.DisplayString, filter, RegexOptions.IgnoreCase)));

return items;
return filteredList;
}

public static string GetPaddedString(List<string> strings, int offset, int[] listViewColumnWidths)
Expand Down