diff --git a/html_export/index_template.html b/html_export/index_template.html index 6fb39ec48..2343b17e5 100644 --- a/html_export/index_template.html +++ b/html_export/index_template.html @@ -59,5 +59,31 @@ const GDQUEST_ENVIRONMENT = {}; + + + + + + diff --git a/ui/components/CodeEditor.gd b/ui/components/CodeEditor.gd index 5165c598d..53d578e30 100644 --- a/ui/components/CodeEditor.gd +++ b/ui/components/CodeEditor.gd @@ -77,6 +77,15 @@ func _ready() -> void: slice_editor.grab_focus() + # --- MOBILE KEYBOARD PATCH START --- + # Connect Godot 4 JavaScript Interface to catch browser input events + if not Engine.is_editor_hint() and OS.has_feature("web"): + var key_callback = JavaScriptBridge.create_callback(_on_mobile_key_received) + var window = JavaScriptBridge.get_interface("window") + if window: + window.godotMobileCallback = key_callback + # --- MOBILE KEYBOARD PATCH END --- + if not Engine.is_editor_hint(): for button: BaseButton in _buttons_with_shortcuts: assert( @@ -93,6 +102,30 @@ func _gui_input(event: InputEvent) -> void: accept_event() +# --- MOBILE KEYBOARD CALLBACK FUNCTION START --- +func _on_mobile_key_received(args: Array) -> void: + if not slice_editor: + return + + var typed_char = args[0] # The string passed from JavaScript + + if typed_char == "Enter": + slice_editor.insert_text_at_caret("\n") + elif typed_char == "Backspace": + # Safely trigger a backspace operation on Godot 4's editor node + var column = slice_editor.get_caret_column() + var line = slice_editor.get_caret_line() + if column > 0: + slice_editor.select(line, column - 1, line, column) + slice_editor.delete_selection() + else: + slice_editor.insert_text_at_caret(typed_char) + + # Alert the app container that text has changed to update validation + _on_text_changed() +# --- MOBILE KEYBOARD CALLBACK FUNCTION END --- + + func update_cursor_position(line: int, column: int) -> void: # Fix for lines with TAB indent column = column - 1