summaryrefslogtreecommitdiff
path: root/src/androidterm.c
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2023-10-05 14:23:20 +0800
committerPo Lu <luangruo@yahoo.com>2023-10-05 14:23:20 +0800
commit123b77436e187c6254d4585d08135a44077528d1 (patch)
tree5257a4dbb4d5dc5d1446a58cec224903494bbbb5 /src/androidterm.c
parent253f1aff1ab00e9794f3cfcf50e86e335f411242 (diff)
downloademacs-123b77436e187c6254d4585d08135a44077528d1.tar.gz
Introduce an input method callback required by Android 34
* java/org/gnu/emacs/EmacsInputConnection.java (replaceText): New function. * java/org/gnu/emacs/EmacsNative.java (replaceText): Declare native function. * src/androidgui.h (enum android_ime_operation): New operation ANDROID_IME_REPLACE_TEXT. * src/androidterm.c (android_handle_ime_event): Decode text when encountering an ANDROID_IME_REPLACE_TEXT operation. Return if decoding overflowed rather than presenting Qnil to textconv functions. (replaceText): New JNI function. * src/frame.h (enum text_conversion_operation): New operation TEXTCONV_REPLACE_TEXT. * src/textconv.c (really_commit_text): Move point to start if the composing region is set. (really_replace_text): New function. (handle_pending_conversion_events_1) <TEXTCONV_REPLACE_TEXT>: New case. (replace_text): New function. * src/textconv.h: Update prototypes.
Diffstat (limited to 'src/androidterm.c')
-rw-r--r--src/androidterm.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/androidterm.c b/src/androidterm.c
index 438f8ce1fbb..9b00ad85642 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -687,9 +687,17 @@ android_handle_ime_event (union android_event *event, struct frame *f)
{
case ANDROID_IME_COMMIT_TEXT:
case ANDROID_IME_SET_COMPOSING_TEXT:
+ case ANDROID_IME_REPLACE_TEXT:
text = android_decode_utf16 (event->ime.text,
event->ime.length);
xfree (event->ime.text);
+
+ /* Return should text be long enough that it overflows ptrdiff_t.
+ Such circumstances are detected within android_decode_utf16. */
+
+ if (NILP (text))
+ return;
+
break;
default:
@@ -773,6 +781,12 @@ android_handle_ime_event (union android_event *event, struct frame *f)
case ANDROID_IME_REQUEST_CURSOR_UPDATES:
android_request_cursor_updates (f, event->ime.length);
break;
+
+ case ANDROID_IME_REPLACE_TEXT:
+ replace_text (f, event->ime.start, event->ime.end,
+ text, event->ime.position,
+ event->ime.counter);
+ break;
}
}
@@ -4856,6 +4870,39 @@ NATIVE_NAME (finishComposingText) (JNIEnv *env, jobject object,
android_write_event (&event);
}
+JNIEXPORT void JNICALL
+NATIVE_NAME (replaceText) (JNIEnv *env, jobject object, jshort window,
+ jint start, jint end, jobject text,
+ int new_cursor_position, jobject attribute)
+{
+ JNI_STACK_ALIGNMENT_PROLOGUE;
+
+ union android_event event;
+ size_t length;
+
+ /* First, obtain a copy of the Java string. */
+ text = android_copy_java_string (env, text, &length);
+
+ if (!text)
+ return;
+
+ /* Next, populate the event with the information in this function's
+ arguments. */
+
+ event.ime.type = ANDROID_INPUT_METHOD;
+ event.ime.serial = ++event_serial;
+ event.ime.window = window;
+ event.ime.operation = ANDROID_IME_REPLACE_TEXT;
+ event.ime.start = start + 1;
+ event.ime.end = end + 1;
+ event.ime.length = length;
+ event.ime.position = new_cursor_position;
+ event.ime.text = text;
+ event.ime.counter = ++edit_counter;
+
+ android_write_event (&event);
+}
+
/* Structure describing the context used for a text query. */
struct android_conversion_query_context