From: Po Lu Date: Mon, 5 Jun 2023 02:38:25 +0000 (+0800) Subject: Update Android port X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=66783af554176c68cb58726aeff4ae6a23224234;p=emacs.git Update Android port * java/org/gnu/emacs/EmacsNative.java (EmacsNative): New function clearInputFlags. * java/org/gnu/emacs/EmacsView.java (onCreateInputConnection): Stop reporting changes after a new input method connection is established. * src/androidterm.c (android_handle_ime_event): Implement that change. (JNICALL): New function. --- diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java index f03736fe614..cb1c6caa79a 100644 --- a/java/org/gnu/emacs/EmacsNative.java +++ b/java/org/gnu/emacs/EmacsNative.java @@ -221,6 +221,7 @@ public final class EmacsNative int flags); public static native void requestSelectionUpdate (short window); public static native void requestCursorUpdates (short window, int mode); + public static native void clearInputFlags (short window); /* Return the current value of the selection, or -1 upon diff --git a/java/org/gnu/emacs/EmacsView.java b/java/org/gnu/emacs/EmacsView.java index c223dfa7911..a78dec08839 100644 --- a/java/org/gnu/emacs/EmacsView.java +++ b/java/org/gnu/emacs/EmacsView.java @@ -627,6 +627,10 @@ public final class EmacsView extends ViewGroup return null; } + /* Reset flags set by the previous input method. */ + + EmacsNative.clearInputFlags (window.handle); + /* Obtain the current position of point and set it as the selection. Don't do this under one specific situation: if `android_update_ic' is being called in the main thread, trying @@ -663,10 +667,6 @@ public final class EmacsView extends ViewGroup if (inputConnection == null) inputConnection = new EmacsInputConnection (this); - else - /* Reset the composing region, in case there is still composing - text. */ - inputConnection.finishComposingText (); /* Return the input connection. */ return inputConnection; diff --git a/src/androidterm.c b/src/androidterm.c index d8a8b4c2d71..afa10a1b94b 100644 --- a/src/androidterm.c +++ b/src/androidterm.c @@ -675,6 +675,7 @@ static void android_handle_ime_event (union android_event *event, struct frame *f) { Lisp_Object text UNINIT; + struct android_output *output; /* First, decode the text if necessary. */ @@ -707,8 +708,23 @@ android_handle_ime_event (union android_event *event, struct frame *f) break; case ANDROID_IME_FINISH_COMPOSING_TEXT: + + if (event->ime.length == 2) + { + output = FRAME_ANDROID_OUTPUT (f); + + /* A new input method has connected to Emacs. Stop + reporting changes that the previous input method has + asked to monitor. */ + + output->extracted_text_flags = 0; + output->extracted_text_token = 0; + output->extracted_text_hint = 0; + output->need_cursor_updates = false; + } + finish_composing_text (f, event->ime.counter, - event->ime.length); + event->ime.length == 1); break; case ANDROID_IME_SET_COMPOSING_TEXT: @@ -5580,6 +5596,36 @@ NATIVE_NAME (requestCursorUpdates) (JNIEnv *env, jobject object, android_write_event (&event); } +/* Notice that a new input method connection has been initialized and + clear cursor update requests, extracted text requests, and the + composing region. */ + +JNIEXPORT void JNICALL +NATIVE_NAME (clearInputFlags) (JNIEnv *env, jobject object, + jshort window) +{ + JNI_STACK_ALIGNMENT_PROLOGUE; + + union android_event event; + + event.ime.type = ANDROID_INPUT_METHOD; + event.ime.serial = ++event_serial; + event.ime.window = window; + event.ime.operation = ANDROID_IME_FINISH_COMPOSING_TEXT; + event.ime.start = 0; + event.ime.end = 0; + + /* This value of `length' means that updates to the cursor position + and extracted text should not be reported anymore. */ + + event.ime.length = 2; + event.ime.position = 0; + event.ime.text = NULL; + event.ime.counter = ++edit_counter; + + android_write_event (&event); +} + #ifdef __clang__ #pragma clang diagnostic pop #else