-
Notifications
You must be signed in to change notification settings - Fork 54
Simplify BasicInputConnection implementation and remove composedText #1350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d276cb1
4780ea6
4c90be8
5fd0c5d
da0849c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,12 +32,12 @@ | |||||||||
| import android.content.Intent; | ||||||||||
| import android.graphics.PixelFormat; | ||||||||||
| import android.graphics.Rect; | ||||||||||
| import android.os.Build; | ||||||||||
| import android.os.Bundle; | ||||||||||
| import android.os.Handler; | ||||||||||
| import android.os.SystemClock; | ||||||||||
| import android.text.Editable; | ||||||||||
| import android.text.InputType; | ||||||||||
| import android.text.Selection; | ||||||||||
| import android.util.DisplayMetrics; | ||||||||||
| import android.util.Log; | ||||||||||
|
|
||||||||||
|
|
@@ -228,25 +228,29 @@ public void run() { | |||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * External call that passes the JavaFX text control that is currently active, so composing text | ||||||||||
| * can be tagged with the correct id. | ||||||||||
| * External call that passes the id of the JavaFX text control that is currently active, | ||||||||||
| * so the map of composedTexts can keep track of the current content of each editor per id. | ||||||||||
| */ | ||||||||||
| static void setActiveNodeId(String id) { | ||||||||||
| Log.d(TAG, "setActiveNodeId: " + currentActiveNodeId); | ||||||||||
| currentActiveNodeId = (id != null) ? id : "default"; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * External call that sets the Android InputType keyboard. Triggers a restartInput so the change takes | ||||||||||
| * effect immediately if the keyboard is already visible. | ||||||||||
| * External call that sets the Android InputType keyboard. Triggers a | ||||||||||
| * {@code restartInput} so the change takes effect immediately if the | ||||||||||
| * keyboard is already visible. | ||||||||||
| */ | ||||||||||
| static void setKeyboardType(int keyboardTypeValue) { | ||||||||||
| currentInputType = mapKeyboardTypeToInputType(keyboardTypeValue); | ||||||||||
| Log.d(TAG, "setKeyboardType: keyboardTypeValue=" + keyboardTypeValue + " -> inputType=" + currentInputType); | ||||||||||
| int newInputType = mapKeyboardTypeToInputType(keyboardTypeValue); | ||||||||||
| if (newInputType == currentInputType) { | ||||||||||
| Log.d(TAG, "setKeyboardType: unchanged inputType=" + newInputType); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| currentInputType = newInputType; | ||||||||||
| Log.d(TAG, "setKeyboardType: keyboardTypeValue=" + keyboardTypeValue + " -> inputType=" + newInputType); | ||||||||||
| if (imm != null && mView != null) { | ||||||||||
| instance.runOnUiThread(() -> { | ||||||||||
| imm.restartInput(mView); | ||||||||||
| }); | ||||||||||
| instance.runOnUiThread(() -> imm.restartInput(mView)); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -282,18 +286,6 @@ private static int mapKeyboardTypeToInputType(int keyboardTypeValue) { | |||||||||
| private native void nativeGotTouchEvent(int pcount, int[] actions, int[] ids, int[] touchXs, int[] touchYs); | ||||||||||
| private native void nativeDispatchKeyEvent(int type, int key, char[] chars, int charCount, int modifiers); | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Forwards the final composed text to the JavaFX layer via attach_adapter.c, | ||||||||||
| * without the internals of the BasicInputConnection (like deleting chars and typing | ||||||||||
| * them all over again while composing the resulting text). | ||||||||||
| * <p>Note that listeners attached to the JavaFX text input control {@code textProperty()} will still | ||||||||||
| * catch all those internals, so this is a convenient method to export to the JavaFX layer | ||||||||||
| * only the final composed text instead</p> | ||||||||||
| * | ||||||||||
| * @param id the JavaFX Node id of the active text control | ||||||||||
| * @param text the full text content for that control | ||||||||||
| */ | ||||||||||
| private native void nativeNotifyComposingText(String id, String text); | ||||||||||
|
|
||||||||||
| private native void nativeDispatchLifecycleEvent(String event); | ||||||||||
| private native void nativeDispatchActivityResult(int requestCode, int resultCode, Intent intent); | ||||||||||
|
|
@@ -307,13 +299,16 @@ class InternalSurfaceView extends SurfaceView { | |||||||||
| private final KeyEvent ENTER_DOWN_EVENT = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER); | ||||||||||
| private final KeyEvent ENTER_UP_EVENT = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER); | ||||||||||
|
|
||||||||||
| private String currentComposingText = ""; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Map of currently composed text per Text Input control (identifyed by its id). | ||||||||||
| * It is used to restart the IME {@link Editable} across keyboard switches / focus | ||||||||||
| * changes. The map is only accurate as long as the JavaFX control is not modified | ||||||||||
| * outside of the IME.</p> | ||||||||||
|
||||||||||
| * outside of the IME.</p> | |
| * outside of the IME. |
Copilot
AI
Apr 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This debug log prints the full cached editor content, which may include sensitive user input (e.g., passwords). Consider removing it or logging only non-sensitive metadata (like length) behind a dedicated debug flag.
| Log.d(TAG, "onCreateInputConnection Editable set with '" + initialText + "'"); | |
| if (Log.isLoggable(TAG, Log.DEBUG)) { | |
| Log.d(TAG, "onCreateInputConnection Editable initialized; cached text length=" + initialText.length()); | |
| } |
Copilot
AI
Apr 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cache update on hardware backspace deletes the last character unconditionally. Since DPAD keys are supported (caret can move), this can desync composedTexts from the actual JavaFX editor content and restore incorrect text on the next IME session. Prefer updating the cache based on the current selection (e.g., via Selection.getSelectionStart/End on the Editable) and deleting at that position, or avoid mutating the cache here and instead refresh it from the editor state when possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javadoc typo: "identifyed" should be "identified".