Cocoa: TCocoaComboBox: keep text case after ItemIndex changed when cbactRetainPrefixCase set

This commit is contained in:
rich2014 2023-06-23 12:27:19 +08:00
parent ffe062f433
commit b9b1f7f310
2 changed files with 42 additions and 0 deletions

View File

@ -1413,7 +1413,10 @@ begin
if idx<0 then
Result := NSNotFound
else
begin
TComboBoxAsyncHelper.ResetTextIfNecessary(lclGetTarget, string_.UTF8String);
Result := idx;
end;
end;
end;

View File

@ -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;