feat(term): re-enable keyboard shortcuts

Closes #65.
This commit is contained in:
Leroy Hopson 2024-05-05 16:28:29 +12:00 committed by Leroy Hopson
parent 4c4e61cf99
commit 77b1481f8e
7 changed files with 79 additions and 98 deletions

View file

@ -1,3 +1,9 @@
[gd_resource type="Shortcut" format=3 uid="uid://cdr3iu6ttahlt"] [gd_resource type="Shortcut" load_steps=2 format=3 uid="uid://cdr3iu6ttahlt"]
[sub_resource type="InputEventKey" id="InputEventKey_emaic"]
shift_pressed = true
ctrl_pressed = true
keycode = 67
[resource] [resource]
events = [SubResource("InputEventKey_emaic")]

View file

@ -1,11 +1,9 @@
[gd_resource type="Shortcut" load_steps=2 format=2] [gd_resource type="Shortcut" load_steps=2 format=3 uid="uid://b5vans7f0vp2y"]
[sub_resource type="InputEventKey" id=1] [sub_resource type="InputEventKey" id="InputEventKey_7k47m"]
shift = true shift_pressed = true
control = true ctrl_pressed = true
command = true keycode = 88
pressed = true
scancode = 88
[resource] [resource]
shortcut = SubResource( 1 ) events = [SubResource("InputEventKey_7k47m")]

View file

@ -1,11 +1,9 @@
[gd_resource type="Shortcut" load_steps=2 format=2] [gd_resource type="Shortcut" load_steps=2 format=3 uid="uid://d3iu5cplfailp"]
[sub_resource type="InputEventKey" id=1] [sub_resource type="InputEventKey" id="InputEventKey_0hq5g"]
shift = true shift_pressed = true
control = true ctrl_pressed = true
command = true keycode = 84
pressed = true
scancode = 84
[resource] [resource]
shortcut = SubResource( 1 ) events = [SubResource("InputEventKey_0hq5g")]

View file

@ -1,11 +1,9 @@
[gd_resource type="Shortcut" load_steps=2 format=2] [gd_resource type="Shortcut" load_steps=2 format=3 uid="uid://cn2b3aeang6b"]
[sub_resource type="InputEventKey" id=1] [sub_resource type="InputEventKey" id="InputEventKey_sihkr"]
shift = true shift_pressed = true
control = true ctrl_pressed = true
command = true keycode = 86
pressed = true
scancode = 86
[resource] [resource]
shortcut = SubResource( 1 ) events = [SubResource("InputEventKey_sihkr")]

View file

@ -1,10 +1,8 @@
[gd_resource type="Shortcut" load_steps=2 format=2] [gd_resource type="Shortcut" load_steps=2 format=3 uid="uid://dpb1qwlv6mkfs"]
[sub_resource type="InputEventKey" id=1] [sub_resource type="InputEventKey" id="InputEventKey_v5b4d"]
control = true ctrl_pressed = true
command = true keycode = 4194324
pressed = true
scancode = 16777235
[resource] [resource]
shortcut = SubResource( 1 ) events = [SubResource("InputEventKey_v5b4d")]

View file

@ -1,10 +1,8 @@
[gd_resource type="Shortcut" load_steps=2 format=2] [gd_resource type="Shortcut" load_steps=2 format=3 uid="uid://djs5hhu8vbmqf"]
[sub_resource type="InputEventKey" id=1] [sub_resource type="InputEventKey" id="InputEventKey_svjos"]
control = true ctrl_pressed = true
command = true keycode = 4194323
pressed = true
scancode = 16777236
[resource] [resource]
shortcut = SubResource( 1 ) events = [SubResource("InputEventKey_svjos")]

View file

