Add next/previous tab shortcuts

This commit is contained in:
Leroy Hopson 2021-07-13 22:48:02 +07:00
parent 97e07093b2
commit de7980c077
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
5 changed files with 41 additions and 0 deletions

View file

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

View file

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

View file

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

View file

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

View file

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