CPSearchField: Ignore clicks while hidden or excluded from hit testing

This commit is contained in:
David Richardson committed 2026-11-26 15:36:08 -06:00
1 parent 4999da8c77
commit 5a247365f3
2 files changed
+28

No files matched your search

+9
View File
@@ -595,6 +595,15 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
- (CPView)hitTest:(CGPoint)aPoint
{
/*
2026-11-26: The search field took a hit anywhere in its frame, even while hidden or
while it did not hit test, unlike -[CPView hitTest:]. A hidden search field over other
views took their clicks: in People, the sidebar's hidden search field lay over the All
People row, so that row could no longer be selected with the mouse.
*/
if ([self isHidden] || ![self hitTests])
return nil;
// Make sure a hit anywhere within the search field returns the search field itself
if (CGRectContainsPoint([self frame], aPoint))
return self;
+19
View File
@@ -255,4 +255,23 @@
[self assertFalse:[copy centersPlaceholder]];
}
/*
A hidden search field, or one that does not hit test, must not take clicks meant for the
views beneath it, as -[CPView hitTest:] does for any view.
*/
- (void)testAHiddenSearchFieldTakesNoHits
{
var field = [[CPSearchField alloc] initWithFrame:CGRectMake(10, 10, 100, 22)],
inside = CGPointMake(20, 20);
[self assert:field same:[field hitTest:inside] message:@"a shown search field takes a hit in its frame"];
[field setHidden:YES];
[self assertNull:[field hitTest:inside] message:@"a hidden search field takes no hit"];
[field setHidden:NO];
[field setHitTests:NO];
[self assertNull:[field hitTest:inside] message:@"a search field that does not hit test takes no hit"];
}
@end