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
begin
// in IME state
inherited sendEvent(theEvent);
end
else
begin
// not in IME state
cb.KeyEvBefore(theEvent, allowcocoa);
// may be triggered into IME state
if allowcocoa then
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;
finally
if Assigned(wnd) then

View File

@ -796,9 +796,6 @@ begin
end;
procedure TLCLCommonCallback.KeyEvBeforeDown;
var
i: integer;
lclHandled: Boolean;
begin
// create the CN_KEYDOWN message
if _IsSysKey then
@ -824,7 +821,33 @@ begin
Exit;
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
// send the UTF8 keypress
i := 0;
@ -867,30 +890,6 @@ begin
//LCLCharToMacEvent(Char(_CharMsg.CharCode));
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;
if _KeyHandled then Exit;