From de7980c077c5e5094ec5008d1cf9eb6089b19b1a Mon Sep 17 00:00:00 2001 From: Leroy Hopson Date: Tue, 13 Jul 2021 22:48:02 +0700 Subject: [PATCH] Add next/previous tab shortcuts --- .../editor_plugins/terminal/editor_terminal.gd | 6 ++++++ .../terminal/settings/default_tab_left_shortcut.tres | 10 ++++++++++ .../settings/default_tab_right_shortcut.tres | 10 ++++++++++ .../terminal/settings/terminal_settings.gd | 3 +++ .../editor_plugins/terminal/terminal_panel.gd | 12 ++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 addons/godot_xterm/editor_plugins/terminal/settings/default_tab_left_shortcut.tres create mode 100644 addons/godot_xterm/editor_plugins/terminal/settings/default_tab_right_shortcut.tres diff --git a/addons/godot_xterm/editor_plugins/terminal/editor_terminal.gd b/addons/godot_xterm/editor_plugins/terminal/editor_terminal.gd index c250f2d..e41da0f 100644 --- a/addons/godot_xterm/editor_plugins/terminal/editor_terminal.gd +++ b/addons/godot_xterm/editor_plugins/terminal/editor_terminal.gd @@ -68,10 +68,16 @@ 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: 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: diff --git a/addons/godot_xterm/editor_plugins/terminal/settings/default_tab_left_shortcut.tres b/addons/godot_xterm/editor_plugins/terminal/settings/default_tab_left_shortcut.tres new file mode 100644 index 0000000..54eda3c --- /dev/null +++ b/addons/godot_xterm/editor_plugins/terminal/settings/default_tab_left_shortcut.tres @@ -0,0 +1,10 @@ +[gd_resource type="ShortCut" load_steps=2 format=2] + +[sub_resource type="InputEventKey" id=1] +control = true +command = true +pressed = true +scancode = 16777235 + +[resource] +shortcut = SubResource( 1 ) diff --git a/addons/godot_xterm/editor_plugins/terminal/settings/default_tab_right_shortcut.tres b/addons/godot_xterm/editor_plugins/terminal/settings/default_tab_right_shortcut.tres new file mode 100644 index 0000000..66ce66f --- /dev/null +++ b/addons/godot_xterm/editor_plugins/terminal/settings/default_tab_right_shortcut.tres @@ -0,0 +1,10 @@ +[gd_resource type="ShortCut" load_steps=2 format=2] + +[sub_resource type="InputEventKey" id=1] +control = true +command = true +pressed = true +scancode = 16777236 + +[resource] +shortcut = SubResource( 1 ) diff --git a/addons/godot_xterm/editor_plugins/terminal/settings/terminal_settings.gd b/addons/godot_xterm/editor_plugins/terminal/settings/terminal_settings.gd index e97a27a..da25899 100644 --- a/addons/godot_xterm/editor_plugins/terminal/settings/terminal_settings.gd +++ b/addons/godot_xterm/editor_plugins/terminal/settings/terminal_settings.gd @@ -17,6 +17,9 @@ export (ShortCut) var kill_terminal_shortcut = preload("./default_kill_terminal_ export (ShortCut) var copy_shortcut = preload("./default_copy_shortcut.tres") export (ShortCut) var paste_shortcut = preload("./default_paste_shortcut.tres") +export (ShortCut) var next_tab_shortcut = preload("./default_tab_right_shortcut.tres") +export (ShortCut) var previous_tab_shortcut = preload("./default_tab_left_shortcut.tres") + ### Scroll settings ### # The maximum amount of lines the terminal keeps in its buffer. diff --git a/addons/godot_xterm/editor_plugins/terminal/terminal_panel.gd b/addons/godot_xterm/editor_plugins/terminal/terminal_panel.gd index b756cf3..32a0bb5 100644 --- a/addons/godot_xterm/editor_plugins/terminal/terminal_panel.gd +++ b/addons/godot_xterm/editor_plugins/terminal/terminal_panel.gd @@ -193,6 +193,18 @@ func _input(event: InputEvent) -> void: get_tree().set_input_as_handled() _on_TerminalPopupMenu_id_pressed(TerminalPopupMenuOptions.PASTE) + # Next tab. + if _settings.next_tab_shortcut and _settings.next_tab_shortcut.shortcut: + if event.shortcut_match(_settings.next_tab_shortcut.shortcut): + get_tree().set_input_as_handled() + tabs.current_tab = min(tabs.current_tab + 1, tabs.get_tab_count() - 1) + + # Previous tab. + if _settings.previous_tab_shortcut and _settings.previous_tab_shortcut.shortcut: + if event.shortcut_match(_settings.previous_tab_shortcut.shortcut): + get_tree().set_input_as_handled() + tabs.current_tab = max(tabs.current_tab - 1, 0) + func _on_TabContainer_gui_input(event): if event is InputEventMouseButton and event.button_index == BUTTON_RIGHT: