This commit is contained in:
Kovid Goyal 2022-01-26 16:49:10 +05:30
commit 97e58c5b86
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -709,6 +709,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
_glfwInputWindowFocus(window, false); _glfwInputWindowFocus(window, false);
// IME is cancelled when losing the focus // IME is cancelled when losing the focus
if ([window->ns.view hasMarkedText]) { if ([window->ns.view hasMarkedText]) {
[[window->ns.view inputContext] discardMarkedText];
[window->ns.view unmarkText]; [window->ns.view unmarkText];
GLFWkeyevent dummy = {.action = GLFW_RELEASE, .ime_state = GLFW_IME_PREEDIT_CHANGED}; GLFWkeyevent dummy = {.action = GLFW_RELEASE, .ime_state = GLFW_IME_PREEDIT_CHANGED};
_glfwInputKeyboard(window, &dummy); _glfwInputKeyboard(window, &dummy);
@ -1098,8 +1099,7 @@ is_ascii_control_char(char x) {
#define UPDATE_PRE_EDIT_TEXT glfw_keyevent.text = [[markedText string] UTF8String]; glfw_keyevent.ime_state = GLFW_IME_PREEDIT_CHANGED; _glfwInputKeyboard(window, &glfw_keyevent); #define UPDATE_PRE_EDIT_TEXT glfw_keyevent.text = [[markedText string] UTF8String]; glfw_keyevent.ime_state = GLFW_IME_PREEDIT_CHANGED; _glfwInputKeyboard(window, &glfw_keyevent);
const bool previous_has_marked_text = [self hasMarkedText]; const bool previous_has_marked_text = [self hasMarkedText];
NSTextInputContext *inpctx = [NSTextInputContext currentInputContext]; if (input_context && (!input_source_at_last_key_event || ![input_source_at_last_key_event isEqualToString:input_context.selectedKeyboardInputSource])) {
if (inpctx && (!input_source_at_last_key_event || ![input_source_at_last_key_event isEqualToString:inpctx.selectedKeyboardInputSource])) {
if (input_source_at_last_key_event) { if (input_source_at_last_key_event) {
debug_key("Input source changed, clearing pre-edit text and resetting deadkey state\n"); debug_key("Input source changed, clearing pre-edit text and resetting deadkey state\n");
GLFWkeyevent dummy = {.action = GLFW_RELEASE, .ime_state = GLFW_IME_PREEDIT_CHANGED}; GLFWkeyevent dummy = {.action = GLFW_RELEASE, .ime_state = GLFW_IME_PREEDIT_CHANGED};
@ -1108,7 +1108,7 @@ is_ascii_control_char(char x) {
[input_source_at_last_key_event release]; [input_source_at_last_key_event release];
input_source_at_last_key_event = nil; input_source_at_last_key_event = nil;
} }
input_source_at_last_key_event = [inpctx.selectedKeyboardInputSource retain]; input_source_at_last_key_event = [input_context.selectedKeyboardInputSource retain];
[self unmarkText]; [self unmarkText];
} }
@ -1242,11 +1242,10 @@ is_ascii_control_char(char x) {
debug_key("\x1b[33mflagsChanged:\x1b[m modifier: %s native_key: 0x%x (%s) glfw_key: 0x%x %s\n", debug_key("\x1b[33mflagsChanged:\x1b[m modifier: %s native_key: 0x%x (%s) glfw_key: 0x%x %s\n",
mod_name, keycode, safe_name_for_keycode(keycode), key, format_mods(mods)); mod_name, keycode, safe_name_for_keycode(keycode), key, format_mods(mods));
marked_text_cleared_by_insert = false; marked_text_cleared_by_insert = false;
NSTextInputContext *inpctx = [NSTextInputContext currentInputContext]; if (process_text && input_context) {
if (process_text && inpctx) {
// this will call insertText which will fill up _glfw.ns.text // this will call insertText which will fill up _glfw.ns.text
in_key_handler = 2; in_key_handler = 2;
[inpctx handleEvent:event]; [input_context handleEvent:event];
in_key_handler = 0; in_key_handler = 0;
if (marked_text_cleared_by_insert) { if (marked_text_cleared_by_insert) {
debug_key("Clearing pre-edit text because insertText called from flagsChanged\n"); debug_key("Clearing pre-edit text because insertText called from flagsChanged\n");
@ -1379,7 +1378,7 @@ is_ascii_control_char(char x) {
bool had_marked_text = [self hasMarkedText]; bool had_marked_text = [self hasMarkedText];
[self unmarkText]; [self unmarkText];
if (had_marked_text && (!in_key_handler || in_key_handler == 2)) { if (had_marked_text && (!in_key_handler || in_key_handler == 2)) {
debug_key("Clearing pre-edit because setMarkedText called from event loop or flagsChanged\n"); debug_key("Clearing pre-edit because setMarkedText called from %s\n", in_key_handler ? "flagsChanged" : "event loop");
GLFWkeyevent glfw_keyevent = {.ime_state = GLFW_IME_PREEDIT_CHANGED}; GLFWkeyevent glfw_keyevent = {.ime_state = GLFW_IME_PREEDIT_CHANGED};
_glfwInputKeyboard(window, &glfw_keyevent); _glfwInputKeyboard(window, &glfw_keyevent);
_glfw.ns.text[0] = 0; _glfw.ns.text[0] = 0;