Skip to content

Commit 5795efa

Browse files
committed
Fixed Select All bug.
Refactored `OnWinSubViewLayout` to add null checks for `_header` to ensure safety and prevent runtime exceptions. Simplified "Select All" and "Select None" logic by replacing manual iteration with `_listView?.MarkAll` calls and added comments to address a `Terminal.Gui` bug requiring explicit redraws. Removed default `Ctrl-A` keybinding from `_listView` to allow custom handling in the status bar. Updated `LangVersion` in `Microsoft.PowerShell.ConsoleGuiTools.csproj` to `preview` to enable preview language features. Fixed formatting in the `ProjectReference` element for consistency.
1 parent 8eccca8 commit 5795efa

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ void OnWinSubViewLayout(object? sender, EventArgs e)
119119
{
120120
CalculateColumnWidths(gridHeaders);
121121

122-
_header!.Text = GridViewHelpers.GetPaddedString(gridHeaders, _gridViewDetails!.ListViewOffset,
122+
if (_header is not null)
123+
_header.Text = GridViewHelpers.GetPaddedString(gridHeaders, _gridViewDetails!.ListViewOffset,
123124
_gridViewDetails.ListViewColumnWidths);
124125
UpdateDisplayStrings(_listViewSource);
125126
ApplyFilter();
@@ -269,19 +270,15 @@ private void AddStatusBar(Window win, bool visible)
269270
{
270271
shortcuts.Add(new Shortcut(Key.A.WithCtrl, "Select All", () =>
271272
{
272-
// This selects only the items that match the Filter
273-
var gvds = _listView!.Source as GridViewDataSource;
274-
gvds!.GridViewRowList.ForEach(i => i.IsMarked = true);
275-
_listView.SetNeedsDraw();
273+
_listView?.MarkAll(true);
274+
_listView?.SetNeedsDraw(); // Bug in Terminal.Gui where MarkAll doesn't refresh display
276275
}));
277276

278277
// Ctrl-D is commonly used in GUIs for select-none
279278
shortcuts.Add(new Shortcut(Key.D.WithCtrl, "Select None", () =>
280279
{
281-
// This un-selects only the items that match the Filter
282-
var gvds = _listView!.Source as GridViewDataSource;
283-
gvds!.GridViewRowList.ForEach(i => i.IsMarked = false);
284-
_listView.SetNeedsDraw();
280+
_listView?.MarkAll(false);
281+
_listView?.SetNeedsDraw(); // Bug in Terminal.Gui where MarkAll doesn't refresh display
285282
}));
286283
}
287284

@@ -481,6 +478,9 @@ private void AddListView(Window win)
481478

482479
_listView.SelectedItem = 0;
483480

481+
// ListView captures Ctrl-A (select all) - we handle this in the status bar
482+
_listView.KeyBindings.Remove(Key.A.WithCtrl);
483+
484484
win.Add(_listView);
485485
}
486486

src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\..\ConsoleGuiTools.Common.props" />
33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<LangVersion>latest</LangVersion>
5+
<LangVersion>preview</LangVersion>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

@@ -23,7 +23,7 @@
2323
</ItemGroup>
2424

2525
<ItemGroup>
26-
<ProjectReference Include ="../Microsoft.PowerShell.OutGridView.Models/Microsoft.PowerShell.OutGridView.Models.csproj" />
26+
<ProjectReference Include="../Microsoft.PowerShell.OutGridView.Models/Microsoft.PowerShell.OutGridView.Models.csproj" />
2727
</ItemGroup>
2828

2929
<ItemGroup>

0 commit comments

Comments
 (0)