Skip to content

Commit f0c663d

Browse files
committed
macOS: Improve handling of IME extended input
Compose characters are now highlighted and the IME panel moves along with the text Fixes #1586 Fixes #1461
1 parent e36e44a commit f0c663d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

docs/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
3737
- Make live resizing of OS windows smoother and show the size in cells
3838
while the resize is in progress.
3939

40+
- macOS: Improve handling of IME extended input. Compose characters
41+
are now highlighted and the IME panel moves along with the text
42+
(:pull:`1586`). Also fixes handling of delete key in Chinese IME
43+
(:iss:`1461`)
44+
4045
- When a window is closed, switch focus to the previously active window (if
4146
any) instead of picking the previous window in the layout (:iss:`1450`)
4247

glfw/cocoa_window.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ - (void)keyDown:(NSEvent *)event
831831
} else {
832832
static UniChar text[256];
833833
UniCharCount char_count = 0;
834+
const bool in_compose_sequence = window->ns.deadKeyState != 0;
834835
if (UCKeyTranslate(
835836
[(NSData*) _glfw.ns.unicodeData bytes],
836837
scancode,
@@ -856,8 +857,14 @@ - (void)keyDown:(NSEvent *)event
856857
}
857858
if (window->ns.deadKeyState && (char_count == 0 || scancode == 0x75)) {
858859
// 0x75 is the delete key which needs to be ignored during a compose sequence
859-
debug_key(@"Ignoring dead key (text: %s).\n", format_text(_glfw.ns.text));
860+
debug_key(@"Sending pre-edit text for dead key (text: %s markedText: %@).\n", format_text(_glfw.ns.text), markedText);
861+
_glfwInputKeyboard(window, key, scancode, GLFW_PRESS, mods,
862+
[[markedText string] UTF8String], 1); // update pre-edit text
860863
return;
864+
} else if (in_compose_sequence) {
865+
debug_key(@"Clearing pre-edit text at end of compose sequence\n");
866+
_glfwInputKeyboard(window, key, scancode, GLFW_PRESS, mods,
867+
NULL, 1); // clear pre-edit text
861868
}
862869
}
863870
if (is_ascii_control_char(_glfw.ns.text[0])) _glfw.ns.text[0] = 0; // don't send text for ascii control codes

0 commit comments

Comments
 (0)