]> git.eshelyaron.com Git - emacs.git/commitdiff
Implement more Android text editing controls
authorPo Lu <luangruo@yahoo.com>
Sun, 5 Nov 2023 02:40:52 +0000 (10:40 +0800)
committerPo Lu <luangruo@yahoo.com>
Sun, 5 Nov 2023 02:42:01 +0000 (10:42 +0800)
* lisp/term/android-win.el (android-deactivate-mark-command):
New command.
(select-all, start-selecting-text, stop-selecting-text): Arrange
for commands manipulating the region to be executed when these
keys are registered.

* src/android.c (android_get_keysym_name): Return the keysym
name of each of the new keysyms introduced.

* src/androidterm.c (performContextMenuAction): Save special
keysyms into key events for the selectAll, startSelectingText
and stopSelectingText actions.

lisp/term/android-win.el
src/android.c
src/androidterm.c

index 960dfdcb4a6936a5e3bb8a7b5639a61352dfddd5..70e24f4ccc79568f92174ccb061b4e2b5d2bb6cd 100644 (file)
@@ -294,6 +294,21 @@ content:// URIs into the special file names which represent them."
 
 (define-key special-event-map [drag-n-drop] 'android-handle-dnd-event)
 
+\f
+;; Bind keys sent by input methods to manipulate the state of the
+;; selection to commands which set or deactivate the mark.
+
+(defun android-deactivate-mark-command ()
+  "Deactivate the mark in this buffer.
+This command is generally invoked by input methods sending
+the `stop-selecting-text' editing key."
+  (interactive)
+  (deactivate-mark))
+
+(global-set-key [select-all] 'mark-whole-buffer)
+(global-set-key [start-selecting-text] 'set-mark-command)
+(global-set-key [stop-selecting-text] 'android-deactivate-mark-command)
+
 \f
 (provide 'android-win)
 ;; android-win.el ends here.
index 79f16568fd4ae71742928f0832626b5ee44f0aea..3397ec0e740375cb1a4bad7662e5b321f47c5a6f 100644 (file)
@@ -5598,6 +5598,27 @@ android_get_keysym_name (int keysym, char *name_return, size_t size)
   const char *buffer;
   jmethodID method;
 
+  /* These keysyms are special editor actions sent by the input
+     method.  */
+
+  switch (keysym)
+    {
+    case 65536 + 1:
+      strncpy (name_return, "select-all", size - 1);
+      name_return[size] = '\0';
+      return;
+
+    case 65536 + 2:
+      strncpy (name_return, "start-selecting-text", size - 1);
+      name_return[size] = '\0';
+      return;
+
+    case 65536 + 3:
+      strncpy (name_return, "stop-selecting-text", size - 1);
+      name_return[size] = '\0';
+      return;
+    }
+
   method = service_class.name_keysym;
   string
     = (*android_java_env)->CallNonvirtualObjectMethod (android_java_env,
@@ -5607,6 +5628,13 @@ android_get_keysym_name (int keysym, char *name_return, size_t size)
                                                       (jint) keysym);
   android_exception_check ();
 
+  if (!string)
+    {
+      strncpy (name_return, "stop-selecting-text", size - 1);
+      name_return[size] = '\0';
+      return;
+    }
+
   buffer = (*android_java_env)->GetStringUTFChars (android_java_env,
                                                   (jstring) string,
                                                   NULL);
index 4a479daf45279346f84bc787144bb22912011623..1593cac36ba30b1bf61910d81be340ef1885816a 100644 (file)
@@ -5402,11 +5402,22 @@ NATIVE_NAME (performContextMenuAction) (JNIEnv *env, jobject object,
 
   switch (action)
     {
+      /* The subsequent three keycodes are addressed by
+        android_get_keysym_name rather than in keyboard.c.  */
+
     case 0: /* android.R.id.selectAll */
+      key = 65536 + 1;
+      break;
+
     case 1: /* android.R.id.startSelectingText */
+      key = 65536 + 2;
+      break;
+
     case 2: /* android.R.id.stopSelectingText */
+      key = 65536 + 3;
+      break;
+
     default:
-      /* These actions are not implemented.  */
       return;
 
     case 3: /* android.R.id.cut */