Skip to content

Commit 28fd7b7

Browse files
authored
Marked are now at top; simplified code; fixed margin (#188)
* Marked are now at top; simplified code; fixed margin * removed commented code
1 parent d2d08de commit 28fd7b7

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class ConsoleGui : IDisposable
1515
{
1616
private const string FILTER_LABEL = "Filter";
1717
// This adjusts the left margin of all controls
18-
private const int MARGIN_LEFT = 2;
18+
private const int MARGIN_LEFT = 1;
1919
// Width of Terminal.Gui ListView selection/check UI elements (old == 4, new == 2)
2020
private const int CHECK_WIDTH = 2;
2121
private bool _cancelled;
@@ -302,7 +302,7 @@ private void AddFilter(Window win)
302302
X = Pos.Right(_filterLabel) + 1,
303303
Y = Pos.Top(_filterLabel),
304304
CanFocus = true,
305-
Width = Dim.Fill() - _filterLabel.Text.Length
305+
Width = Dim.Fill() - 1
306306
};
307307

308308
// TextField captures Ctrl-A (select all text) and Ctrl-D (delete backwards)
@@ -338,7 +338,6 @@ private void AddFilter(Window win)
338338
filterErrorLabel.Text = ex.Message;
339339
filterErrorLabel.ColorScheme = Colors.Error;
340340
filterErrorLabel.Redraw(filterErrorLabel.Bounds);
341-
_listView.Source = _inputSource;
342341
}
343342
};
344343

@@ -403,7 +402,7 @@ private void AddListView(Window win)
403402
{
404403
_listView.Y = 1; // 1 for space, 1 for header, 1 for header underline
405404
}
406-
_listView.Width = Dim.Fill(2);
405+
_listView.Width = Dim.Fill(1);
407406
_listView.Height = Dim.Fill();
408407
_listView.AllowsMarking = _applicationData.OutputMode != OutputModeOption.None;
409408
_listView.AllowsMultipleSelection = _applicationData.OutputMode == OutputModeOption.Multiple;

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewHelpers.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,20 @@ namespace OutGridView.Cmdlet
1414
{
1515
internal class GridViewHelpers
1616
{
17-
public static List<GridViewRow> FilterData(List<GridViewRow> list, string filter)
17+
// Add all items already selected plus any that match the filter
18+
// The selected items should be at the top of the list, in their original order
19+
public static List<GridViewRow> FilterData(List<GridViewRow> listToFilter, string filter)
1820
{
19-
var items = new List<GridViewRow>();
21+
var filteredList = new List<GridViewRow>();
2022
if (string.IsNullOrEmpty(filter))
2123
{
22-
filter = ".*";
24+
return listToFilter;
2325
}
2426

25-
foreach (GridViewRow gvr in list)
26-
{
27-
if (gvr.IsMarked || Regex.IsMatch(gvr.DisplayString, filter, RegexOptions.IgnoreCase))
28-
{
29-
items.Add(gvr);
30-
}
31-
}
27+
filteredList.AddRange(listToFilter.Where(gvr => gvr.IsMarked));
28+
filteredList.AddRange(listToFilter.Where(gvr => !gvr.IsMarked && Regex.IsMatch(gvr.DisplayString, filter, RegexOptions.IgnoreCase)));
3229

33-
return items;
30+
return filteredList;
3431
}
3532

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

0 commit comments

Comments
 (0)