ptrdiff_t length, bytes;
/* Offsets into that text. */
- ptrdiff_t start, offset;
+ ptrdiff_t start, start_offset, end_offset;
/* The window. */
android_window window;
/* Now get the extracted text. */
request->text
= get_extracted_text (f, min (request->hint_max_chars, 600),
- &request->start, &request->offset,
- &request->length, &request->bytes);
+ &request->start, &request->start_offset,
+ &request->end_offset, &request->length,
+ &request->bytes);
/* See if request->flags & GET_EXTRACTED_TEXT_MONITOR. If so, then
the input method has asked to monitor changes to the extracted
/* Return an ExtractedText object corresponding to the extracted text
TEXT. START is a character position describing the offset of the
- first character in TEXT. OFFSET is the offset of point relative to
- START.
+ first character in TEXT. START_OFFSET is the offset of the lesser
+ of point or mark relative to START, and END_OFFSET is that of the
+ greater of point or mark relative to START.
Assume that request_class and text_class have already been
initialized.
static jobject
android_build_extracted_text (jstring text, ptrdiff_t start,
- ptrdiff_t offset)
+ ptrdiff_t start_offset,
+ ptrdiff_t end_offset)
{
JNIEnv *env;
jobject object;
(*env)->SetIntField (env, object, text_class.partial_start_offset, -1);
(*env)->SetIntField (env, object, text_class.partial_end_offset, -1);
(*env)->SetIntField (env, object, text_class.selection_start,
- min (offset, TYPE_MAXIMUM (jint)));
+ min (start_offset, TYPE_MAXIMUM (jint)));
(*env)->SetIntField (env, object, text_class.selection_end,
- min (offset, TYPE_MAXIMUM (jint)));
+ min (end_offset, TYPE_MAXIMUM (jint)));
/* Subtract 1 from start: point indices in Emacs start from 1, but
Android expects 0. */
(*env)->SetIntField (env, object, text_class.partial_start_offset, -1);
(*env)->SetIntField (env, object, text_class.partial_end_offset, -1);
(*env)->SetIntField (env, object, text_class.selection_start,
- min (context.offset, TYPE_MAXIMUM (jint)));
+ min (context.start_offset, TYPE_MAXIMUM (jint)));
(*env)->SetIntField (env, object, text_class.selection_end,
- min (context.offset, TYPE_MAXIMUM (jint)));
+ min (context.end_offset, TYPE_MAXIMUM (jint)));
/* Subtract 1 from start: point indices in Emacs start from 1, but
Android expects 0. */
static void
android_update_selection (struct frame *f, struct window *w)
{
- ptrdiff_t start, end, point, mark, offset, length, bytes;
+ ptrdiff_t start, end, point, mark, start_offset, end_offset;
+ ptrdiff_t length, bytes;
struct buffer *b;
int hint, token;
char *text;
hint = FRAME_ANDROID_OUTPUT (f)->extracted_text_hint;
token = FRAME_ANDROID_OUTPUT (f)->extracted_text_token;
text = get_extracted_text (f, min (hint, 600), &start,
- &offset, &length, &bytes);
+ &start_offset, &end_offset,
+ &length, &bytes);
if (text)
{
/* Make extracted text out of that string. */
extracted = android_build_extracted_text (string, start,
- offset);
+ start_offset,
+ end_offset);
android_exception_check_1 (string);
ANDROID_DELETE_LOCAL_REF (string);
that the mark is active.
Set *N to the actual number of characters returned, *START_RETURN
- to the position of the first character returned, *OFFSET to the
- offset of point within that text, *LENGTH to the actual number of
- characters returned, and *BYTES to the actual number of bytes
- returned.
+ to the position of the first character returned, *START_OFFSET to
+ the offset of the lesser of mark and point within that text,
+ *END_OFFSET to the greater of mark and point within that text, and
+ *LENGTH to the actual number of characters returned, and *BYTES to
+ the actual number of bytes returned.
Value is NULL upon failure, and a malloced string upon success. */
char *
get_extracted_text (struct frame *f, ptrdiff_t n,
ptrdiff_t *start_return,
- ptrdiff_t *offset, ptrdiff_t *length,
+ ptrdiff_t *start_offset,
+ ptrdiff_t *end_offset, ptrdiff_t *length,
ptrdiff_t *bytes)
{
specpdl_ref count;
- ptrdiff_t start, end, start_byte, end_byte;
+ ptrdiff_t start, end, start_byte, end_byte, mark;
char *buffer;
if (!WINDOW_LIVE_P (f->old_selected_window))
copy_buffer (start, start_byte, end, end_byte,
buffer);
+ /* Get the mark. If it's not active, use PT. */
+
+ mark = get_mark ();
+
+ if (mark == -1)
+ mark = PT;
+
/* Return the offsets. */
*start_return = start;
- *offset = PT - start;
+ *start_offset = min (mark - start, PT - start);
+ *end_offset = max (mark - start, PT - start);
*length = end - start;
*bytes = end_byte - start_byte;