diff --git a/Terminal.Gui/Views/FileDialogs/FileDialog.TableView.cs b/Terminal.Gui/Views/FileDialogs/FileDialog.TableView.cs index 9d3edf7ae5..537ecd1e82 100644 --- a/Terminal.Gui/Views/FileDialogs/FileDialog.TableView.cs +++ b/Terminal.Gui/Views/FileDialogs/FileDialog.TableView.cs @@ -160,8 +160,11 @@ private Scheme ColorGetter (CellColorGetterArgs args) { Normal = new Attribute (foreground, background), HotNormal = new Attribute (foreground, background), - Focus = new Attribute (background, foreground), - HotFocus = new Attribute (background, foreground) + Focus = args.RowScheme.Focus, + HotFocus = args.RowScheme.HotFocus, + Active = args.RowScheme.Active, + HotActive = args.RowScheme.HotActive, + Disabled = args.RowScheme.Disabled }; } diff --git a/Tests/UnitTestsParallelizable/Views/FileDialogColorTests.cs b/Tests/UnitTestsParallelizable/Views/FileDialogColorTests.cs new file mode 100644 index 0000000000..2ae8d781d2 --- /dev/null +++ b/Tests/UnitTestsParallelizable/Views/FileDialogColorTests.cs @@ -0,0 +1,50 @@ +// Copilot + +using System.IO.Abstractions.TestingHelpers; +using System.Reflection; + +namespace UnitTests.Views; + +public class FileDialogColorTests +{ + [Fact] + public void ParentRowColorGetter_UsesSelectionScheme_WhenNavigatingUp () + { + MockFileSystem fileSystem = new (); + fileSystem.AddDirectory ("/test-dir/sub-dir"); + + using SaveDialog dialog = new TestableSaveDialog (fileSystem); + dialog.PushState (fileSystem.DirectoryInfo.New ("/test-dir/sub-dir"), false); + + FieldInfo? tableViewField = typeof (FileDialog).GetField ("_tableView", BindingFlags.Instance | BindingFlags.NonPublic); + Assert.NotNull (tableViewField); + + TableView tableView = Assert.IsType (tableViewField!.GetValue (dialog)); + ITableSource table = tableView.Table!; + Assert.NotNull (table); + Assert.True (dialog.State!.Children [0].IsParent); + + ColumnStyle nameStyle = tableView.Style.GetOrCreateColumnStyle (0); + Assert.NotNull (nameStyle.ColorGetter); + + object cellValue = table [0, 0]; + string representation = cellValue.ToString () ?? string.Empty; + Scheme rowScheme = tableView.GetScheme (); + Scheme effectiveScheme = nameStyle.ColorGetter! ( + new CellColorGetterArgs ( + table, + 0, + 0, + cellValue, + representation, + rowScheme))!; + + Assert.Equal (rowScheme.Focus, effectiveScheme.Focus); + Assert.Equal (rowScheme.Active, effectiveScheme.Active); + } + + private sealed class TestableSaveDialog : SaveDialog + { + public TestableSaveDialog (MockFileSystem fileSystem) : base (fileSystem) { } + } +}