aboutsummaryrefslogtreecommitdiffstats
path: root/src/textconv.c
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/textconv.c
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/textconv.c')
-rw-r--r--src/textconv.c24
1 files changed, 17 insertions, 7 deletions
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