@ -67,24 +67,23 @@ func _update_settings() -> void:
tabs.tab_close_display_policy = TabBar.CLOSE_BUTTON_SHOW_ALWAYS tabs.tab_close_display_policy = TabBar.CLOSE_BUTTON_SHOW_ALWAYS
#FIXME # Update shortcuts.
# # Update shortcuts. if _settings.new_terminal_shortcut:
# if _settings.new_terminal_shortcut: terminal_popup_menu.set_item_shortcut(
# terminal_popup_menu.set_item_shortcut( TerminalPopupMenuOptions.NEW_TERMINAL, _settings.new_terminal_shortcut, true
# TerminalPopupMenuOptions.NEW_TERMINAL, _settings.new_terminal_shortcut, true )
# ) if _settings.kill_terminal_shortcut:
# if _settings.kill_terminal_shortcut: terminal_popup_menu.set_item_shortcut(
# terminal_popup_menu.set_item_shortcut( TerminalPopupMenuOptions.KILL_TERMINAL, _settings.kill_terminal_shortcut, false
# TerminalPopupMenuOptions.KILL_TERMINAL, _settings.kill_terminal_shortcut, false )
# ) if _settings.copy_shortcut:
# if _settings.copy_shortcut: terminal_popup_menu.set_item_shortcut(
# terminal_popup_menu.set_item_shortcut( TerminalPopupMenuOptions.COPY, _settings.copy_shortcut, false
# TerminalPopupMenuOptions.COPY, _settings.copy_shortcut, false )
# ) if _settings.paste_shortcut:
# if _settings.paste_shortcut: terminal_popup_menu.set_item_shortcut(
# terminal_popup_menu.set_item_shortcut( TerminalPopupMenuOptions.PASTE, _settings.paste_shortcut, false
# TerminalPopupMenuOptions.PASTE, _settings.paste_shortcut, false )
# )
_update_terminal_tabs() _update_terminal_tabs()
@ -172,53 +171,43 @@ func _input(event: InputEvent) -> void:
return return
# Global shortcut to open new terminal and make terminal panel visible. # Global shortcut to open new terminal and make terminal panel visible.
# FIXME if _settings.new_terminal_shortcut and _settings.new_terminal_shortcut.matches_event(event):
# if _settings.new_terminal_shortcut and _settings.new_terminal_shortcut.shortcut: get_viewport().set_input_as_handled()
# if event.is_match(_settings.new_terminal_shortcut.shortcut): editor_plugin.make_bottom_panel_item_visible(self)
# get_tree().set_input_as_handled() _on_AddButton_pressed()
# editor_plugin.make_bottom_panel_item_visible(self)
# _on_AddButton_pressed()
# Non-global shortcuts, only applied if terminal is active and focused. # Non-global shortcuts, only applied if terminal is active and focused.
if ( if (
tabs.get_tab_count() > 0 and tab_container.get_child(tabs.current_tab).has_focus() tabs.get_tab_count() > 0 and tab_container.get_child(tabs.current_tab).has_focus()
or terminal_popup_menu.has_focus() or terminal_popup_menu.has_focus()
): ):
pass
# Kill terminal. # Kill terminal.
# FIXME shortcut if (
_settings.kill_terminal_shortcut
and _settings.kill_terminal_shortcut.matches_event(event)
# if _settings.kill_terminal_shortcut and _settings.kill_terminal_shortcut.shortcut: ):
# if event.is_match(_settings.kill_terminal_shortcut.shortcut): get_viewport().set_input_as_handled()
# get_tree().set_input_as_handled() _on_TerminalPopupMenu_id_pressed(TerminalPopupMenuOptions.KILL_TERMINAL)
# _on_TerminalPopupMenu_id_pressed(TerminalPopupMenuOptions.KILL_TERMINAL)
# Copy. # Copy.
#FIXME if _settings.copy_shortcut and _settings.copy_shortcut.matches_event(event):
# if _settings.copy_shortcut and _settings.copy_shortcut.shortcut: get_viewport().set_input_as_handled()
# if event.is_match(_settings.copy_shortcut.shortcut): _on_TerminalPopupMenu_id_pressed(TerminalPopupMenuOptions.COPY)
# get_tree().set_input_as_handled()
# _on_TerminalPopupMenu_id_pressed(TerminalPopupMenuOptions.COPY)
# Paste. # Paste.
#FIXME if _settings.paste_shortcut and _settings.paste_shortcut.matches_event(event):
# if _settings.paste_shortcut and _settings.paste_shortcut.shortcut: get_viewport().set_input_as_handled()
# if event.is_match(_settings.paste_shortcut.shortcut): _on_TerminalPopupMenu_id_pressed(TerminalPopupMenuOptions.PASTE)
# get_tree().set_input_as_handled()
# _on_TerminalPopupMenu_id_pressed(TerminalPopupMenuOptions.PASTE) # Next tab.
# if _settings.next_tab_shortcut and _settings.next_tab_shortcut.matches_event(event):
# # Next tab. get_viewport().set_input_as_handled()
# if _settings.next_tab_shortcut and _settings.next_tab_shortcut.shortcut: tabs.current_tab = min(tabs.current_tab + 1, tabs.get_tab_count() - 1)
# if event.is_match(_settings.next_tab_shortcut.shortcut):
# get_tree().set_input_as_handled() # Previous tab.
# tabs.current_tab = min(tabs.current_tab + 1, tabs.get_tab_count() - 1) if _settings.previous_tab_shortcut and _settings.previous_tab_shortcut.matches_event(event):
# get_viewport().set_input_as_handled()
# # Previous tab. tabs.current_tab = max(tabs.current_tab - 1, 0)
# if _settings.previous_tab_shortcut and _settings.previous_tab_shortcut.shortcut:
# if event.is_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): func _on_TabContainer_gui_input(event):
@ -238,11 +227,7 @@ func _on_TerminalPopupMenu_id_pressed(id):
TerminalPopupMenuOptions.COPY: TerminalPopupMenuOptions.COPY:
DisplayServer.clipboard_set(terminal.copy_selection()) DisplayServer.clipboard_set(terminal.copy_selection())
TerminalPopupMenuOptions.PASTE: TerminalPopupMenuOptions.PASTE:
for i in DisplayServer.clipboard_get().length(): terminal.write(DisplayServer.clipboard_get())
var event = InputEventKey.new()
event.unicode = DisplayServer.clipboard_get().unicode_at(i)
event.button_pressed = true
terminal._gui_input(event)
TerminalPopupMenuOptions.COPY_ALL: TerminalPopupMenuOptions.COPY_ALL:
DisplayServer.clipboard_set(terminal.copy_all()) DisplayServer.clipboard_set(terminal.copy_all())
TerminalPopupMenuOptions.CLEAR: TerminalPopupMenuOptions.CLEAR: