Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions html_export/index_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,31 @@
const GDQUEST_ENVIRONMENT = {};
</script>
<script type="text/javascript" src="bootstrap.js"></script>

<!-- --- MOBILE KEYBOARD PASS-THROUGH PATCH --- -->
<script type="text/javascript">
(function() {
// We use a passive listener on the window to catch keys as they happen
window.addEventListener('keydown', function(event) {
// If our GDScript code callback bridge is initialized on the window
if (window.godotMobileCallback) {
let keyToSend = event.key;

if (keyToSend) {
// Fire the character across the bridge to codeeditor.gd
window.godotMobileCallback(keyToSend);

// Prevent standard arrow-key browser scrolling while typing in the box
if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].indexOf(keyToSend) > -1) {
event.preventDefault();
}
}
}
}, true); // The 'true' capture flag intercepts the event before the WebGL canvas breaks it
})();
</script>
<!-- --- END PATCH --- -->

</body>
</html>

33 changes: 33 additions & 0 deletions ui/components/CodeEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
Loading