Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add title-to-title scroll feature to Help Menu #1527

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
|Scroll down|<kbd>PgDn</kbd> / <kbd>J</kbd>|
|Go to bottom / Last message|<kbd>End</kbd> / <kbd>G</kbd>|
|Trigger the selected entry|<kbd>Enter</kbd> / <kbd>Space</kbd>|
|Go to previous help category|<kbd>p</kbd>|
|Go to next help category|<kbd>n</kbd>|

## Switching Messages View
|Command|Key Combination|
Expand Down
2 changes: 1 addition & 1 deletion tools/lint-hotkeys
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SCRIPT_NAME = PurePath(__file__).name
HELP_TEXT_STYLE = re.compile(r"^[a-zA-Z /()',&@#:_-]*$")

# Exclude keys from duplicate keys checking
KEYS_TO_EXCLUDE = ["q", "e", "m", "r", "Esc"]
KEYS_TO_EXCLUDE = ["q", "e", "m", "r", "Esc", "p", "n"]


def main(fix: bool) -> None:
Expand Down
12 changes: 12 additions & 0 deletions zulipterminal/config/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ class KeyBinding(TypedDict):
'help_text': 'Trigger the selected entry',
'key_category': 'navigation',
},
'GO_TO_PREVIOUS_TITLE': {
'keys': ['p'],
'help_text': 'Go to previous help category',
'key_category': 'navigation',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether navigation is a good category for this, but I don't see a better one either. The problem I see is that the two new commands are very specific to the "Help" popup while the other ones seem to be more generic. In that sense the new commands seem to be a bit similar to "Show/hide user information (from user list)": It could also be "Go to previous category (in Help Menu)" or something like that.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also wondering whether it's useful to put hints towards those keys in the headline of the popup. It probably will get a bit crowded there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, see the linked topic for some discussion. The keys aren't critical here, but my thoughts would be to use ones that

  • don't clash with existing more-global key use (like n & p; so don't need to remember context)
  • more easily translate to use more globally in the UI (reuse/memorization; can apply to other vertical sectioned lists)
  • have relative movement (like these, but not eg. numbered points to jump to)

Some options I raised were perhaps tab/shift-tab (depending on usage of that elsewhere), and various matching parentheses such as (/), or ], or }.

'excluded_from_random_tips': True,
},
'GO_TO_NEXT_TITLE': {
'keys': ['n'],
'help_text': 'Go to next help category',
'key_category': 'navigation',
'excluded_from_random_tips': True,
},
'REPLY_MESSAGE': {
'keys': ['r', 'enter'],
'help_text': 'Reply to the current message',
Expand Down
27 changes: 27 additions & 0 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,33 @@ def __init__(self, controller: Any, title: str) -> None:

super().__init__(controller, widgets, "HELP", popup_width, title)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mainly independent of this PR, but it seems a bit strange to me to have a super().__init__ call in the middle of a constructor. I would have expected it at the start of the constructor, but that doesn't seem to be a pattern in Zulip Terminal.

It seems that the general pattern is to have the super init at the end. But now that the setup code for category_start_positions relies on the parent to be initialized it lands in the middle.

Nevertheless I'd be curious if that's also something we can prevent, maybe by putting the responsibility for the category positions to the parent or something.


self.category_start_positions = [
index
for index, widget in enumerate(self.log)
if isinstance(widget, urwid.Text)
and widget.get_text()[1]
and widget.get_text()[1][0][0] == "popup_category"
]

def keypress(self, size: urwid_Size, key: str) -> str:
if is_command_key("GO_TO_NEXT_TITLE", key):
focus_position = self.log.get_focus()[1]
last_visible_position = focus_position + size[1] - 1 # type: ignore[misc]
last_help_entry = len(self.log) - 1
if last_help_entry > last_visible_position:
for category_start_position in self.category_start_positions:
if category_start_position > focus_position:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My LSP (I think) shows me a type error here. I think this file is not typed, so the CI passes on github. The error is:

Operator ">" not supported for types "int" and "Unknown | None"
Operator ">" not supported for types "int" and "None"

Which might be caused by the previous # type: ignore[misc]. I would be curious if there's a way to make mypy happy without the ignore.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, I think this was caused by using a later version of Urwid here.

self.log.set_focus(category_start_position)
break

elif is_command_key("GO_TO_PREVIOUS_TITLE", key):
focus_position = self.log.get_focus()[1]
for category_start_position in reversed(self.category_start_positions):
if category_start_position < focus_position:
self.log.set_focus(category_start_position)
break
return super().keypress(size, key)


class MarkdownHelpView(PopUpView):
def __init__(self, controller: Any, title: str) -> None:
Expand Down
Loading