From c0bb5a2d1f372d05ece2263a3c0634ec5c909a62 Mon Sep 17 00:00:00 2001 From: Voyend Date: Wed, 27 May 2026 04:50:58 +0300 Subject: [PATCH] Fix backspace not deleting original text in soft keyboard on Android MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a soft keyboard's backspace sends KEYCODE_DEL via sendKeyEvent(), GodotEditText.onKeyDown() delegates to super.onKeyDown() which modifies the EditText's Editable, triggering beforeTextChanged() in GodotTextInputWrapper, which then forwards KEYCODE_DEL to the engine. However, the EditText is only seeded with text up to the cursor position (mOriginText) when the keyboard opens. Once the user backspaces through all of that content, the EditText becomes empty. At that point, super.onKeyDown(KEYCODE_DEL) on an empty EditText makes no change to the Editable, so beforeTextChanged() never fires and the engine receives no DEL event — even though the engine's own buffer still has text before the cursor. This causes a visible bug: the user can delete characters they typed in the current session, but backspacing further into pre-existing text does nothing. Re-tapping the field fixes it temporarily because showKeyboard() is called again, reseeding the EditText with the current text and cursor position. Fixed this by forwarding KEYCODE_DEL directly to the engine when the EditText is empty, bypassing the TextWatcher path that can't fire in that state. This produces no double events since beforeTextChanged() is physically unable to fire on an empty field. Move DEL release event from onKeyDown to onKeyUp --- .../org/godotengine/godot/input/GodotEditText.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotEditText.java b/platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotEditText.java index 21d0e2c388..58cb40140c 100644 --- a/platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotEditText.java +++ b/platform/android/java/lib/src/main/java/org/godotengine/godot/input/GodotEditText.java @@ -239,6 +239,14 @@ public class GodotEditText extends EditText { return mRenderView.getInputHandler().onKeyDown(keyCode, keyEvent); } + // If EditText is empty, super.onKeyDown won't modify the Editable, + // so beforeTextChanged won't fire and Godot never receives the DEL event. + // Forward it directly in that case. + if (keyCode == KeyEvent.KEYCODE_DEL && length() == 0) { + mRenderView.getInputHandler().handleKeyEvent(KeyEvent.KEYCODE_DEL, 0, 0, true, false); + return true; + } + // pass event to godot in special cases if (needHandlingInGodot(keyCode, keyEvent) && mRenderView.getInputHandler().onKeyDown(keyCode, keyEvent)) { return true; @@ -261,6 +269,12 @@ public class GodotEditText extends EditText { return mRenderView.getInputHandler().onKeyUp(keyCode, keyEvent); } + // Paired release event for the KEYCODE_DEL press forwarded in onKeyDown. + if (keyCode == KeyEvent.KEYCODE_DEL && length() == 0) { + mRenderView.getInputHandler().handleKeyEvent(KeyEvent.KEYCODE_DEL, 0, 0, false, false); + return true; + } + if (needHandlingInGodot(keyCode, keyEvent) && mRenderView.getInputHandler().onKeyUp(keyCode, keyEvent)) { return true; } else {