From e7bf3ec52dbf9ed64acfc9c35fc80f8e9d06d9f6 Mon Sep 17 00:00:00 2001 From: Anish Kumar Date: Wed, 12 Nov 2025 00:17:52 +0530 Subject: [PATCH] Android Editor: Adjust script editor size for virtual keyboard --- editor/script/script_editor_plugin.cpp | 49 ++++++++++++++++++++++++++ editor/script/script_editor_plugin.h | 5 +++ 2 files changed, 54 insertions(+) diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp index f422f8ca80a..837ab5c4a55 100644 --- a/editor/script/script_editor_plugin.cpp +++ b/editor/script/script_editor_plugin.cpp @@ -1864,8 +1864,51 @@ void ScriptEditor::_notification(int p_what) { EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &ScriptEditor::_editor_settings_changed)); EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &ScriptEditor::_filesystem_changed)); +#ifdef ANDROID_ENABLED + set_process(true); +#endif } break; +#ifdef ANDROID_ENABLED + case NOTIFICATION_VISIBILITY_CHANGED: { + set_process(is_visible_in_tree()); + } break; + + case NOTIFICATION_PROCESS: { + const int kb_height = DisplayServer::get_singleton()->virtual_keyboard_get_height(); + if (kb_height == last_kb_height) { + break; + } + + last_kb_height = kb_height; + float spacer_height = 0.0f; + const float status_bar_height = 28 * EDSCALE; // Magic number + + if (kb_height > 0) { + if (ScriptEditorBase *editor = _get_current_editor()) { + if (CodeTextEditor *code_editor = editor->get_code_editor()) { + if (CodeEdit *text_editor = code_editor->get_text_editor()) { + if (!text_editor->has_focus()) { + break; + } + text_editor->adjust_viewport_to_caret(); + } + } + } + + const float control_bottom = get_global_position().y + get_size().y; + const float extra_bottom = get_viewport_rect().size.y - control_bottom; + spacer_height = float(kb_height) - extra_bottom - status_bar_height; + + if (spacer_height < 0.0f) { + spacer_height = 0.0f; + } + } + + virtual_keyboard_spacer->set_custom_minimum_size(Size2(0, spacer_height)); + } break; +#endif + case NOTIFICATION_EXIT_TREE: { EditorRunBar::get_singleton()->disconnect("stop_pressed", callable_mp(this, &ScriptEditor::_editor_stop)); } break; @@ -4187,6 +4230,12 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { main_container->add_child(script_split); script_split->set_v_size_flags(SIZE_EXPAND_FILL); +#ifdef ANDROID_ENABLED + virtual_keyboard_spacer = memnew(Control); + virtual_keyboard_spacer->set_h_size_flags(SIZE_EXPAND_FILL); + main_container->add_child(virtual_keyboard_spacer); +#endif + list_split = memnew(VSplitContainer); script_split->add_child(list_split); list_split->set_v_size_flags(SIZE_EXPAND_FILL); diff --git a/editor/script/script_editor_plugin.h b/editor/script/script_editor_plugin.h index 9980457e0c9..2f596a51be0 100644 --- a/editor/script/script_editor_plugin.h +++ b/editor/script/script_editor_plugin.h @@ -372,6 +372,11 @@ class ScriptEditor : public PanelContainer { WindowWrapper *window_wrapper = nullptr; +#ifdef ANDROID_ENABLED + Control *virtual_keyboard_spacer = nullptr; + int last_kb_height = -1; +#endif + enum { SCRIPT_EDITOR_FUNC_MAX = 32, };