Prevent editor shortcuts while terminal is focused

This commit is contained in:
Leroy Hopson 2022-06-01 22:39:06 +07:00
parent bea5d1c27d
commit 6ec3c93c55
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
2 changed files with 21 additions and 12 deletions

View file

@ -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

View file

@ -67,22 +67,27 @@ func _poll():
func _input(event):
if not has_focus():
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
# 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 event.control and event.shift:
# Not handled by terminal.
return
if event.control and event.scancode == KEY_PAGEUP or event.scancode == KEY_PAGEDOWN:
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)