aboutsummaryrefslogtreecommitdiffstats
path: root/src/androidterm.c
diff options
context:
space:
mode:
authorPo Lu2023-02-15 22:51:44 +0800
committerPo Lu2023-02-15 22:51:44 +0800
commitcf24b61985c26cbf2e5a24cb0b64a8528aa3a9cc (patch)
treeb69f8dbb50e3e2f6f09caa05aecbee5241876f62 /src/androidterm.c
parentdd7066901f67233c09f3b0409a57db7686c7ea5b (diff)
downloademacs-cf24b61985c26cbf2e5a24cb0b64a8528aa3a9cc.tar.gz
emacs-cf24b61985c26cbf2e5a24cb0b64a8528aa3a9cc.zip
Update Android port
* doc/emacs/input.texi (On-Screen Keyboards): * doc/lispref/commands.texi (Misc Events): Improve documentation of text conversion stuff. * java/org/gnu/emacs/EmacsInputConnection.java (beginBatchEdit) (endBatchEdit, commitCompletion, commitText, deleteSurroundingText) (finishComposingText, getSelectedText, getTextAfterCursor) (EmacsInputConnection, setComposingRegion, performEditorAction) (getExtractedText): Condition debug code on DEBUG_IC. * java/org/gnu/emacs/EmacsService.java (EmacsService, updateIC): Likewise. * lisp/bindings.el (global-map): * lisp/electric.el (global-map): Make `text-conversion' `analyze-text-conversion'. * lisp/progmodes/prog-mode.el (prog-mode): Enable text conversion in input methods. * lisp/simple.el (analyze-text-conversion): New function. * lisp/textmodes/text-mode.el (text-conversion-style) (text-mode): Likewise. * src/androidterm.c (android_handle_ime_event): Handle set_point_and_mark. (android_sync_edit): Give Emacs 100 ms instead. (android_perform_conversion_query): Skip the active region, not the conversion region. (getSelectedText): Implement properly. (android_update_selection): Expose mark to input methods. (android_reset_conversion): Handle `text-conversion-style'. * src/buffer.c (init_buffer_once, syms_of_buffer): Add buffer local variable `text-conversion-style'. * src/buffer.h (struct buffer, bset_text_conversion_style): New fields. * src/emacs.c (android_emacs_init): Call syms_of_textconv. * src/frame.h (enum text_conversion_operation): Rename TEXTCONV_SET_POINT. * src/lisp.h: Export syms_of_textconv. * src/marker.c (set_marker_internal): Force redisplay when the mark is set and the buffer is visible on builds that use text conversion. Explain why. * src/textconv.c (copy_buffer): Fix copying past gap. (get_mark): New function. (textconv_query): Implement new flag. (sync_overlay): New function. Display conversion text in an overlay. (record_buffer_change, really_commit_text) (really_set_composing_text, really_set_composing_region) (really_delete_surrounding_text, really_set_point) (handle_pending_conversion_events_1, decrement_inside) (handle_pending_conversion_events, textconv_set_point) (get_extracted_text, register_textconv_interface): Various fixes and improvements. * src/textconv.h (struct textconv_interface): Update documentation. * src/window.h (GCALIGNED_STRUCT): New field `prev_mark'. * src/xdisp.c (mark_window_display_accurate_1): Handle prev_mark.
Diffstat (limited to 'src/androidterm.c')
-rw-r--r--src/androidterm.c88
1 files changed, 67 insertions, 21 deletions
diff --git a/src/androidterm.c b/src/androidterm.c
index 767b7d8240c..0c990d3d2d2 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -621,8 +621,9 @@ android_handle_ime_event (union android_event *event, struct frame *f)
621 break; 621 break;
622 622
623 case ANDROID_IME_SET_POINT: 623 case ANDROID_IME_SET_POINT:
624 textconv_set_point (f, event->ime.position, 624 textconv_set_point_and_mark (f, event->ime.start,
625 event->ime.counter); 625 event->ime.end,
626 event->ime.counter);
626 break; 627 break;
627 628
628 case ANDROID_IME_START_BATCH_EDIT: 629 case ANDROID_IME_START_BATCH_EDIT:
@@ -4305,7 +4306,7 @@ static sem_t edit_sem;
4305 4306
4306 Every time one of the text retrieval functions is called and an 4307 Every time one of the text retrieval functions is called and an
4307 editing request is made, Emacs gives the main thread approximately 4308 editing request is made, Emacs gives the main thread approximately
4308 50 ms to process it, in order to mostly keep the input method in 4309 100 ms to process it, in order to mostly keep the input method in
4309 sync with the buffer contents. */ 4310 sync with the buffer contents. */
4310 4311
4311static void 4312static void
@@ -4319,7 +4320,7 @@ android_sync_edit (void)
4319 return; 4320 return;
4320 4321
4321 start = current_timespec (); 4322 start = current_timespec ();
4322 end = timespec_add (start, make_timespec (0, 50000000)); 4323 end = timespec_add (start, make_timespec (0, 100000000));
4323 4324
4324 while (true) 4325 while (true)
4325 { 4326 {
@@ -4550,8 +4551,7 @@ android_perform_conversion_query (void *data)
4550 if (!f) 4551 if (!f)
4551 return; 4552 return;
4552 4553
4553 textconv_query (f, &context->query, 4554 textconv_query (f, &context->query, TEXTCONV_SKIP_ACTIVE_REGION);
4554 TEXTCONV_SKIP_CONVERSION_REGION);
4555 4555
4556 /* context->query.text will have been set even if textconv_query 4556 /* context->query.text will have been set even if textconv_query
4557 returns 1. */ 4557 returns 1. */
@@ -4649,13 +4649,6 @@ android_text_to_string (JNIEnv *env, char *buffer, ptrdiff_t n,
4649} 4649}
4650 4650
4651JNIEXPORT jstring JNICALL 4651JNIEXPORT jstring JNICALL
4652NATIVE_NAME (getSelectedText) (JNIEnv *env, jobject object,
4653 jshort window)
4654{
4655 return NULL;
4656}
4657
4658JNIEXPORT jstring JNICALL
4659NATIVE_NAME (getTextAfterCursor) (JNIEnv *env, jobject object, jshort window, 4652NATIVE_NAME (getTextAfterCursor) (JNIEnv *env, jobject object, jshort window,
4660 jint length, jint flags) 4653 jint length, jint flags)
4661{ 4654{
@@ -4805,8 +4798,8 @@ NATIVE_NAME (setSelection) (JNIEnv *env, jobject object, jshort window,
4805 event.ime.serial = ++event_serial; 4798 event.ime.serial = ++event_serial;
4806 event.ime.window = window; 4799 event.ime.window = window;
4807 event.ime.operation = ANDROID_IME_SET_POINT; 4800 event.ime.operation = ANDROID_IME_SET_POINT;
4808 event.ime.start = 0; 4801 event.ime.start = start;
4809 event.ime.end = 0; 4802 event.ime.end = end;
4810 event.ime.length = 0; 4803 event.ime.length = 0;
4811 event.ime.position = start; 4804 event.ime.position = start;
4812 event.ime.text = NULL; 4805 event.ime.text = NULL;
@@ -5068,6 +5061,34 @@ NATIVE_NAME (getExtractedText) (JNIEnv *env, jobject ignored_object,
5068 return object; 5061 return object;
5069} 5062}
5070 5063
5064JNIEXPORT jstring JNICALL
5065NATIVE_NAME (getSelectedText) (JNIEnv *env, jobject object,
5066 jshort window)
5067{
5068 struct android_get_extracted_text_context context;
5069 jstring string;
5070
5071 context.hint_max_chars = -1;
5072 context.token = 0;
5073 context.text = NULL;
5074 context.window = window;
5075
5076 android_sync_edit ();
5077 if (android_run_in_emacs_thread (android_get_extracted_text,
5078 &context))
5079 return NULL;
5080
5081 if (!context.text)
5082 return NULL;
5083
5084 /* Encode the returned text. */
5085 string = android_text_to_string (env, context.text, context.length,
5086 context.bytes);
5087 free (context.text);
5088
5089 return string;
5090}
5091
5071#ifdef __clang__ 5092#ifdef __clang__
5072#pragma clang diagnostic pop 5093#pragma clang diagnostic pop
5073#else 5094#else
@@ -5083,7 +5104,8 @@ NATIVE_NAME (getExtractedText) (JNIEnv *env, jobject ignored_object,
5083static void 5104static void
5084android_update_selection (struct frame *f, struct window *w) 5105android_update_selection (struct frame *f, struct window *w)
5085{ 5106{
5086 ptrdiff_t start, end, point; 5107 ptrdiff_t start, end, point, mark;
5108 struct buffer *b;
5087 5109
5088 if (MARKERP (f->conversion.compose_region_start)) 5110 if (MARKERP (f->conversion.compose_region_start))
5089 { 5111 {
@@ -5103,12 +5125,20 @@ android_update_selection (struct frame *f, struct window *w)
5103 if (!w) 5125 if (!w)
5104 w = XWINDOW (f->selected_window); 5126 w = XWINDOW (f->selected_window);
5105 5127
5106 /* Figure out where the point is. */ 5128 /* Figure out where the point and mark are. If the mark is not
5129 active, then point is set to equal mark. */
5130 b = XBUFFER (w->contents);
5107 point = min (w->last_point, TYPE_MAXIMUM (jint)); 5131 point = min (w->last_point, TYPE_MAXIMUM (jint));
5132 mark = ((!NILP (BVAR (b, mark_active))
5133 && w->last_mark != -1)
5134 ? min (w->last_mark, TYPE_MAXIMUM (jint))
5135 : point);
5108 5136
5109 /* Send the update. */ 5137 /* Send the update. Android doesn't have a concept of ``point'' and
5110 android_update_ic (FRAME_ANDROID_WINDOW (f), point, point, 5138 ``mark''; instead, it only has a selection, where the start of
5111 start, end); 5139 the selection is less than or equal to the end. */
5140 android_update_ic (FRAME_ANDROID_WINDOW (f), min (point, mark),
5141 max (point, mark), start, end);
5112} 5142}
5113 5143
5114/* Notice that the input method connection to F should be reset as a 5144/* Notice that the input method connection to F should be reset as a
@@ -5117,16 +5147,32 @@ android_update_selection (struct frame *f, struct window *w)
5117static void 5147static void
5118android_reset_conversion (struct frame *f) 5148android_reset_conversion (struct frame *f)
5119{ 5149{
5150 enum android_ic_mode mode;
5151 struct window *w;
5152 struct buffer *buffer;
5153
5120 /* Reset the input method. 5154 /* Reset the input method.
5121 5155
5122 Pick an appropriate ``input mode'' based on whether or not the 5156 Pick an appropriate ``input mode'' based on whether or not the
5123 minibuffer window is selected; this controls whether or not 5157 minibuffer window is selected; this controls whether or not
5124 ``RET'' inserts a newline or sends an actual key event. */ 5158 ``RET'' inserts a newline or sends an actual key event. */
5159
5160 w = XWINDOW (f->selected_window);
5161 buffer = XBUFFER (WINDOW_BUFFER (w));
5162
5163 if (NILP (BVAR (buffer, text_conversion_style)))
5164 mode = ANDROID_IC_MODE_NULL;
5165 else if (EQ (BVAR (buffer, text_conversion_style),
5166 Qaction))
5167 mode = ANDROID_IC_MODE_ACTION;
5168 else
5169 mode = ANDROID_IC_MODE_TEXT;
5170
5125 android_reset_ic (FRAME_ANDROID_WINDOW (f), 5171 android_reset_ic (FRAME_ANDROID_WINDOW (f),
5126 (EQ (f->selected_window, 5172 (EQ (f->selected_window,
5127 f->minibuffer_window) 5173 f->minibuffer_window)
5128 ? ANDROID_IC_MODE_ACTION 5174 ? ANDROID_IC_MODE_ACTION
5129 : ANDROID_IC_MODE_TEXT)); 5175 : mode));
5130 5176
5131 /* Move its selection to the specified position. */ 5177 /* Move its selection to the specified position. */
5132 android_update_selection (f, NULL); 5178 android_update_selection (f, NULL);