Add keyboard action to go to room by unique prefix

This is especially useful in combination with the
newly introduced `unique_prefix_tab_names` config option. It has
no default binding.
This commit is contained in:
Jonas Schäfer 2020-05-10 11:46:31 +02:00
parent a15e52dc39
commit 1e7ce43789
2 changed files with 38 additions and 0 deletions

View file

@ -374,6 +374,15 @@ Actions list
Similar to F4.
**_go_to_room_name**: Jump to a tab by unique prefix.
Similar to :term:`/wup` and the default *Alt-j*. This action will take
input as long as there is at least one tab name starting with the input
given so far. If there is exactly one tab matching, the action completes
and the current tab is switched over to the tab matching the input. If
no tab matches, the action completes without any change. This means that
you can typically abort the action with Escape.
Status actions
~~~~~~~~~~~~~~

View file

@ -209,6 +209,7 @@ class Core:
'_show_plugins': self.command.plugins,
'_show_xmltab': self.command.xml_tab,
'_toggle_pane': self.toggle_left_pane,
"_go_to_room_name": self.go_to_room_name,
###### status actions ######
'_available': lambda: self.command.status('available'),
'_away': lambda: self.command.status('away'),
@ -1108,6 +1109,34 @@ class Core:
keyboard.continuation_keys_callback = read_next_digit
def go_to_room_name(self) -> None:
room_name_jump = []
def read_next_letter(s) -> None:
nonlocal room_name_jump
room_name_jump.append(s)
any_matched, unique_tab = self.tabs.find_by_unique_prefix(
"".join(room_name_jump)
)
if not any_matched:
return
if unique_tab is not None:
self.tabs.set_current_tab(unique_tab)
# NOTE: returning here means that as soon as the tab is
# matched, normal input resumes. If we do *not* return here,
# any further characters matching the prefix of the tab will
# be swallowed (and a lot of tab switching will happen...),
# until a non-matching character or escape or something is
# pressed.
# This behaviour *may* be desirable.
return
keyboard.continuation_keys_callback = read_next_letter
keyboard.continuation_keys_callback = read_next_letter
def go_to_roster(self) -> None:
"Select the roster as the current tab"
self.tabs.set_current_tab(self.tabs.first())