Skip to content

Simplify BasicInputConnection implementation and remove composedText#1350

Merged
jperedadnr merged 5 commits intogluonhq:masterfrom
jperedadnr:165-2-predictivetext
Apr 17, 2026
Merged

Simplify BasicInputConnection implementation and remove composedText#1350
jperedadnr merged 5 commits intogluonhq:masterfrom
jperedadnr:165-2-predictivetext

Conversation

@jperedadnr
Copy link
Copy Markdown
Contributor

This PR is a follow up of #1346

  • It simplifies and improves the BasicInputConnection implementation for Android, fixing several issues.
  • It withdraws the composedText: there is no point in tracking the text of the native editor, given that there is no communication from JavaFX text editor to Android editor: any change to the former (via setText or paste) won't be sent to Android, and the composedText will be out of sync.
  • It fixes the call to set the keyboard type, preventing unnecessary restarts

Copilot AI review requested due to automatic review settings April 17, 2026 22:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Android’s BaseInputConnection handling to better synchronize IME edits with the JavaFX text control, removes the native “composing text” forwarding API, and avoids unnecessary IME restarts when the keyboard type is unchanged.

Changes:

  • Remove composed-text JNI plumbing (attach_setComposingText / nativeNotifyComposingText) and related adapter code.
  • Rework onCreateInputConnection to restore cached text and sync editor changes by diffing before/after Editable.
  • Prevent redundant restartInput() calls when the mapped InputType is unchanged.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/main/resources/native/android/c/grandroid_ext.h Removes the attach_setComposingText API surface from the native header.
src/main/resources/native/android/c/attach_adapter.c Deletes the JNI bridge that forwarded composing text to the native layer.
src/main/resources/native/android/android_project/app/src/main/java/com/gluonhq/helloandroid/MainActivity.java Refactors IME/editor synchronization, adds cached text restoration + selection setup, and avoids unnecessary IME restarts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

private String currentComposingText = "";

/**
* Map of currently composed text per Text Input control (identifyed by its id).
Copy link

Copilot AI Apr 17, 2026

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".

Suggested change
* Map of currently composed text per Text Input control (identifyed by its id).
* Map of currently composed text per Text Input control (identified by its id).

Copilot uses AI. Check for mistakes.
* 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>
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Javadoc comment ends with a stray </p> without an opening <p>, which can trigger doclint warnings and renders incorrectly. Remove the closing tag or wrap the paragraph properly.

Suggested change
* outside of the IME.</p>
* outside of the IME.

Copilot uses AI. Check for mistakes.
editable.replace(0, editable.length(), initialText);
Selection.setSelection(editable, initialText.length());
}
Log.d(TAG, "onCreateInputConnection Editable set with '" + initialText + "'");
Copy link

Copilot AI Apr 17, 2026

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.

Suggested change
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 uses AI. Check for mistakes.
Comment on lines +474 to +481
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL
&& inputConnection != null) {
// sync after direct backspace key presses.
updateComposedText(1, "");
Editable content = inputConnection.getEditable();
if (content != null && content.length() > 0) {
content.delete(content.length() - 1, content.length());
composedTexts.put(currentActiveNodeId, content.toString());
}
Copy link

Copilot AI Apr 17, 2026

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.

Copilot uses AI. Check for mistakes.
@jperedadnr jperedadnr merged commit 87406f1 into gluonhq:master Apr 17, 2026
6 of 7 checks passed
@jperedadnr jperedadnr deleted the 165-2-predictivetext branch April 17, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants