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
7 changes: 6 additions & 1 deletion Terminal.Gui/ViewBase/Adornment/AdornmentView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,15 @@ public override bool Contains (in Point location)
}
}

if (Adornment is null)
{
return false;
}

Rectangle outside = Frame;
outside.Offset (parentOrSuperView.Frame.Location);

return Adornment!.Thickness.Contains (outside, location);
return Adornment.Thickness.Contains (outside, location);
}

#endregion View Overrides
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace ViewBaseTests.Adornments;

// Copilot
public class AdornmentViewTests
{
/// <summary>
/// Regression test for https://github.com/gui-cs/Terminal.Gui/issues/4883.
/// AdornmentView.Contains must not throw NullReferenceException when Adornment is null
/// (i.e. the view was created via its parameter-less constructor, as happens when
/// AllViewsTester / Themes UICatalog scenario creates it via reflection).
/// </summary>
[Fact]
public void Contains_Returns_False_When_Adornment_Is_Null ()
{
// Arrange - parameter-less ctor leaves Adornment = null
AdornmentView adornmentView = new ();

// Act & Assert - must not throw NullReferenceException
bool result = adornmentView.Contains (new Point (0, 0));

Assert.False (result);
}


}
Loading