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

Improve hotkey rendering in documentation #1479

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Niloth-p
Copy link
Collaborator

What does this PR do, and why?

Improves the rendering of hotkeys in hotkeys.md.

  • Make lowercase alphabet keys display as uppercase to match their physical representation in a keyboard.
  • Added a prefix of Shift to uppercase alphabet keys
  • Use the new display_keys_for_command() helper function in keys.py
    • Space-separated keys that were previously being rendered separately, are now rendered as a single key
    • Special key names are capitalized
  • Added arrow symbols to the direction keys

Outstanding aspect(s)

Tests are not included.

External discussion & connections

How did you test this?

  • Manually - Visual changes

Visual changes

image

@zulipbot zulipbot added the size: XL [Automatic label added by zulipbot] label Apr 11, 2024
@Niloth-p
Copy link
Collaborator Author

@zulipbot add "area: hotkeys" "PR needs review"

@zulipbot zulipbot added area: hotkeys PR needs review PR requires feedback to proceed labels Apr 11, 2024
@zulipbot
Copy link
Member

Hello @zulip/server-hotkeys members, this pull request was labeled with the "area: hotkeys" label, so you may want to check it out!

Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@Niloth-p Thanks for this matching PR to #1476 👍

I replied about this in the stream, but left some comments inline too, which will apply depending on how we move forward with this.

Comment on lines +90 to +93
LEFT_ARROW = "←" # LEFTWARDS ARROW, U+2190
UP_ARROW = "↑" # UPWARDS ARROW, U+2191
RIGHT_ARROW = "→" # RIGHTWARDS ARROW, U+2192
DOWN_ARROW = "↓" # DOWNWARDS ARROW, U+2193
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm inclined to keep this change as something that we choose to do universally, rather than only in the hotkeys doc.

We'll definitely want a space between the text and symbols if we do this.

Copy link
Collaborator Author

@Niloth-p Niloth-p Apr 13, 2024

Choose a reason for hiding this comment

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

I'm inclined to keep this change as something that we choose to do universally, rather than only in the hotkeys doc.

We'll definitely want a space between the text and symbols if we do this.

Just to clarify,
We're updating all direction keys (and just the direction keys) to be - text + space + symbol.
Direction keys that are used in keys.py, in hotkeys.md and the ones in core.py (popup headers).

Copy link
Collaborator

Choose a reason for hiding this comment

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

My main point was that we'll likely want to leave the symbol change to a different PR since I'm not sure we want it only in the docs. Specific symbols can be a separate discussion too - I recall some from the original PR weren't that clear.

Then, with the original changes you made I noticed that there wasn't a space, so for that future work the second comment I made was to indicate that we'll want a space if/when we do that.

Comment on lines 122 to 127
f"<kbd>Shift</kbd> + <kbd>{key}</kbd>"
if len(key) == 1 and key.isupper()
else f"<kbd>{key.capitalize()}</kbd>"
if len(key) == 1
else f"<kbd>{key + DIRECTION_TO_SYMBOL_MAP.get(key, '')}</kbd>"
for key in key_combination.split()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I replied separately in the stream, so we may not need this change as it stands.

However, when inline conditionals get large they get more difficult to read, so at a minimum I'd go with something like the following:

Suggested change
f"<kbd>Shift</kbd> + <kbd>{key}</kbd>"
if len(key) == 1 and key.isupper()
else f"<kbd>{key.capitalize()}</kbd>"
if len(key) == 1
else f"<kbd>{key + DIRECTION_TO_SYMBOL_MAP.get(key, '')}</kbd>"
for key in key_combination.split()
f"<kbd>Shift</kbd> + <kbd>{key}</kbd>"
if len(key) == 1 and key.isupper()
else (
f"<kbd>{key.capitalize()}</kbd>"
if len(key) == 1
else f"<kbd>{key + DIRECTION_TO_SYMBOL_MAP.get(key, '')}</kbd>"
)
for key in key_combination.split()

However, while it requires rewriting the comprehensions/loops, it may well be clearer to simply express it as regular if statements instead - particularly given one of the inline conditionals is itself a +-separated string.

@zulipbot zulipbot added size: L [Automatic label added by zulipbot] and removed size: XL [Automatic label added by zulipbot] labels Apr 13, 2024
Uses the new display functions from keys.py.

Applies
- Capitalization of special keys.
- Fix "<kbd>page</kbd> + <kbd>up</kbd>" to "<kbd>PgUp</kbd>".

Fixes zulip#945.
@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] labels Apr 13, 2024
Copy link
Collaborator Author

@Niloth-p Niloth-p left a comment

Choose a reason for hiding this comment

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

Commit Flow:

  1. Apply the display functions from keys.py.
  2. Append direction key symbols - in UI and docs.
  3. Update the scroll prompt in Popup headers.
  4. Use Shift in docs (for demo). Created functions and refactored the formatting.

Also, some miscellaneous changes,

  • Added a --fix argument in error message.
  • Added a docstring to a function in lint-hotkeys, for full coverage.

The commit structure is temporary.
I've just submitted the changes, I'll need to re-order them once we choose the parts we want, and group them.

Visual Changes

Help Menu
im2
Popup Header
im3

