diff options
| author | Po Lu | 2023-06-15 12:36:50 +0800 |
|---|---|---|
| committer | Po Lu | 2023-06-15 12:36:50 +0800 |
| commit | 363e293cc919ab02c40bd9a8fa4875c2e5644b2d (patch) | |
| tree | 5fa537364e29fbcdb13cd195ac6da253a6d95771 /java | |
| parent | ca120044ac11d38ca1e8cac7903be38d5ca15d2b (diff) | |
| download | emacs-363e293cc919ab02c40bd9a8fa4875c2e5644b2d.tar.gz emacs-363e293cc919ab02c40bd9a8fa4875c2e5644b2d.zip | |
Update Android port
* java/org/gnu/emacs/EmacsInputConnection.java
(EmacsInputConnection, beginBatchEdit, reset, endBatchEdit):
Keep track of the number of batch edits and return an
appropriate value.
(takeSnapshot): Implement function.
* java/org/gnu/emacs/EmacsNative.java (takeSnapshot): New
function.
* java/org/gnu/emacs/EmacsService.java (resetIC): Improve
debugging output.
* java/org/gnu/emacs/EmacsView.java (onCreateInputConnection):
Call `reset' to clear the UI side batch edit count.
* src/androidterm.c (struct
android_get_surrounding_text_context): New fields
`conversion_start' and `conversion_end'.
(android_get_surrounding_text): Return the conversion region.
(android_get_surrounding_text_internal, NATIVE_NAME): Factor out
`getSurroundingText'.
(takeSnapshot): New function.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsInputConnection.java | 66 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsNative.java | 2 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 25 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsView.java | 3 |
4 files changed, 81 insertions, 15 deletions
diff --git a/java/org/gnu/emacs/EmacsInputConnection.java b/java/org/gnu/emacs/EmacsInputConnection.java index 1bcc9a62a81..f8dce5dfa79 100644 --- a/java/org/gnu/emacs/EmacsInputConnection.java +++ b/java/org/gnu/emacs/EmacsInputConnection.java | |||
| @@ -50,6 +50,11 @@ public final class EmacsInputConnection implements InputConnection | |||
| 50 | /* The handle ID associated with that view's window. */ | 50 | /* The handle ID associated with that view's window. */ |
| 51 | private short windowHandle; | 51 | private short windowHandle; |
| 52 | 52 | ||
| 53 | /* Number of batch edits currently underway. Used to avoid | ||
| 54 | synchronizing with the Emacs thread after each | ||
| 55 | `endBatchEdit'. */ | ||
| 56 | private int batchEditCount; | ||
| 57 | |||
| 53 | /* Whether or not to synchronize and call `updateIC' with the | 58 | /* Whether or not to synchronize and call `updateIC' with the |
| 54 | selection position after committing text. | 59 | selection position after committing text. |
| 55 | 60 | ||
| @@ -110,6 +115,10 @@ public final class EmacsInputConnection implements InputConnection | |||
| 110 | Log.d (TAG, "beginBatchEdit"); | 115 | Log.d (TAG, "beginBatchEdit"); |
| 111 | 116 | ||
| 112 | EmacsNative.beginBatchEdit (windowHandle); | 117 | EmacsNative.beginBatchEdit (windowHandle); |
| 118 | |||
| 119 | /* Keep a record of the number of outstanding batch edits here as | ||
| 120 | well. */ | ||
| 121 | batchEditCount++; | ||
| 113 | return true; | 122 | return true; |
| 114 | } | 123 | } |
| 115 | 124 | ||
| @@ -125,7 +134,14 @@ public final class EmacsInputConnection implements InputConnection | |||
| 125 | Log.d (TAG, "endBatchEdit"); | 134 | Log.d (TAG, "endBatchEdit"); |
| 126 | 135 | ||
| 127 | EmacsNative.endBatchEdit (windowHandle); | 136 | EmacsNative.endBatchEdit (windowHandle); |
| 128 | return true; | 137 | |
| 138 | /* Subtract one from the UI thread record of the number of batch | ||
| 139 | edits currently under way. */ | ||
| 140 | |||
| 141 | if (batchEditCount > 0) | ||
| 142 | batchEditCount -= 1; | ||
| 143 | |||
| 144 | return batchEditCount > 0; | ||
| 129 | } | 145 | } |
| 130 | 146 | ||
| 131 | public boolean | 147 | public boolean |
| @@ -584,21 +600,50 @@ public final class EmacsInputConnection implements InputConnection | |||
| 584 | return text; | 600 | return text; |
| 585 | } | 601 | } |
| 586 | 602 | ||
| 587 | |||
| 588 | /* Override functions which are not implemented. */ | ||
| 589 | |||
| 590 | @Override | 603 | @Override |
| 591 | public Handler | 604 | public TextSnapshot |
| 592 | getHandler () | 605 | takeSnapshot () |
| 593 | { | 606 | { |
| 594 | return null; | 607 | TextSnapshot snapshot; |
| 608 | |||
| 609 | /* Return if the input connection is out of date. */ | ||
| 610 | if (view.icSerial < view.icGeneration) | ||
| 611 | return null; | ||
| 612 | |||
| 613 | snapshot = EmacsNative.takeSnapshot (windowHandle); | ||
| 614 | |||
| 615 | if (EmacsService.DEBUG_IC) | ||
| 616 | Log.d (TAG, ("takeSnapshot: " | ||
| 617 | + snapshot.getSurroundingText ().getText () | ||
| 618 | + " @ " + snapshot.getCompositionEnd () | ||
| 619 | + ", " + snapshot.getCompositionStart ())); | ||
| 620 | |||
| 621 | return snapshot; | ||
| 595 | } | 622 | } |
| 596 | 623 | ||
| 597 | @Override | 624 | @Override |
| 598 | public void | 625 | public void |
| 599 | closeConnection () | 626 | closeConnection () |
| 600 | { | 627 | { |
| 628 | batchEditCount = 0; | ||
| 629 | } | ||
| 630 | |||
| 631 | |||
| 601 | 632 | ||
| 633 | public void | ||
| 634 | reset () | ||
| 635 | { | ||
| 636 | batchEditCount = 0; | ||
| 637 | } | ||
| 638 | |||
| 639 | |||
| 640 | /* Override functions which are not implemented. */ | ||
| 641 | |||
| 642 | @Override | ||
| 643 | public Handler | ||
| 644 | getHandler () | ||
| 645 | { | ||
| 646 | return null; | ||
| 602 | } | 647 | } |
| 603 | 648 | ||
| 604 | @Override | 649 | @Override |
| @@ -617,13 +662,6 @@ public final class EmacsInputConnection implements InputConnection | |||
| 617 | } | 662 | } |
| 618 | 663 | ||
| 619 | @Override | 664 | @Override |
| 620 | public TextSnapshot | ||
| 621 | takeSnapshot () | ||
| 622 | { | ||
| 623 | return null; | ||
| 624 | } | ||
| 625 | |||
| 626 | @Override | ||
| 627 | public boolean | 665 | public boolean |
| 628 | clearMetaKeyStates (int states) | 666 | clearMetaKeyStates (int states) |
| 629 | { | 667 | { |
diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java index 2fcbf8b94ef..9e87c419f95 100644 --- a/java/org/gnu/emacs/EmacsNative.java +++ b/java/org/gnu/emacs/EmacsNative.java | |||
| @@ -26,6 +26,7 @@ import android.graphics.Bitmap; | |||
| 26 | import android.view.inputmethod.ExtractedText; | 26 | import android.view.inputmethod.ExtractedText; |
| 27 | import android.view.inputmethod.ExtractedTextRequest; | 27 | import android.view.inputmethod.ExtractedTextRequest; |
| 28 | import android.view.inputmethod.SurroundingText; | 28 | import android.view.inputmethod.SurroundingText; |
| 29 | import android.view.inputmethod.TextSnapshot; | ||
| 29 | 30 | ||
| 30 | public final class EmacsNative | 31 | public final class EmacsNative |
| 31 | { | 32 | { |
| @@ -230,6 +231,7 @@ public final class EmacsNative | |||
| 230 | public static native SurroundingText getSurroundingText (short window, | 231 | public static native SurroundingText getSurroundingText (short window, |
| 231 | int left, int right, | 232 | int left, int right, |
| 232 | int flags); | 233 | int flags); |
| 234 | public static native TextSnapshot takeSnapshot (short window); | ||
| 233 | 235 | ||
| 234 | 236 | ||
| 235 | /* Return the current value of the selection, or -1 upon | 237 | /* Return the current value of the selection, or -1 upon |
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index 96216e51cf4..2fe4e8c4146 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -767,8 +767,31 @@ public final class EmacsService extends Service | |||
| 767 | public void | 767 | public void |
| 768 | resetIC (EmacsWindow window, int icMode) | 768 | resetIC (EmacsWindow window, int icMode) |
| 769 | { | 769 | { |
| 770 | int oldMode; | ||
| 771 | |||
| 770 | if (DEBUG_IC) | 772 | if (DEBUG_IC) |
| 771 | Log.d (TAG, "resetIC: " + window); | 773 | Log.d (TAG, "resetIC: " + window + ", " + icMode); |
| 774 | |||
| 775 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU | ||
| 776 | && (oldMode = window.view.getICMode ()) == icMode | ||
| 777 | /* Don't do this if there is currently no input | ||
| 778 | connection. */ | ||
| 779 | && oldMode != IC_MODE_NULL) | ||
| 780 | { | ||
| 781 | if (DEBUG_IC) | ||
| 782 | Log.d (TAG, "resetIC: calling invalidateInput"); | ||
| 783 | |||
| 784 | /* Android 33 and later allow the IM reset to be optimized out | ||
| 785 | and replaced by a call to `invalidateInput', which is much | ||
| 786 | faster, as it does not involve resetting the input | ||
| 787 | connection. */ | ||
| 788 | |||
| 789 | icBeginSynchronous (); | ||
| 790 | window.view.imManager.invalidateInput (window.view); | ||
| 791 | icEndSynchronous (); | ||
| 792 | |||
| 793 | return; | ||
| 794 | } | ||
| 772 | 795 | ||
| 773 | window.view.setICMode (icMode); | 796 | window.view.setICMode (icMode); |
| 774 | 797 | ||
diff --git a/java/org/gnu/emacs/EmacsView.java b/java/org/gnu/emacs/EmacsView.java index 278c6025902..aba1184b0c2 100644 --- a/java/org/gnu/emacs/EmacsView.java +++ b/java/org/gnu/emacs/EmacsView.java | |||
| @@ -681,6 +681,9 @@ public final class EmacsView extends ViewGroup | |||
| 681 | 681 | ||
| 682 | if (inputConnection == null) | 682 | if (inputConnection == null) |
| 683 | inputConnection = new EmacsInputConnection (this); | 683 | inputConnection = new EmacsInputConnection (this); |
| 684 | else | ||
| 685 | /* Clear several pieces of state in the input connection. */ | ||
| 686 | inputConnection.reset (); | ||
| 684 | 687 | ||
| 685 | /* Return the input connection. */ | 688 | /* Return the input connection. */ |
| 686 | return inputConnection; | 689 | return inputConnection; |