Cocoa: IME: in IME state, skip UTF8KeyPress() and KeyPress(), consistent with Win32

This commit is contained in:
rich2014 2023-07-05 00:33:07 +08:00
parent 7031b6b752
commit 019b57e4ce
2 changed files with 35 additions and 28 deletions

View File

@ -584,14 +584,22 @@ begin
if cb.IsCocoaOnlyState then if cb.IsCocoaOnlyState then
begin begin
// in IME state
inherited sendEvent(theEvent); inherited sendEvent(theEvent);
end end
else else
begin begin
// not in IME state
cb.KeyEvBefore(theEvent, allowcocoa); cb.KeyEvBefore(theEvent, allowcocoa);
// may be triggered into IME state
if allowcocoa then if allowcocoa then
inherited sendEvent(theEvent); inherited sendEvent(theEvent);
cb.KeyEvAfter; // retest IME state
if responder.conformsToProtocol(objcprotocol(NSTextInputClientProtocol)) then
cb.CocoaOnlyState := NSTextInputClientProtocol(responder).hasMarkedText;
// if in IME state, pass KeyEvAfter
if not cb.CocoaOnlyState then
cb.KeyEvAfter;
end; end;
finally finally
if Assigned(wnd) then if Assigned(wnd) then

View File

@ -796,9 +796,6 @@ begin
end; end;
procedure TLCLCommonCallback.KeyEvBeforeDown; procedure TLCLCommonCallback.KeyEvBeforeDown;
var
i: integer;
lclHandled: Boolean;
begin begin
// create the CN_KEYDOWN message // create the CN_KEYDOWN message
if _IsSysKey then if _IsSysKey then
@ -824,7 +821,33 @@ begin
Exit; Exit;
end; end;
end; end;
end;
procedure TLCLCommonCallback.KeyEvBeforeUp;
begin
if _IsSysKey then
_KeyMsg.Msg := CN_SYSKEYUP
else
_KeyMsg.Msg := CN_KEYUP;
//Send message to LCL
if _KeyMsg.CharCode <> VK_UNKNOWN then
begin
NotifyApplicationUserInput(Target, _KeyMsg.Msg);
if (DeliverMessage(_KeyMsg) <> 0) or (_KeyMsg.CharCode = VK_UNKNOWN) then
begin
// the LCL has handled the key
KeyEvHandled;
Exit;
end;
end;
end;
procedure TLCLCommonCallback.KeyEvAfterDown(out AllowCocoaHandle: boolean);
var
i: integer;
lclHandled: Boolean;
begin
if (_SendChar) then begin if (_SendChar) then begin
// send the UTF8 keypress // send the UTF8 keypress
i := 0; i := 0;
@ -867,30 +890,6 @@ begin
//LCLCharToMacEvent(Char(_CharMsg.CharCode)); //LCLCharToMacEvent(Char(_CharMsg.CharCode));
end; end;
end;
procedure TLCLCommonCallback.KeyEvBeforeUp;
begin
if _IsSysKey then
_KeyMsg.Msg := CN_SYSKEYUP
else
_KeyMsg.Msg := CN_KEYUP;
//Send message to LCL
if _KeyMsg.CharCode <> VK_UNKNOWN then
begin
NotifyApplicationUserInput(Target, _KeyMsg.Msg);
if (DeliverMessage(_KeyMsg) <> 0) or (_KeyMsg.CharCode = VK_UNKNOWN) then
begin
// the LCL has handled the key
KeyEvHandled;
Exit;
end;
end;
end;
procedure TLCLCommonCallback.KeyEvAfterDown(out AllowCocoaHandle: boolean);
begin
AllowCocoaHandle := False; AllowCocoaHandle := False;
if _KeyHandled then Exit; if _KeyHandled then Exit;