From 25a4c027c87f2fd960c72b3b8ca80173a0f4584e Mon Sep 17 00:00:00 2001 From: rich2014 Date: Sun, 10 Dec 2023 13:36:34 +0800 Subject: [PATCH] Cocoa: Fix the issue that KillFocus message is sent to the wrong control when the control is a FieldEditor #40635 --- lcl/interfaces/cocoa/cocoawindows.pas | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lcl/interfaces/cocoa/cocoawindows.pas b/lcl/interfaces/cocoa/cocoawindows.pas index 1e61ca726d..cffec4527d 100644 --- a/lcl/interfaces/cocoa/cocoawindows.pas +++ b/lcl/interfaces/cocoa/cocoawindows.pas @@ -1027,6 +1027,12 @@ begin newResponder := getProperFocusedResponder( self, aResponder ); if lastResponder = newResponder then exit; + // get the callback of lastResponder first, because the callback of + // lastResponder may be changed dynamically. + // for example, when lastResponder is a FieldEditor. + // see also: TCocoaFieldEditor.lclGetCallback() + cb := getResponderCallback( lastResponder ); + // do toggle Focused Control // Result=false when the focused control has not been changed // TCocoaWindow.makeFirstResponder() may be triggered reentrant here @@ -1038,7 +1044,6 @@ begin exit; // 1st: send KillFocus Message first - cb:= getResponderCallback( lastResponder ); if Assigned(cb) then cb.ResignFirstResponder;