summaryrefslogtreecommitdiff
path: root/src/androidterm.c
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2024-04-21 21:51:09 +0800
committerPo Lu <luangruo@yahoo.com>2024-04-29 12:34:39 +0800
commit430088c9ccec5fe9be57d267f45acdc87aa3b28e (patch)
treea953f845c4176e4a18a542c1e321f80ad34ab4af /src/androidterm.c
parentee2e0031d8cc32bb7837ea97ce07ef3b25463223 (diff)
downloademacs-430088c9ccec5fe9be57d267f45acdc87aa3b28e.tar.gz
emacs-430088c9ccec5fe9be57d267f45acdc87aa3b28e.tar.bz2
emacs-430088c9ccec5fe9be57d267f45acdc87aa3b28e.zip
Take fields into account during text conversion
* lisp/cus-edit.el (Custom-mode): Enable text conversion, now that fields are correctly treated. * src/alloc.c (mark_frame): Mark f->conversion.field. * src/androidterm.c (android_update_selection): Adjust conversion region and selection position by the field start and end. * src/editfns.c (find_field): Export function. * src/frame.c (make_frame): Clear f->conversion.field. * src/frame.h (struct text_conversion_state) <field>: New field. * src/lisp.h (find_fields, reset_frame_conversion): Export functions. * src/minibuf.c (Fread_from_minibuffer): Reset frame conversion if Voverriding_text_conversion_style is set. * src/textconv.c (textconv_query): Narrow to field. (reset_frame_conversion): New function. (reset_frame_state): Clear conversion field. (really_delete_surrounding_text): Narrow to field. (locate_and_save_position_in_field): New function. (really_request_point_update, really_set_point_and_mark) (complete_edit_check, handle_pending_conversion_events_1) (handle_pending_conversion_events, get_conversion_field) (set_composing_region, textconv_set_point_and_mark, replace_text) (get_extracted_text, get_surrounding_text, report_point_change): Compute, narrow to and offset by the currently active field whenever point is updated or a command is received. (syms_of_textconv): Revise doc strings. * src/textconv.h (get_conversion_field): Export function.
Diffstat (limited to 'src/androidterm.c')
-rw-r--r--src/androidterm.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/androidterm.c b/src/androidterm.c
index 4549941ee2e..f849f0d9919 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -6265,14 +6265,24 @@ android_update_selection (struct frame *f, struct window *w)
jobject extracted;
jstring string;
bool mark_active;
+ ptrdiff_t field_start, field_end;
+
+ /* Offset these values by the start offset of the field. */
+ get_conversion_field (f, &field_start, &field_end);
if (MARKERP (f->conversion.compose_region_start))
{
eassert (MARKERP (f->conversion.compose_region_end));
/* Indexing in android starts from 0 instead of 1. */
- start = marker_position (f->conversion.compose_region_start) - 1;
- end = marker_position (f->conversion.compose_region_end) - 1;
+ start = marker_position (f->conversion.compose_region_start);
+ end = marker_position (f->conversion.compose_region_end);
+
+ /* Offset and detect underflow. */
+ start = max (start, field_start) - field_start - 1;
+ end = min (end, field_end) - field_start - 1;
+ if (end < 0 || start < 0)
+ end = start = -1;
}
else
start = -1, end = -1;
@@ -6288,24 +6298,27 @@ android_update_selection (struct frame *f, struct window *w)
/* Figure out where the point and mark are. If the mark is not
active, then point is set to equal mark. */
b = XBUFFER (w->contents);
- point = min (w->ephemeral_last_point,
+ point = min (min (max (w->ephemeral_last_point,
+ field_start),
+ field_end) - field_start,
TYPE_MAXIMUM (jint));
mark = ((!NILP (BVAR (b, mark_active))
&& w->last_mark != -1)
- ? min (w->last_mark, TYPE_MAXIMUM (jint))
+ ? min (min (max (w->last_mark, field_start),
+ field_end) - field_start,
+ TYPE_MAXIMUM (jint))
: point);
- /* Send the update. Android doesn't employ a concept of ``point''
- and ``mark''; instead, it only has a selection, where the start
- of the selection is less than or equal to the end, and the region
- is ``active'' when those two values differ. Also, convert the
- indices from 1-based Emacs indices to 0-based Android ones. */
- android_update_ic (FRAME_ANDROID_WINDOW (f), min (point, mark) - 1,
- max (point, mark) - 1, start, end);
+ /* Send the update. Android doesn't employ a concept of "point" and
+ "mark"; instead, it only has a selection, where the start of the
+ selection is less than or equal to the end, and the region is
+ "active" when those two values differ. The indices will have been
+ converted from 1-based Emacs indices to 0-based Android ones. */
+ android_update_ic (FRAME_ANDROID_WINDOW (f), min (point, mark),
+ max (point, mark), start, end);
/* Update the extracted text as well, if the input method has asked
- for updates. 1 is
- InputConnection.GET_EXTRACTED_TEXT_MONITOR. */
+ for updates. 1 is InputConnection.GET_EXTRACTED_TEXT_MONITOR. */
if (FRAME_ANDROID_OUTPUT (f)->extracted_text_flags & 1)
{