emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/android 01bea42cbff: Avoid responding to input method queries as


From: Po Lu
Subject: feature/android 01bea42cbff: Avoid responding to input method queries asynchronously
Date: Fri, 9 Jun 2023 06:05:50 -0400 (EDT)

branch: feature/android
commit 01bea42cbff84ca76f339088f19a42cddfe83cbb
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Avoid responding to input method queries asynchronously
    
    * src/androidterm.c (handle_one_android_event): Don't answer
    queries here; just rely on the event interrupting
    android_select.  This avoids exposing buffer contents to input
    methods while a command is being executed.
    * src/textconv.c (TEXTCONV_DEBUG, really_commit_text)
    (really_finish_composing_text, really_set_composing_text)
    (really_set_composing_region, really_delete_surrounding_text)
    (really_set_point_and_mark, get_extracted_text): Add debugging
    printouts.
---
 src/androidterm.c | 12 ++++++------
 src/textconv.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/src/androidterm.c b/src/androidterm.c
index 77f2bd1c7a0..704ff5f5d85 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -1053,12 +1053,12 @@ handle_one_android_event (struct android_display_info 
*dpyinfo,
         used to make Android run stuff.  */
 
       if (!event->xaction.window && !event->xaction.action)
-       {
-         /* Check for and run anything the UI thread wants to run on the main
-            thread.  */
-         android_check_query ();
-         goto OTHER;
-       }
+       /* Don't run queries here, as it may run inside editor
+          commands, which can expose an inconsistent view of buffer
+          contents to the input method during command execution.
+
+          Instead, wait for Emacs to return to `android_select'.  */
+       goto OTHER;
 
       f = any;
 
diff --git a/src/textconv.c b/src/textconv.c
index 1161b781b6a..92d44fe2e66 100644
--- a/src/textconv.c
+++ b/src/textconv.c
@@ -40,6 +40,24 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 
 
 
+/* Define debugging macros.  */
+
+#if defined HAVE_ANDROID && !defined ANDROID_STUBIFY
+#if 0
+#include <android/log.h>
+
+#define TEXTCONV_DEBUG(fmt, ...)                                       \
+  __android_log_print (ANDROID_LOG_VERBOSE, "EmacsInputConnection",    \
+                      "%s: " fmt, __func__, ## __VA_ARGS__)
+#endif /* 0 */
+#endif /* defined HAVE_ANDROID && !defined ANDROID_STUBIFY */
+
+#ifndef TEXTCONV_DEBUG
+#define TEXTCONV_DEBUG(...) ((void) 0)
+#endif /* TEXTCONV_DEBUG */
+
+
+
 /* The window system's text conversion interface.  NULL when the
    window system has not set up text conversion.  */
 
@@ -701,6 +719,10 @@ really_commit_text (struct frame *f, EMACS_INT position,
   /* This should deactivate the mark.  */
   call0 (Qdeactivate_mark);
 
+  /* Print some debugging information.  */
+  TEXTCONV_DEBUG ("text inserted: %s, point now: %zd",
+                 SSDATA (text), PT);
+
   /* Update the ephemeral last point.  */
   w = XWINDOW (selected_window);
   w->ephemeral_last_point = PT;
@@ -730,6 +752,8 @@ really_finish_composing_text (struct frame *f, bool update)
 
   if (!NILP (f->conversion.compose_region_overlay))
     Fdelete_overlay (f->conversion.compose_region_overlay);
+
+  TEXTCONV_DEBUG ("conversion region removed");
 }
 
 /* Set the composing text on F to TEXT.  Then, move point to an
@@ -876,6 +900,13 @@ really_set_composing_text (struct frame *f, ptrdiff_t 
position,
   w = XWINDOW (selected_window);
   w->ephemeral_last_point = PT;
 
+  if (SCHARS (text))
+    TEXTCONV_DEBUG ("conversion region set to: %td %td",
+                   marker_position (f->conversion.compose_region_start),
+                   marker_position (f->conversion.compose_region_end));
+  else
+    TEXTCONV_DEBUG ("conversion region removed; PT is now: %td", PT);
+
   unbind_to (count, Qnil);
 }
 
@@ -927,6 +958,9 @@ really_set_composing_region (struct frame *f, ptrdiff_t 
start,
               make_fixnum (end), Qnil);
   sync_overlay (f);
 
+  TEXTCONV_DEBUG ("composing region set to: %td, %td; point is: %td",
+                 start, end, PT);
+
   /* Update the ephemeral last point.  */
   w = XWINDOW (selected_window);
   w->ephemeral_last_point = PT;
@@ -1011,6 +1045,9 @@ really_delete_surrounding_text (struct frame *f, 
ptrdiff_t left,
       record_buffer_change (start, start, text);
     }
 
+  TEXTCONV_DEBUG ("deleted surrounding text: %td, %td; PT is now %td",
+                 left, right, PT);
+
   /* if the mark is now equal to start, deactivate it.  */
 
   if (get_mark () == PT)
@@ -1093,6 +1130,9 @@ really_set_point_and_mark (struct frame *f, ptrdiff_t 
point,
   w = XWINDOW (selected_window);
   w->ephemeral_last_point = PT;
 
+  TEXTCONV_DEBUG ("set point and mark: %td %td",
+                 PT, get_mark ());
+
   unbind_to (count, Qnil);
 }
 
@@ -1727,6 +1767,9 @@ get_extracted_text (struct frame *f, ptrdiff_t n,
   *length = end - start;
   *bytes = end_byte - start_byte;
 
+  TEXTCONV_DEBUG ("get_extracted_text: PT, mark, start: %td, %td, %td",
+                 PT, mark, start);
+
  finish:
   unbind_to (count, Qnil);
   return buffer;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]