From 5f21280130b154ea517a0f283c7c554aa41d69e8 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 30 Jan 2018 17:17:47 +0100 Subject: [PATCH] Avoid duplicate wxEVT_SEARCHCTRL_CANCEL_BTN event under macOS see https://github.com/wxWidgets/wxWidgets/pull/698 , along the idea by commit 1776f136f7d673c8e772c9ca6e1607089a071651, implemented a little bit more defensively --- src/osx/cocoa/srchctrl.mm | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/osx/cocoa/srchctrl.mm b/src/osx/cocoa/srchctrl.mm index 162408426b..7cf1695285 100644 --- a/src/osx/cocoa/srchctrl.mm +++ b/src/osx/cocoa/srchctrl.mm @@ -30,6 +30,7 @@ @interface wxNSSearchField : NSSearchField { + BOOL m_withinTextDidChange; } @end @@ -48,10 +49,20 @@ - (id)initWithFrame:(NSRect)frame { - self = [super initWithFrame:frame]; + if ( self = [super initWithFrame:frame] ) + { + m_withinTextDidChange = NO; + } return self; } - + +- (void)textDidChange:(NSNotification *)aNotification +{ + m_withinTextDidChange = YES; + [super textDidChange:aNotification]; + m_withinTextDidChange = NO; +} + - (void)controlTextDidChange:(NSNotification *)aNotification { wxUnusedVar(aNotification); @@ -84,6 +95,11 @@ return matches; } +- (BOOL) isWithinTextDidChange +{ + return m_withinTextDidChange; +} + @end // ============================================================================ @@ -157,7 +173,8 @@ public : NSString *searchString = [m_searchField stringValue]; if ( searchString == nil || !searchString.length ) { - wxpeer->HandleSearchFieldCancelHit(); + if ( ![m_searchField isWithinTextDidChange]) + wxpeer->HandleSearchFieldCancelHit(); } else {