aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2023-06-01 08:29:48 +0800
committerPo Lu2023-06-01 08:29:48 +0800
commitce238de2b1126bb1f356285c9713d8efefae3d59 (patch)
tree3a07e273d3bf948527e63bcc61f4e59c523785cd /src
parenta964116008735492a50a309c28fb8768630c14b7 (diff)
downloademacs-ce238de2b1126bb1f356285c9713d8efefae3d59.tar.gz
emacs-ce238de2b1126bb1f356285c9713d8efefae3d59.zip
Correctly report start and end in extracted text
* src/androidterm.c (struct android_get_extracted_text_context): New field `start_offset' and `end_offset'. Delete `offset'. (android_get_extracted_text, android_build_extracted_text): Replace `offset' with new args `start_offset' and `end_offset'. (NATIVE_NAME): Set `start_offset' and `end_offset'. (android_update_selection): Likewise. * src/textconv.c (get_extracted_text): Likewise. * src/textconv.h: Update prototypes.
Diffstat (limited to 'src')
-rw-r--r--src/androidterm.c32
-rw-r--r--src/textconv.c24
-rw-r--r--src/textconv.h3
3 files changed, 38 insertions, 21 deletions
diff --git a/src/androidterm.c b/src/androidterm.c
index 6f7c06875ca..a9b5834c08f 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -5196,7 +5196,7 @@ struct android_get_extracted_text_context
5196 ptrdiff_t length, bytes; 5196 ptrdiff_t length, bytes;
5197 5197
5198 /* Offsets into that text. */ 5198 /* Offsets into that text. */
5199 ptrdiff_t start, offset; 5199 ptrdiff_t start, start_offset, end_offset;
5200 5200
5201 /* The window. */ 5201 /* The window. */
5202 android_window window; 5202 android_window window;
@@ -5222,8 +5222,9 @@ android_get_extracted_text (void *data)
5222 /* Now get the extracted text. */ 5222 /* Now get the extracted text. */
5223 request->text 5223 request->text
5224 = get_extracted_text (f, min (request->hint_max_chars, 600), 5224 = get_extracted_text (f, min (request->hint_max_chars, 600),
5225 &request->start, &request->offset, 5225 &request->start, &request->start_offset,
5226 &request->length, &request->bytes); 5226 &request->end_offset, &request->length,
5227 &request->bytes);
5227 5228
5228 /* See if request->flags & GET_EXTRACTED_TEXT_MONITOR. If so, then 5229 /* See if request->flags & GET_EXTRACTED_TEXT_MONITOR. If so, then
5229 the input method has asked to monitor changes to the extracted 5230 the input method has asked to monitor changes to the extracted
@@ -5268,8 +5269,9 @@ struct android_extracted_text_class text_class;
5268 5269
5269/* Return an ExtractedText object corresponding to the extracted text 5270/* Return an ExtractedText object corresponding to the extracted text
5270 TEXT. START is a character position describing the offset of the 5271 TEXT. START is a character position describing the offset of the
5271 first character in TEXT. OFFSET is the offset of point relative to 5272 first character in TEXT. START_OFFSET is the offset of the lesser
5272 START. 5273 of point or mark relative to START, and END_OFFSET is that of the
5274 greater of point or mark relative to START.
5273 5275
5274 Assume that request_class and text_class have already been 5276 Assume that request_class and text_class have already been
5275 initialized. 5277 initialized.
@@ -5279,7 +5281,8 @@ struct android_extracted_text_class text_class;
5279 5281
5280static jobject 5282static jobject
5281android_build_extracted_text (jstring text, ptrdiff_t start, 5283android_build_extracted_text (jstring text, ptrdiff_t start,
5282 ptrdiff_t offset) 5284 ptrdiff_t start_offset,
5285 ptrdiff_t end_offset)
5283{ 5286{
5284 JNIEnv *env; 5287 JNIEnv *env;
5285 jobject object; 5288 jobject object;
@@ -5299,9 +5302,9 @@ android_build_extracted_text (jstring text, ptrdiff_t start,
5299 (*env)->SetIntField (env, object, text_class.partial_start_offset, -1); 5302 (*env)->SetIntField (env, object, text_class.partial_start_offset, -1);
5300 (*env)->SetIntField (env, object, text_class.partial_end_offset, -1); 5303 (*env)->SetIntField (env, object, text_class.partial_end_offset, -1);
5301 (*env)->SetIntField (env, object, text_class.selection_start, 5304 (*env)->SetIntField (env, object, text_class.selection_start,
5302 min (offset, TYPE_MAXIMUM (jint))); 5305 min (start_offset, TYPE_MAXIMUM (jint)));
5303 (*env)->SetIntField (env, object, text_class.selection_end, 5306 (*env)->SetIntField (env, object, text_class.selection_end,
5304 min (offset, TYPE_MAXIMUM (jint))); 5307 min (end_offset, TYPE_MAXIMUM (jint)));
5305 5308
5306 /* Subtract 1 from start: point indices in Emacs start from 1, but 5309 /* Subtract 1 from start: point indices in Emacs start from 1, but
5307 Android expects 0. */ 5310 Android expects 0. */
@@ -5404,9 +5407,9 @@ NATIVE_NAME (getExtractedText) (JNIEnv *env, jobject ignored_object,
5404 (*env)->SetIntField (env, object, text_class.partial_start_offset, -1); 5407 (*env)->SetIntField (env, object, text_class.partial_start_offset, -1);
5405 (*env)->SetIntField (env, object, text_class.partial_end_offset, -1); 5408 (*env)->SetIntField (env, object, text_class.partial_end_offset, -1);
5406 (*env)->SetIntField (env, object, text_class.selection_start, 5409 (*env)->SetIntField (env, object, text_class.selection_start,
5407 min (context.offset, TYPE_MAXIMUM (jint))); 5410 min (context.start_offset, TYPE_MAXIMUM (jint)));
5408 (*env)->SetIntField (env, object, text_class.selection_end, 5411 (*env)->SetIntField (env, object, text_class.selection_end,
5409 min (context.offset, TYPE_MAXIMUM (jint))); 5412 min (context.end_offset, TYPE_MAXIMUM (jint)));
5410 5413
5411 /* Subtract 1 from start: point indices in Emacs start from 1, but 5414 /* Subtract 1 from start: point indices in Emacs start from 1, but
5412 Android expects 0. */ 5415 Android expects 0. */
@@ -5507,7 +5510,8 @@ NATIVE_NAME (requestCursorUpdates) (JNIEnv *env, jobject object,
5507static void 5510static void
5508android_update_selection (struct frame *f, struct window *w) 5511android_update_selection (struct frame *f, struct window *w)
5509{ 5512{
5510 ptrdiff_t start, end, point, mark, offset, length, bytes; 5513 ptrdiff_t start, end, point, mark, start_offset, end_offset;
5514 ptrdiff_t length, bytes;
5511 struct buffer *b; 5515 struct buffer *b;
5512 int hint, token; 5516 int hint, token;
5513 char *text; 5517 char *text;
@@ -5560,7 +5564,8 @@ android_update_selection (struct frame *f, struct window *w)
5560 hint = FRAME_ANDROID_OUTPUT (f)->extracted_text_hint; 5564 hint = FRAME_ANDROID_OUTPUT (f)->extracted_text_hint;
5561 token = FRAME_ANDROID_OUTPUT (f)->extracted_text_token; 5565 token = FRAME_ANDROID_OUTPUT (f)->extracted_text_token;
5562 text = get_extracted_text (f, min (hint, 600), &start, 5566 text = get_extracted_text (f, min (hint, 600), &start,
5563 &offset, &length, &bytes); 5567 &start_offset, &end_offset,
5568 &length, &bytes);
5564 5569
5565 if (text) 5570 if (text)
5566 { 5571 {
@@ -5572,7 +5577,8 @@ android_update_selection (struct frame *f, struct window *w)
5572 5577
5573 /* Make extracted text out of that string. */ 5578 /* Make extracted text out of that string. */
5574 extracted = android_build_extracted_text (string, start, 5579 extracted = android_build_extracted_text (string, start,
5575 offset); 5580 start_offset,
5581 end_offset);
5576 android_exception_check_1 (string); 5582 android_exception_check_1 (string);
5577 ANDROID_DELETE_LOCAL_REF (string); 5583 ANDROID_DELETE_LOCAL_REF (string);
5578 5584
diff --git a/src/textconv.c b/src/textconv.c
index a2c790d5374..dcf016104fe 100644
--- a/src/textconv.c
+++ b/src/textconv.c
@@ -1513,21 +1513,23 @@ request_point_update (struct frame *f, unsigned long counter)
1513 that the mark is active. 1513 that the mark is active.
1514 1514
1515 Set *N to the actual number of characters returned, *START_RETURN 1515 Set *N to the actual number of characters returned, *START_RETURN
1516 to the position of the first character returned, *OFFSET to the 1516 to the position of the first character returned, *START_OFFSET to
1517 offset of point within that text, *LENGTH to the actual number of 1517 the offset of the lesser of mark and point within that text,
1518 characters returned, and *BYTES to the actual number of bytes 1518 *END_OFFSET to the greater of mark and point within that text, and
1519 returned. 1519 *LENGTH to the actual number of characters returned, and *BYTES to
1520 the actual number of bytes returned.
1520 1521
1521 Value is NULL upon failure, and a malloced string upon success. */ 1522 Value is NULL upon failure, and a malloced string upon success. */
1522 1523
1523char * 1524char *
1524get_extracted_text (struct frame *f, ptrdiff_t n, 1525get_extracted_text (struct frame *f, ptrdiff_t n,
1525 ptrdiff_t *start_return, 1526 ptrdiff_t *start_return,
1526 ptrdiff_t *offset, ptrdiff_t *length, 1527 ptrdiff_t *start_offset,
1528 ptrdiff_t *end_offset, ptrdiff_t *length,
1527 ptrdiff_t *bytes) 1529 ptrdiff_t *bytes)
1528{ 1530{
1529 specpdl_ref count; 1531 specpdl_ref count;
1530 ptrdiff_t start, end, start_byte, end_byte; 1532 ptrdiff_t start, end, start_byte, end_byte, mark;
1531 char *buffer; 1533 char *buffer;
1532 1534
1533 if (!WINDOW_LIVE_P (f->old_selected_window)) 1535 if (!WINDOW_LIVE_P (f->old_selected_window))
@@ -1595,9 +1597,17 @@ get_extracted_text (struct frame *f, ptrdiff_t n,
1595 copy_buffer (start, start_byte, end, end_byte, 1597 copy_buffer (start, start_byte, end, end_byte,
1596 buffer); 1598 buffer);
1597 1599
1600 /* Get the mark. If it's not active, use PT. */
1601
1602 mark = get_mark ();
1603
1604 if (mark == -1)
1605 mark = PT;
1606
1598 /* Return the offsets. */ 1607 /* Return the offsets. */
1599 *start_return = start; 1608 *start_return = start;
1600 *offset = PT - start; 1609 *start_offset = min (mark - start, PT - start);
1610 *end_offset = max (mark - start, PT - start);
1601 *length = end - start; 1611 *length = end - start;
1602 *bytes = end_byte - start_byte; 1612 *bytes = end_byte - start_byte;
1603 1613
diff --git a/src/textconv.h b/src/textconv.h
index 6abca97bc52..055bf251651 100644
--- a/src/textconv.h
+++ b/src/textconv.h
@@ -139,7 +139,8 @@ extern void delete_surrounding_text (struct frame *, ptrdiff_t,
139 ptrdiff_t, unsigned long); 139 ptrdiff_t, unsigned long);
140extern void request_point_update (struct frame *, unsigned long); 140extern void request_point_update (struct frame *, unsigned long);
141extern char *get_extracted_text (struct frame *, ptrdiff_t, ptrdiff_t *, 141extern char *get_extracted_text (struct frame *, ptrdiff_t, ptrdiff_t *,
142 ptrdiff_t *, ptrdiff_t *, ptrdiff_t *); 142 ptrdiff_t *, ptrdiff_t *, ptrdiff_t *,
143 ptrdiff_t *);
143extern bool conversion_disabled_p (void); 144extern bool conversion_disabled_p (void);
144 145
145extern void register_textconv_interface (struct textconv_interface *); 146extern void register_textconv_interface (struct textconv_interface *);