Skip to content
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
6 changes: 6 additions & 0 deletions Terminal.Gui/Drawing/Scheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,12 @@ private Attribute GetAttributeForRoleCore (VisualRole role, HashSet<VisualRole>
// Helper method for property _set implementation
private Attribute? SetAttributeForRoleProperty (Attribute value, VisualRole role)
{
// Reassigning an explicit value must not change the role to implicit.
if (TryGetExplicitlySetAttributeForRole (role, out Attribute? explicitValue) && explicitValue == value)
{
return value;
}

// If value is the same as the algorithm value, use null
if (GetAttributeForRoleCore (role, [], null) == value)
{
Expand Down
22 changes: 22 additions & 0 deletions Tests/UnitTestsParallelizable/Drawing/SchemeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,28 @@ public void ToString_Outputs_All_Properties ()
[Fact]
public void CopyConstructor_Null_Throws () => Assert.Throws<ArgumentNullException> (() => new Scheme (null));

// Codex - GPT-5
Comment thread
YourRobotOverlord marked this conversation as resolved.
[Fact]
public void CopyConstructor_Reassigning_Explicit_Role_Same_Value_Preserves_Explicit_Value ()
{
Attribute editable = new (new Color ("#00FF6A"), new Color ("#292E42"));
Scheme baseScheme = new ()
{
Normal = new Attribute (new Color ("#C0CAF5"), new Color ("#1A1B26")),
Editable = editable
};

Scheme copiedScheme = new (baseScheme)
{
Normal = new Attribute (new Color ("#C0CAF5"), new Color ("#16161E")),
Editable = editable
};

Assert.Equal (editable, copiedScheme.Editable);
Assert.True (copiedScheme.TryGetExplicitlySetAttributeForRole (VisualRole.Editable, out Attribute? explicitEditable));
Assert.Equal (editable, explicitEditable);
}

[Fact]
public void Is_Thread_Safe_For_Concurrent_Reads ()
{
Expand Down
Loading