tools/lint-hotkeys Show resolved Hide resolved
for symbol in ARROW_SYMBOLS:
if symbol in key_combination:
return f"<kbd>{key_combination}</kbd>"
return " + ".join([format_key(key) for key in key_combination.split()])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just added for an alternative option.
Also, there's the limitation that format_key_combination() does not work when the arrow key is used with modifier keys.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Re the point about the arrow keys, again let's keep that for building later.

One issue here is how we're defining what a 'key' is for various purposes, ie. surrounding by <kbd> tags as a keyboard-key, or as a key-combination. Currently the display function just gives a string, but we're not limited to that data format until we ultimately must output it. Also, if we style the keys (physical keyboard and combinations) in the UI, we'll likely want to think of how we structure them in a similar way.

tools/lint-hotkeys Show resolved Hide resolved
Comment on lines +90 to +93
LEFT_ARROW = "←" # LEFTWARDS ARROW, U+2190
UP_ARROW = "↑" # UPWARDS ARROW, U+2191
RIGHT_ARROW = "→" # RIGHTWARDS ARROW, U+2192
DOWN_ARROW = "↓" # DOWNWARDS ARROW, U+2193
Copy link
Collaborator Author

@Niloth-p Niloth-p Apr 13, 2024

Choose a reason for hiding this comment

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

I'm inclined to keep this change as something that we choose to do universally, rather than only in the hotkeys doc.

We'll definitely want a space between the text and symbols if we do this.

Just to clarify,
We're updating all direction keys (and just the direction keys) to be - text + space + symbol.
Direction keys that are used in keys.py, in hotkeys.md and the ones in core.py (popup headers).

UP_ARROW = "↑" # UPWARDS ARROW, U+2191
RIGHT_ARROW = "→" # RIGHTWARDS ARROW, U+2192
DOWN_ARROW = "↓" # DOWNWARDS ARROW, U+2193
ARROW_SYMBOLS = [LEFT_ARROW, UP_ARROW, RIGHT_ARROW, DOWN_ARROW]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For convenient use in lint-hotkeys to check if the key_combination contains any of the arrow keys.

Replace the hardcoded scroll hints with
the commands' display keys.
Prepends upper case alphabets with 'Shift + '.
@zulipbot
Copy link
Member

Heads up @Niloth-p, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@Niloth-p Thanks for splitting out the core changes - I just merged the first commit as d65cbee 🎉

Regarding the remainder, I left inline comments.

For reviewing, it's good to have separate changes in separate commits except for the earliest code demos. For now, let's restructure the remainder to have the capitalization first, symbols last (if left in for others to view), and any adjustment to the linting tool in one or more separate commits.

Leaving the symbols until last, which are more of an unknown, means we can drop the commit at the end without needing to adjust the intervening commits for conflicts.

Having just been able to test it, the use of the common text in the menu titles looks promising as a refactor, but less-so with the symbols with the text. Without the symbols it looks better, but the upper case text from the capitalization then dominates the menu titles? I do think that refactor would be a good improvement, if not using the new key casing yet for this reason. It could then lead onto the popup general key improvements.

tools/lint-hotkeys Show resolved Hide resolved
Comment on lines +90 to +93
LEFT_ARROW = "←" # LEFTWARDS ARROW, U+2190
UP_ARROW = "↑" # UPWARDS ARROW, U+2191
RIGHT_ARROW = "→" # RIGHTWARDS ARROW, U+2192
DOWN_ARROW = "↓" # DOWNWARDS ARROW, U+2193
Copy link
Collaborator

Choose a reason for hiding this comment

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

My main point was that we'll likely want to leave the symbol change to a different PR since I'm not sure we want it only in the docs. Specific symbols can be a separate discussion too - I recall some from the original PR weren't that clear.

Then, with the original changes you made I noticed that there wasn't a space, so for that future work the second comment I made was to indicate that we'll want a space if/when we do that.

tools/lint-hotkeys Show resolved Hide resolved
for symbol in ARROW_SYMBOLS:
if symbol in key_combination:
return f"<kbd>{key_combination}</kbd>"
return " + ".join([format_key(key) for key in key_combination.split()])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Re the point about the arrow keys, again let's keep that for building later.

One issue here is how we're defining what a 'key' is for various purposes, ie. surrounding by <kbd> tags as a keyboard-key, or as a key-combination. Currently the display function just gives a string, but we're not limited to that data format until we ultimately must output it. Also, if we style the keys (physical keyboard and combinations) in the UI, we'll likely want to think of how we structure them in a similar way.

self.show_pop_up(help_view, "area:help")

def show_markdown_help(self) -> None:
markdown_view = MarkdownHelpView(self, "Markdown Help Menu (up/down scrolls)")
markdown_view = MarkdownHelpView(self, "Markdown Help Menu " + SCROLL_PROMPT)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Improvements and bugfixes to the doc/linting are fine in a related PR, but this commit looks like a different overall change - useful for consistency as it is 👍

You should be able to cherry-pick it into another branch just fine.

I've not tested this yet, but you updated the formatting of other lines but not this one?

This also prompts thoughts on ensuring we're consistent with naming of the menu titles and their names in the descriptions of the related hotkeys, which I've not checked recently, and I'm not sure if it's worth checking technically, or manually.

@neiljp neiljp added PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback and removed PR needs review PR requires feedback to proceed labels Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: hotkeys has conflicts PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve key rendering in documentation
3 participants