From b9b1f7f310bd57ad32165b5050e28e99cedd9969 Mon Sep 17 00:00:00 2001 From: rich2014 Date: Fri, 23 Jun 2023 12:27:19 +0800 Subject: [PATCH] Cocoa: TCocoaComboBox: keep text case after ItemIndex changed when cbactRetainPrefixCase set --- lcl/interfaces/cocoa/cocoatextedits.pas | 3 ++ lcl/interfaces/cocoa/cocoawsstdctrls.pas | 39 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/lcl/interfaces/cocoa/cocoatextedits.pas b/lcl/interfaces/cocoa/cocoatextedits.pas index 15183b78a5..4a229c255d 100644 --- a/lcl/interfaces/cocoa/cocoatextedits.pas +++ b/lcl/interfaces/cocoa/cocoatextedits.pas @@ -1413,7 +1413,10 @@ begin if idx<0 then Result := NSNotFound else + begin + TComboBoxAsyncHelper.ResetTextIfNecessary(lclGetTarget, string_.UTF8String); Result := idx; + end; end; end; diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pas b/lcl/interfaces/cocoa/cocoawsstdctrls.pas index fb92bda3a7..ba4ccada67 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pas +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pas @@ -57,6 +57,19 @@ type class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override; end; + { TComboBoxAsyncHelper } + + TComboBoxAsyncHelper = class + private + cmb: TCustomComboBox; + newText: String; + procedure AsyncResetText(Data:PtrInt); + public + constructor Create(ACmb:TCustomComboBox; ANewText:String); + public + class procedure ResetTextIfNecessary(AObject:TObject; ANewText:String); + end; + { TLCLComboboxCallback } TLCLComboboxCallback = class(TLCLCommonCallback, IComboBoxCallback) @@ -705,6 +718,32 @@ begin allowed := TCustomCheckBox(Target).AllowGrayed; end; +{ TComboBoxAsyncHelper } + +constructor TComboBoxAsyncHelper.Create(ACmb:TCustomComboBox; ANewText:String); +begin + cmb:= ACmb; + newText:= ANewText; +end; + +procedure TComboBoxAsyncHelper.AsyncResetText(Data:PtrInt); +begin + TCocoaWSCustomComboBox.SetText(cmb, newText); + cmb.SelStart:= UTF8Length(newText); + cmb.SelLength:= 0; + Free; +end; + +class procedure TComboBoxAsyncHelper.ResetTextIfNecessary(AObject:TObject; ANewText:String); +var + helper: TComboBoxAsyncHelper; + ACmb: TCustomComboBox absolute AObject; +begin + if not (cbactRetainPrefixCase in ACmb.AutoCompleteText) then exit; + helper:= TComboBoxAsyncHelper.Create(ACmb, ANewText); + Application.QueueAsyncCall(@helper.AsyncResetText, 0); +end; + { TLCLComboboxCallback } procedure TLCLComboboxCallback.ComboBoxWillPopUp;