From ea66a0c799b9daa6411475a70466877746f13288 Mon Sep 17 00:00:00 2001 From: Leroy Hopson Date: Wed, 1 Jun 2022 22:39:06 +0700 Subject: [PATCH] Prevent editor shortcuts while terminal is focused --- CHANGELOG.md | 4 +++ .../terminal/editor_terminal.gd | 29 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4d1c0d..59138ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Linux binaries now support systems with older GLIBC versions. By building the binaries inside a docker container with an older GLIBC version, the minimum required GLIBC version is now 2.17 which was released in 2012. +- Prevent all editor shortcuts while terminal is focused except for: + - The shortcuts used to switch between terminal tabs (Ctrl+Page up, Ctrl+Page down). + - Shortcuts starting with Ctrl + Shift. This includes the remaining default terminal + panel shortcuts such as 'Copy' (Ctrl+Shift+C) and 'New Terminal' (Ctrl+Shift+T). - Target Godot version from 3.3.2-stable -> 3.4.4-stable. ### Removed diff --git a/addons/godot_xterm/editor_plugins/terminal/editor_terminal.gd b/addons/godot_xterm/editor_plugins/terminal/editor_terminal.gd index 349b227..7e4daf6 100644 --- a/addons/godot_xterm/editor_plugins/terminal/editor_terminal.gd +++ b/addons/godot_xterm/editor_plugins/terminal/editor_terminal.gd @@ -67,22 +67,27 @@ func _poll(): func _input(event): - if not has_focus(): - return - - # Ignore some input that is used by shortcuts. - # TODO: Figure out how to handle this properly as the user might set their - # own custom shortcuts. - if event is InputEventKey: - if event.shift: + if has_focus() and event is InputEventKey and event.is_pressed(): + if event.control and event.scancode in [KEY_PAGEUP, KEY_PAGEDOWN]: + # Handled by switch tabs shortcut. return - if event.control and event.scancode == KEY_PAGEUP or event.scancode == KEY_PAGEDOWN: + if event.control and event.shift: + # Not handled by terminal. return - # We need to handle many input events otherwise keys such as TAB, ctrl, etc. - # will trigger editor shortcuts when using them in the terminal. - if event is InputEventKey: + # Handle all other InputEventKey events to prevent triggering of editor + # shortcuts when using the terminal. + # + # Currently the only way to get shortcuts is by calling editor_settings.get_setting("shortcuts") + # and it returns an array that *only* contains shortcuts that have been modified from the original. + # Once https://github.com/godotengine/godot-proposals/issues/4112 is resolved it should be possible + # to get all shortcuts by their editor setting string as documented here: + # https://docs.godotengine.org/en/stable/tutorials/editor/default_key_mapping.html. + # In this case we could simply add a setting called something like "allowed shortcuts" or + # "propagated shortcuts" consisting of an array of shortcut editor setting strings. + # For example "editor/save_scene" which saves the scene and by default maps to 'Ctrl + S'. + # Then any shortcut events listed here can be handled by the terminal *and* the editor. get_tree().set_input_as_handled() _gui_input(event)