public InputConnection
onCreateInputConnection (EditorInfo info)
{
- int selection, mode;
+ int mode;
+ int[] selection;
/* Figure out what kind of IME behavior Emacs wants. */
mode = getICMode ();
/* If this fails or ANDROID_IC_MODE_NULL was requested, then don't
initialize the input connection. */
- if (selection == -1 || mode == EmacsService.IC_MODE_NULL)
+ if (mode == EmacsService.IC_MODE_NULL || selection == null)
{
info.inputType = InputType.TYPE_NULL;
return null;
info.imeOptions |= EditorInfo.IME_ACTION_DONE;
/* Set the initial selection fields. */
- info.initialSelStart = selection;
- info.initialSelEnd = selection;
+ info.initialSelStart = selection[0];
+ info.initialSelEnd = selection[1];
/* Create the input connection if necessary. */
android_window window;
/* The position of the window's point when it was last
- redisplayed. */
- ptrdiff_t point;
+ redisplayed, and its last mark if active. */
+ ptrdiff_t point, mark;
};
/* Function run on the main thread by `getSelection'.
struct android_get_selection_context *context;
struct frame *f;
struct window *w;
+ struct buffer *b;
context = data;
rather important to keep the input method consistent with the
contents of the display. */
context->point = w->ephemeral_last_point;
+
+ /* Default context->mark to w->last_point too. */
+ context->mark = context->point;
+
+ /* If the mark is active, then set it properly. */
+ b = XBUFFER (w->contents);
+ if (!NILP (BVAR (b, mark_active)) && w->last_mark != -1)
+ context->mark = w->last_mark;
}
}
-JNIEXPORT jint JNICALL
+JNIEXPORT jintArray JNICALL
NATIVE_NAME (getSelection) (JNIEnv *env, jobject object, jshort window)
{
struct android_get_selection_context context;
+ jintArray array;
+ jint contents[2];
context.window = window;
android_sync_edit ();
if (android_run_in_emacs_thread (android_get_selection,
&context))
- return -1;
+ return NULL;
if (context.point == -1)
- return -1;
+ return NULL;
+
+ /* Wraparound actually makes more sense than truncation; at least
+ editing will sort of work. */
+ contents[0] = (unsigned int) min (context.point,
+ context.mark);
+ contents[1] = (unsigned int) max (context.point,
+ context.mark);
+
+ /* Now create the array. */
+ array = (*env)->NewIntArray (env, 2);
+
+ if (!array)
+ return NULL;
- return min (context.point, TYPE_MAXIMUM (jint));
+ /* Set its contents. */
+ (*env)->SetIntArrayRegion (env, array, 0, 2, contents);
+ return array;
}
JNIEXPORT void JNICALL