]> git.eshelyaron.com Git - emacs.git/commitdiff
Work around one Android bug and document another
authorPo Lu <luangruo@yahoo.com>
Thu, 23 May 2024 09:46:48 +0000 (17:46 +0800)
committerEshel Yaron <me@eshelyaron.com>
Thu, 23 May 2024 20:36:17 +0000 (22:36 +0200)
* etc/PROBLEMS (Runtime problems specific to Android): Document
deficiency of "Android Keyboard (AOSP)."

* java/org/gnu/emacs/EmacsView.java (showOnScreenKeyboard):
Revert yesterday's change.

* java/org/gnu/emacs/EmacsWindow.java (toggleOnScreenKeyboard):
Sync with the UI thread after displaying the on-screen keyboard.

(cherry picked from commit e96e4906c8cb2a8810f969579446f6d151954586)

etc/PROBLEMS
java/org/gnu/emacs/EmacsView.java
java/org/gnu/emacs/EmacsWindow.java

index 77856087367279729edc4e8d88fd0d1f834c6502..da861ebe6e782b7a6da197461dcec670a4c687a6 100644 (file)
@@ -3650,6 +3650,20 @@ result that the next redisplay recenters the window around this outdated
 position.  There is no solution but installing a more
 cooperative--and preferably free--input method.
 
+** The default input method sometimes performs edits out of place in large buffers.
+
+When first reactivated in a window after having been dismissed, certain
+heuristics applied by the "Android Keyboard (AOSP)" input method to
+detect unresponsive text editors, which are ill-adapted to buffers
+greater than a few thousand characters in length, conclude that Emacs is
+misbehaving, so that the input method ignores updates to the position of
+point reported around the time of its activation, and edits suggested by
+the input method are inserted in a previously reported location that
+might be wildly removed from the current insertion point.  This is a bug
+in the input method that can be easily reproduced by inserting lengthy
+documents into any text editor, with no real solution except avoiding
+edit suggestions from recently-reactivated input methods.
+
 * Build-time problems
 
 ** Configuration
index db270b796e83c236b6e1df11936994949ed412e0..244a3a021662a5221248ff9850d3b4634c458fb7 100644 (file)
@@ -777,15 +777,6 @@ public final class EmacsView extends ViewGroup
 
     imManager.showSoftInput (this, 0);
     isCurrentlyTextEditor = true;
-
-    /* The OS text editing widget unconditionally reports the current
-       values of the selection to the input method after calls to
-       showSoftInput, which is redundant if inputConnection exists but
-       is now relied upon in such circumstances by the OS's default
-       input method, and must therefore be faithfully reproduced on our
-       part.  */
-    if (inputConnection != null)
-      EmacsNative.requestSelectionUpdate (window.handle);
   }
 
   public void
index d18212759dba63b5d0aa9dacd75ccaf558742d59..60036ad305ead9a7efdcc0fe146e1b4df48d9926 100644 (file)
@@ -20,12 +20,16 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 package org.gnu.emacs;
 
 import java.lang.IllegalStateException;
+
 import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.ListIterator;
-import java.util.LinkedHashMap;
 import java.util.Map;
 
+import java.util.concurrent.Callable;
+import java.util.concurrent.FutureTask;
+
 import android.app.Activity;
 
 import android.content.ClipData;
@@ -1620,23 +1624,38 @@ public final class EmacsWindow extends EmacsHandleObject
   public void
   toggleOnScreenKeyboard (final boolean on)
   {
+    FutureTask<Void> task;
+
     /* Even though InputMethodManager functions are thread safe,
        `showOnScreenKeyboard' etc must be called from the UI thread in
        order to avoid deadlocks if the calls happen in tandem with a
        call to a synchronizing function within
        `onCreateInputConnection'.  */
 
-    EmacsService.SERVICE.runOnUiThread (new Runnable () {
+    task = new FutureTask<Void> (new Callable<Void> () {
        @Override
-       public void
-       run ()
+       public Void
+       call ()
        {
          if (on)
            view.showOnScreenKeyboard ();
          else
            view.hideOnScreenKeyboard ();
+         return null;
        }
       });
+
+    /* Block Lisp until this request to display the on-screen keyboard
+       is registered by the UI thread, or updates arising from a
+       redisplay that are reported between the two events will be liable
+       to run afoul of the IMM's cache of selection positions and never
+       reach the input method, if it is currently hidden, as input
+       methods receive outdated selection information reported during
+       the previous call to `onCreateInputConnection' when first
+       displayed.
+
+       Chances are this is a long-standing bug in the system.  */
+    EmacsService.<Void>syncRunnable (task);
   }
 
   public String