jstring string;
/* First, set up the conversion query. */
- context.query.position = 0;
+ context.query.position = EMACS_INT_MAX;
context.query.direction = TEXTCONV_FORWARD_CHAR;
context.query.factor = min (length, 65535);
context.query.operation = TEXTCONV_RETRIEVAL;
jstring string;
/* First, set up the conversion query. */
- context.query.position = 0;
+ context.query.position = TYPE_MINIMUM (EMACS_INT);
context.query.direction = TEXTCONV_BACKWARD_CHAR;
context.query.factor = min (length, 65535);
context.query.operation = TEXTCONV_RETRIEVAL;
event.ime.serial = ++event_serial;
event.ime.window = window;
event.ime.operation = ANDROID_IME_SET_COMPOSING_REGION;
- event.ime.start = start;
- event.ime.end = end;
+ event.ime.start = start + 1;
+ event.ime.end = end + 1;
event.ime.length = 0;
event.ime.position = 0;
event.ime.text = NULL;
event.ime.serial = ++event_serial;
event.ime.window = window;
event.ime.operation = ANDROID_IME_SET_POINT;
- event.ime.start = start;
- event.ime.end = end;
+ event.ime.start = start + 1;
+ event.ime.end = end + 1;
event.ime.length = 0;
event.ime.position = start;
event.ime.text = NULL;
return NULL;
/* Wraparound actually makes more sense than truncation; at least
- editing will sort of work. */
+ editing will sort of work. Convert the positions to start from
+ index 0, as that is what Android expects. */
contents[0] = (unsigned int) min (context.point,
- context.mark);
+ context.mark) - 1;
contents[1] = (unsigned int) max (context.point,
- context.mark);
+ context.mark) - 1;
/* Now create the array. */
array = (*env)->NewIntArray (env, 2);
min (offset, TYPE_MAXIMUM (jint)));
(*env)->SetIntField (env, object, text_class.selection_end,
min (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.start_offset,
- min (start, TYPE_MAXIMUM (jint)));
+ min (start - 1, TYPE_MAXIMUM (jint)));
(*env)->SetObjectField (env, object, text_class.text, text);
return object;
}
min (context.offset, TYPE_MAXIMUM (jint)));
(*env)->SetIntField (env, object, text_class.selection_end,
min (context.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.start_offset,
- min (context.start, TYPE_MAXIMUM (jint)));
+ min (context.start - 1, TYPE_MAXIMUM (jint)));
(*env)->SetObjectField (env, object, text_class.text, string);
return object;
}
{
eassert (MARKERP (f->conversion.compose_region_end));
- start = marker_position (f->conversion.compose_region_start);
- end = marker_position (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;
}
else
start = -1, end = -1;
/* Send the update. Android doesn't have 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. */
- android_update_ic (FRAME_ANDROID_WINDOW (f), min (point, mark),
- max (point, mark), start, end);
+ the selection is less than or equal to the end. 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);
/* Update the extracted text as well, if the input method has asked
for updates. 1 is
text = get_extracted_text (f, min (hint, 600), &start,
&offset, &length, &bytes);
- /* Make a string out of the extracted text. */
- string = android_text_to_string (android_java_env,
- text, length, bytes);
- xfree (text);
- android_exception_check ();
-
- /* Make extracted text out of that string. */
- extracted = android_build_extracted_text (string, start,
- offset);
- android_exception_check_1 (string);
- ANDROID_DELETE_LOCAL_REF (string);
-
- if (extracted)
+ if (text)
{
- /* extracted is now an associated ExtractedText object.
- Perform the update. */
- android_update_extracted_text (FRAME_ANDROID_WINDOW (f),
- extracted, token);
- ANDROID_DELETE_LOCAL_REF (extracted);
+ /* Make a string out of the extracted text. */
+ string = android_text_to_string (android_java_env,
+ text, length, bytes);
+ xfree (text);
+ android_exception_check ();
+
+ /* Make extracted text out of that string. */
+ extracted = android_build_extracted_text (string, start,
+ offset);
+ android_exception_check_1 (string);
+ ANDROID_DELETE_LOCAL_REF (string);
+
+ if (extracted)
+ {
+ /* extracted is now an associated ExtractedText object.
+ Perform the update. */
+ android_update_extracted_text (FRAME_ANDROID_WINDOW (f),
+ extracted, token);
+ ANDROID_DELETE_LOCAL_REF (extracted);
+ }
}
}
}
window and QUERY->factor times QUERY->direction from that
position. Return it in QUERY->text.
+ If QUERY->position is TYPE_MINIMUM (EMACS_INT) or EMACS_INT_MAX,
+ start at the window's last point or mark, whichever is greater or
+ smaller.
+
Then, either delete that text from the buffer if QUERY->operation
is TEXTCONV_SUBSTITUTION, or return 0.
{
specpdl_ref count;
ptrdiff_t pos, pos_byte, end, end_byte, start;
- ptrdiff_t temp, temp1;
+ ptrdiff_t temp, temp1, mark;
char *buffer;
+ struct window *w;
/* Save the excursion, as there will be extensive changes to the
selected window. */
select_window ((WINDOW_LIVE_P (f->old_selected_window)
? f->old_selected_window
: f->selected_window), Qt);
+ w = XWINDOW (selected_window);
/* Now find the appropriate text bounds for QUERY. First, move
point QUERY->position steps forward or backwards. */
pos = PT;
+ /* If QUERY->position is EMACS_INT_MAX, use the last mark or the
+ ephemeral last point, whichever is greater.
+
+ The opposite applies for EMACS_INT_MIN. */
+
+ mark = get_mark ();
+
+ if (query->position == EMACS_INT_MAX)
+ {
+ pos = (mark == -1
+ ? w->ephemeral_last_point
+ : max (w->ephemeral_last_point, mark));
+ goto escape1;
+ }
+ else if (query->position == TYPE_MINIMUM (EMACS_INT))
+ {
+ pos = (mark == -1
+ ? w->ephemeral_last_point
+ : min (w->ephemeral_last_point, mark));
+ goto escape1;
+ }
+
/* Next, if POS lies within the conversion region and the caller
asked for it to be moved away, move it away from the conversion
region. */
if (flags & TEXTCONV_SKIP_ACTIVE_REGION)
{
- temp = get_mark ();
+ temp = mark;
if (temp == -1)
goto escape;
if (INT_ADD_WRAPV (pos, query->position, &pos))
pos = PT;
+ escape1:
+
if (pos < BEGV)
pos = BEGV;
/* If PT hasn't changed, the conversion region definitely has.
Otherwise, redisplay will update the input method instead. */
- if (PT == w->last_point
+ if (PT == w->ephemeral_last_point
&& text_interface
&& text_interface->compose_region_changed)
{