diff options
| author | Po Lu | 2023-03-12 17:07:57 +0800 |
|---|---|---|
| committer | Po Lu | 2023-03-12 17:07:57 +0800 |
| commit | 82b4b9e8692c349a45d319fe05c9fbfed4ab203d (patch) | |
| tree | 5fe33349f7992327f23d124c19b6d9e5ebb8f023 /src/androidterm.c | |
| parent | 3573db24ad0125d1a553e85eb08c93c61c62ef33 (diff) | |
| download | emacs-82b4b9e8692c349a45d319fe05c9fbfed4ab203d.tar.gz emacs-82b4b9e8692c349a45d319fe05c9fbfed4ab203d.zip | |
Update Android port
* src/androidterm.c (NATIVE_NAME, JNICALL)
(android_build_extracted_text, android_update_selection): Use
0-based indices for Android buffer positions. Also, report
surrounding text relative to the region, not to the cursor.
* src/textconv.c (textconv_query): Accept new values of
position.
(really_set_composing_text): Use ephemeral last point.
Diffstat (limited to 'src/androidterm.c')
| -rw-r--r-- | src/androidterm.c | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/src/androidterm.c b/src/androidterm.c index 397971e3c87..ed375ef53fe 100644 --- a/src/androidterm.c +++ b/src/androidterm.c | |||
| @@ -4811,7 +4811,7 @@ NATIVE_NAME (getTextAfterCursor) (JNIEnv *env, jobject object, jshort window, | |||
| 4811 | jstring string; | 4811 | jstring string; |
| 4812 | 4812 | ||
| 4813 | /* First, set up the conversion query. */ | 4813 | /* First, set up the conversion query. */ |
| 4814 | context.query.position = 0; | 4814 | context.query.position = EMACS_INT_MAX; |
| 4815 | context.query.direction = TEXTCONV_FORWARD_CHAR; | 4815 | context.query.direction = TEXTCONV_FORWARD_CHAR; |
| 4816 | context.query.factor = min (length, 65535); | 4816 | context.query.factor = min (length, 65535); |
| 4817 | context.query.operation = TEXTCONV_RETRIEVAL; | 4817 | context.query.operation = TEXTCONV_RETRIEVAL; |
| @@ -4855,7 +4855,7 @@ NATIVE_NAME (getTextBeforeCursor) (JNIEnv *env, jobject object, jshort window, | |||
| 4855 | jstring string; | 4855 | jstring string; |
| 4856 | 4856 | ||
| 4857 | /* First, set up the conversion query. */ | 4857 | /* First, set up the conversion query. */ |
| 4858 | context.query.position = 0; | 4858 | context.query.position = TYPE_MINIMUM (EMACS_INT); |
| 4859 | context.query.direction = TEXTCONV_BACKWARD_CHAR; | 4859 | context.query.direction = TEXTCONV_BACKWARD_CHAR; |
| 4860 | context.query.factor = min (length, 65535); | 4860 | context.query.factor = min (length, 65535); |
| 4861 | context.query.operation = TEXTCONV_RETRIEVAL; | 4861 | context.query.operation = TEXTCONV_RETRIEVAL; |
| @@ -4936,8 +4936,8 @@ NATIVE_NAME (setComposingRegion) (JNIEnv *env, jobject object, jshort window, | |||
| 4936 | event.ime.serial = ++event_serial; | 4936 | event.ime.serial = ++event_serial; |
| 4937 | event.ime.window = window; | 4937 | event.ime.window = window; |
| 4938 | event.ime.operation = ANDROID_IME_SET_COMPOSING_REGION; | 4938 | event.ime.operation = ANDROID_IME_SET_COMPOSING_REGION; |
| 4939 | event.ime.start = start; | 4939 | event.ime.start = start + 1; |
| 4940 | event.ime.end = end; | 4940 | event.ime.end = end + 1; |
| 4941 | event.ime.length = 0; | 4941 | event.ime.length = 0; |
| 4942 | event.ime.position = 0; | 4942 | event.ime.position = 0; |
| 4943 | event.ime.text = NULL; | 4943 | event.ime.text = NULL; |
| @@ -4961,8 +4961,8 @@ NATIVE_NAME (setSelection) (JNIEnv *env, jobject object, jshort window, | |||
| 4961 | event.ime.serial = ++event_serial; | 4961 | event.ime.serial = ++event_serial; |
| 4962 | event.ime.window = window; | 4962 | event.ime.window = window; |
| 4963 | event.ime.operation = ANDROID_IME_SET_POINT; | 4963 | event.ime.operation = ANDROID_IME_SET_POINT; |
| 4964 | event.ime.start = start; | 4964 | event.ime.start = start + 1; |
| 4965 | event.ime.end = end; | 4965 | event.ime.end = end + 1; |
| 4966 | event.ime.length = 0; | 4966 | event.ime.length = 0; |
| 4967 | event.ime.position = start; | 4967 | event.ime.position = start; |
| 4968 | event.ime.text = NULL; | 4968 | event.ime.text = NULL; |
| @@ -5040,11 +5040,12 @@ NATIVE_NAME (getSelection) (JNIEnv *env, jobject object, jshort window) | |||
| 5040 | return NULL; | 5040 | return NULL; |
| 5041 | 5041 | ||
| 5042 | /* Wraparound actually makes more sense than truncation; at least | 5042 | /* Wraparound actually makes more sense than truncation; at least |
| 5043 | editing will sort of work. */ | 5043 | editing will sort of work. Convert the positions to start from |
| 5044 | index 0, as that is what Android expects. */ | ||
| 5044 | contents[0] = (unsigned int) min (context.point, | 5045 | contents[0] = (unsigned int) min (context.point, |
| 5045 | context.mark); | 5046 | context.mark) - 1; |
| 5046 | contents[1] = (unsigned int) max (context.point, | 5047 | contents[1] = (unsigned int) max (context.point, |
| 5047 | context.mark); | 5048 | context.mark) - 1; |
| 5048 | 5049 | ||
| 5049 | /* Now create the array. */ | 5050 | /* Now create the array. */ |
| 5050 | array = (*env)->NewIntArray (env, 2); | 5051 | array = (*env)->NewIntArray (env, 2); |
| @@ -5209,8 +5210,11 @@ android_build_extracted_text (jstring text, ptrdiff_t start, | |||
| 5209 | min (offset, TYPE_MAXIMUM (jint))); | 5210 | min (offset, TYPE_MAXIMUM (jint))); |
| 5210 | (*env)->SetIntField (env, object, text_class.selection_end, | 5211 | (*env)->SetIntField (env, object, text_class.selection_end, |
| 5211 | min (offset, TYPE_MAXIMUM (jint))); | 5212 | min (offset, TYPE_MAXIMUM (jint))); |
| 5213 | |||
| 5214 | /* Subtract 1 from start: point indices in Emacs start from 1, but | ||
| 5215 | Android expects 0. */ | ||
| 5212 | (*env)->SetIntField (env, object, text_class.start_offset, | 5216 | (*env)->SetIntField (env, object, text_class.start_offset, |
| 5213 | min (start, TYPE_MAXIMUM (jint))); | 5217 | min (start - 1, TYPE_MAXIMUM (jint))); |
| 5214 | (*env)->SetObjectField (env, object, text_class.text, text); | 5218 | (*env)->SetObjectField (env, object, text_class.text, text); |
| 5215 | return object; | 5219 | return object; |
| 5216 | } | 5220 | } |
| @@ -5311,8 +5315,11 @@ NATIVE_NAME (getExtractedText) (JNIEnv *env, jobject ignored_object, | |||
| 5311 | min (context.offset, TYPE_MAXIMUM (jint))); | 5315 | min (context.offset, TYPE_MAXIMUM (jint))); |
| 5312 | (*env)->SetIntField (env, object, text_class.selection_end, | 5316 | (*env)->SetIntField (env, object, text_class.selection_end, |
| 5313 | min (context.offset, TYPE_MAXIMUM (jint))); | 5317 | min (context.offset, TYPE_MAXIMUM (jint))); |
| 5318 | |||
| 5319 | /* Subtract 1 from start: point indices in Emacs start from 1, but | ||
| 5320 | Android expects 0. */ | ||
| 5314 | (*env)->SetIntField (env, object, text_class.start_offset, | 5321 | (*env)->SetIntField (env, object, text_class.start_offset, |
| 5315 | min (context.start, TYPE_MAXIMUM (jint))); | 5322 | min (context.start - 1, TYPE_MAXIMUM (jint))); |
| 5316 | (*env)->SetObjectField (env, object, text_class.text, string); | 5323 | (*env)->SetObjectField (env, object, text_class.text, string); |
| 5317 | return object; | 5324 | return object; |
| 5318 | } | 5325 | } |
| @@ -5397,8 +5404,9 @@ android_update_selection (struct frame *f, struct window *w) | |||
| 5397 | { | 5404 | { |
| 5398 | eassert (MARKERP (f->conversion.compose_region_end)); | 5405 | eassert (MARKERP (f->conversion.compose_region_end)); |
| 5399 | 5406 | ||
| 5400 | start = marker_position (f->conversion.compose_region_start); | 5407 | /* Indexing in android starts from 0 instead of 1. */ |
| 5401 | end = marker_position (f->conversion.compose_region_end); | 5408 | start = marker_position (f->conversion.compose_region_start) - 1; |
| 5409 | end = marker_position (f->conversion.compose_region_end) - 1; | ||
| 5402 | } | 5410 | } |
| 5403 | else | 5411 | else |
| 5404 | start = -1, end = -1; | 5412 | start = -1, end = -1; |
| @@ -5423,9 +5431,11 @@ android_update_selection (struct frame *f, struct window *w) | |||
| 5423 | 5431 | ||
| 5424 | /* Send the update. Android doesn't have a concept of ``point'' and | 5432 | /* Send the update. Android doesn't have a concept of ``point'' and |
| 5425 | ``mark''; instead, it only has a selection, where the start of | 5433 | ``mark''; instead, it only has a selection, where the start of |
| 5426 | the selection is less than or equal to the end. */ | 5434 | the selection is less than or equal to the end. Also, convert |
| 5427 | android_update_ic (FRAME_ANDROID_WINDOW (f), min (point, mark), | 5435 | the indices from 1-based Emacs indices to 0-based Android |
| 5428 | max (point, mark), start, end); | 5436 | ones. */ |
| 5437 | android_update_ic (FRAME_ANDROID_WINDOW (f), min (point, mark) - 1, | ||
| 5438 | max (point, mark) - 1, start, end); | ||
| 5429 | 5439 | ||
| 5430 | /* Update the extracted text as well, if the input method has asked | 5440 | /* Update the extracted text as well, if the input method has asked |
| 5431 | for updates. 1 is | 5441 | for updates. 1 is |
| @@ -5438,25 +5448,28 @@ android_update_selection (struct frame *f, struct window *w) | |||
| 5438 | text = get_extracted_text (f, min (hint, 600), &start, | 5448 | text = get_extracted_text (f, min (hint, 600), &start, |
| 5439 | &offset, &length, &bytes); | 5449 | &offset, &length, &bytes); |
| 5440 | 5450 | ||
| 5441 | /* Make a string out of the extracted text. */ | 5451 | if (text) |
| 5442 | string = android_text_to_string (android_java_env, | ||
| 5443 | text, length, bytes); | ||
| 5444 | xfree (text); | ||
| 5445 | android_exception_check (); | ||
| 5446 | |||
| 5447 | /* Make extracted text out of that string. */ | ||
| 5448 | extracted = android_build_extracted_text (string, start, | ||
| 5449 | offset); | ||
| 5450 | android_exception_check_1 (string); | ||
| 5451 | ANDROID_DELETE_LOCAL_REF (string); | ||
| 5452 | |||
| 5453 | if (extracted) | ||
| 5454 | { | 5452 | { |
| 5455 | /* extracted is now an associated ExtractedText object. | 5453 | /* Make a string out of the extracted text. */ |
| 5456 | Perform the update. */ | 5454 | string = android_text_to_string (android_java_env, |
| 5457 | android_update_extracted_text (FRAME_ANDROID_WINDOW (f), | 5455 | text, length, bytes); |
| 5458 | extracted, token); | 5456 | xfree (text); |
| 5459 | ANDROID_DELETE_LOCAL_REF (extracted); | 5457 | android_exception_check (); |
| 5458 | |||
| 5459 | /* Make extracted text out of that string. */ | ||
| 5460 | extracted = android_build_extracted_text (string, start, | ||
| 5461 | offset); | ||
| 5462 | android_exception_check_1 (string); | ||
| 5463 | ANDROID_DELETE_LOCAL_REF (string); | ||
| 5464 | |||
| 5465 | if (extracted) | ||
| 5466 | { | ||
| 5467 | /* extracted is now an associated ExtractedText object. | ||
| 5468 | Perform the update. */ | ||
| 5469 | android_update_extracted_text (FRAME_ANDROID_WINDOW (f), | ||
| 5470 | extracted, token); | ||
| 5471 | ANDROID_DELETE_LOCAL_REF (extracted); | ||
| 5472 | } | ||
| 5460 | } | 5473 | } |
| 5461 | } | 5474 | } |
| 5462 | } | 5475 | } |