mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Fixes #4177: View.GetAttributeForRole now defers to SuperView for proper attribute hierarchy (#4292)
* Initial plan * Fix GetAttributeForRole to defer to SuperView when no explicit scheme Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add test for Adornment attribute resolution Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix: Also check SchemeName when deferring to SuperView in GetAttributeForRole Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add test for StatusBar/Bar not deferring when SchemeName is set Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive low-level tests for GetAttributeForRole hierarchy Co-authored-by: tig <585482+tig@users.noreply.github.com> * Update AGENTS.md with PR branch pull instructions Co-authored-by: tig <585482+tig@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tig <585482+tig@users.noreply.github.com> Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
@@ -102,4 +102,37 @@ public class BarTests
|
||||
bar.LayoutSubViews ();
|
||||
// TODO: Assert specific layout expectations for vertical orientation
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetAttributeForRole_DoesNotDeferToSuperView_WhenSchemeNameIsSet ()
|
||||
{
|
||||
// This test would fail before the fix that checks SchemeName in GetAttributeForRole
|
||||
// StatusBar and MenuBarv2 set SchemeName = "Menu", and should use Menu scheme
|
||||
// instead of deferring to parent's customized attributes
|
||||
|
||||
var parentView = new View { SchemeName = "Base" };
|
||||
var statusBar = new StatusBar ();
|
||||
parentView.Add (statusBar);
|
||||
|
||||
// Parent customizes attribute resolution
|
||||
var customAttribute = new Attribute (Color.BrightMagenta, Color.BrightGreen);
|
||||
parentView.GettingAttributeForRole += (sender, args) =>
|
||||
{
|
||||
if (args.Role == VisualRole.Normal)
|
||||
{
|
||||
args.Result = customAttribute;
|
||||
args.Handled = true;
|
||||
}
|
||||
};
|
||||
|
||||
// StatusBar sets SchemeName = "Menu" in its constructor
|
||||
// Before the fix: StatusBar would defer to parent and get customAttribute (WRONG)
|
||||
// After the fix: StatusBar uses Menu scheme (CORRECT)
|
||||
var menuScheme = SchemeManager.GetHardCodedSchemes ()? ["Menu"];
|
||||
Assert.NotEqual (customAttribute, statusBar.GetAttributeForRole (VisualRole.Normal));
|
||||
Assert.Equal (menuScheme!.Normal, statusBar.GetAttributeForRole (VisualRole.Normal));
|
||||
|
||||
statusBar.Dispose ();
|
||||
parentView.Dispose ();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user