Cocoa: IME: improve NSKeyUp and fix the issue in TComboBox

fix the issue that the first letter is added when using IME in TComboBox with AutoComplete (trigger AutoComplete in KeyUp)
This commit is contained in:
rich2014 2023-07-01 20:00:34 +08:00
parent b9473bdb50
commit fda1f35008

View File

@ -551,14 +551,24 @@ begin
begin
responder := win.firstResponder;
cb := responder.lclGetCallback;
if Assigned(cb) and (theEvent.type_=NSKeyDown) then
if Assigned(cb) then
begin
// set CocoaOnlyState when NSKeyDown only,
// keep last CocoaOnlyState when NSKeyUp
if responder.conformsToProtocol(objcprotocol(NSTextInputClientProtocol)) then
cb.CocoaOnlyState := NSTextInputClientProtocol(responder).hasMarkedText
else
cb.CocoaOnlyState := false;
case theEvent.type_ of
NSKeyDown:
// when NSKeyDown, always reset CocoaOnlyState
if responder.conformsToProtocol(objcprotocol(NSTextInputClientProtocol)) then
cb.CocoaOnlyState := NSTextInputClientProtocol(responder).hasMarkedText
else
cb.CocoaOnlyState := false;
NSKeyUp:
// when NSKeyUp, reset CocoaOnlyState only if it's false (last KeyDown set)
// keep true if CocoaOnlyState=true
if not cb.CocoaOnlyState then
begin
if responder.conformsToProtocol(objcprotocol(NSTextInputClientProtocol)) then
cb.CocoaOnlyState := NSTextInputClientProtocol(responder).hasMarkedText;
end;
end;
end;
end;