-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
base: main
Are you sure you want to change the base?
Conversation
39886e1
to
5683c3a
Compare
@zulipbot add "area: hotkeys" "PR needs review" |
Hello @zulip/server-hotkeys members, this pull request was labeled with the "area: hotkeys" label, so you may want to check it out! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LEFT_ARROW = "←" # LEFTWARDS ARROW, U+2190 | ||
UP_ARROW = "↑" # UPWARDS ARROW, U+2191 | ||
RIGHT_ARROW = "→" # RIGHTWARDS ARROW, U+2192 | ||
DOWN_ARROW = "↓" # DOWNWARDS ARROW, U+2193 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
Outdated
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() |
There was a problem hiding this comment.
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:
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.
5683c3a
to
88cd99e
Compare
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.
88cd99e
to
b682d2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit Flow:
- Apply the display functions from keys.py.
- Append direction key symbols - in UI and docs.
- Update the scroll prompt in Popup headers.
- 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
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()]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
LEFT_ARROW = "←" # LEFTWARDS ARROW, U+2190 | ||
UP_ARROW = "↑" # UPWARDS ARROW, U+2191 | ||
RIGHT_ARROW = "→" # RIGHTWARDS ARROW, U+2192 | ||
DOWN_ARROW = "↓" # DOWNWARDS ARROW, U+2193 |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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 + '.
c94310a
to
3897db4
Compare
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 |
There was a problem hiding this 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.
LEFT_ARROW = "←" # LEFTWARDS ARROW, U+2190 | ||
UP_ARROW = "↑" # UPWARDS ARROW, U+2191 | ||
RIGHT_ARROW = "→" # RIGHTWARDS ARROW, U+2192 | ||
DOWN_ARROW = "↓" # DOWNWARDS ARROW, U+2193 |
There was a problem hiding this comment.
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.
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()]) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
What does this PR do, and why?
Improves the rendering of hotkeys in hotkeys.md.
Outstanding aspect(s)
Tests are not included.
External discussion & connections
How did you test this?
Visual changes