Skip to content

Commit

Permalink
change to dict.fromkeys for faster de-duping
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Nov 7, 2024
1 parent e516d7e commit a2bd3c3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/textual/widgets/_key_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ def render_description(binding: Binding) -> Text:
get_key_display = self.app.get_key_display
for multi_bindings in action_to_bindings.values():
binding, enabled, tooltip = multi_bindings[0]
unique_key_displays: list[str] = []
for binding, _, _ in multi_bindings:
key_display = get_key_display(binding)
if key_display not in unique_key_displays:
unique_key_displays.append(key_display)
keys_display = " ".join(unique_key_displays)
keys_display = " ".join(
dict.fromkeys( # Remove duplicates while preserving order
get_key_display(binding) for binding, _, _ in multi_bindings
)
)
table.add_row(
Text(keys_display, style=key_style),
render_description(binding),
Expand Down

0 comments on commit a2bd3c3

Please sign in to comment.