-
-
Notifications
You must be signed in to change notification settings - Fork 921
fix(help panel): prevent duplicated key displays #5066
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
fix(help panel): prevent duplicated key displays #5066
Conversation
I don't think this will de-duplicate the key displays, except where we have identical keys to the same action. i.e something like this: BINDINGS = [
("foo", "do_foo"),
("foo", "do_foo"),
("bar", "do_foo")
] Should display |
Sorry @willmcgugan, I'm not sure I understand what you mean. Currently if you define a binding with a comma-separated list of keys along with a I don't see any issues with duplicated keys with your example bindings above, but perhaps I'm missing something? |
Consider the following: from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Footer
class HelpPanelApp(App):
BINDINGS = [
Binding("a", "bell", "Ring the bell", key_display="bar"),
Binding("b,e,l", "bell", "Ring the bell", key_display="foo"),
]
def compose(self) -> ComposeResult:
yield Footer()
HelpPanelApp().run() This will only display a single key, when there are multiple that would apply. A contrived example perhaps, but even more likely now we have keymaps. |
Thanks Will for clarifying. I see your point about this edge case, but why would you define multiple bindings like this? The key panel also wouldn't account for these bindings having different descriptions, so why should the key display be different? |
I think I now understand what you meant by this not de-duping the key displays, now that support for keymaps has been released. Hopefully fixed by 9aa73f0? from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Footer, Label
class MyApp(App[None]):
BINDINGS = [
Binding(
key="i,up",
action="increment",
description="Increment",
id="app.increment",
key_display="INCORRECT",
),
]
def compose(self) -> ComposeResult:
yield Label("Check the footer and help panel")
yield Footer()
def on_mount(self) -> None:
self.action_show_help_panel()
self.set_keymap({"app.increment": "k,plus,j,l"})
def get_key_display(self, binding: Binding) -> str:
if binding.id == "app.increment":
return "correct"
return super().get_key_display(binding)
if __name__ == "__main__":
app = MyApp()
app.run() |
@willmcgugan Friendly ping as currently the duplication of key displays is a bit of a wart in the help panel. The updated |
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.
Thanks. Just a suggestion, which I'm happy to leave as "your call"!
Fixes #5037
Please review the following checklist.