Skip to content

Commit

Permalink
fix key
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed May 22, 2024
1 parent ae4a3f8 commit c14a351
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 0 additions & 1 deletion examples/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class MarkdownApp(App):
("t", "toggle_table_of_contents", "TOC"),
("b", "back", "Back"),
("f", "forward", "Forward"),
("ctrl+d", "app.bell", "Bell"),
]

path = var(Path(__file__).parent / "demo.md")
Expand Down
2 changes: 1 addition & 1 deletion src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ async def check_mouse() -> None:
if widget is not self.mouse_over:
self._set_mouse_over(widget)

self.call_later(check_mouse)
self.call_after_refresh(check_mouse)

def capture_mouse(self, widget: Widget | None) -> None:
"""Send all mouse events to the given widget or disable mouse capture.
Expand Down
23 changes: 15 additions & 8 deletions src/textual/widgets/_footer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ class FooterKey(Widget):
compact = reactive(True)

def __init__(
self, key: str, description: str, action: str, disabled: bool = False
self,
key: str,
key_display: str,
description: str,
action: str,
disabled: bool = False,
) -> None:
self.key = key
self.key_display = key_display
self.description = description
self.action = action
self._disabled = disabled
Expand All @@ -69,24 +75,24 @@ def __init__(
def render(self) -> Text:
key_style = self.get_component_rich_style("footer-key--key")
description_style = self.get_component_rich_style("footer-key--description")
key = self.key
key_display = self.key_display
if self.upper_case_keys:
key = key.upper()
if key.lower().startswith("ctrl+"):
key = "^" + key.split("+", 1)[1]
key_display = key_display.upper()
if key_display.lower().startswith("ctrl+"):
key_display = "^" + key_display.split("+", 1)[1]
description = self.description
if self.compact:
label_text = Text.assemble(
(key, key_style), " ", (description, description_style)
(key_display, key_style), " ", (description, description_style)
)
else:
label_text = Text.assemble(
(f" {key} ", key_style), (description, description_style), " "
(f" {key_display} ", key_style), (description, description_style), " "
)
label_text.stylize_before(self.rich_style)
return label_text

async def on_mouse_up(self) -> None:
async def on_mouse_down(self) -> None:
if self._disabled:
self.app.bell()
else:
Expand Down Expand Up @@ -129,6 +135,7 @@ def compose(self) -> ComposeResult:
self.styles.grid_size_columns = len(bindings)
for binding, enabled in bindings:
yield FooterKey(
binding.key,
binding.key_display or self.app.get_key_display(binding.key),
binding.description,
binding.action,
Expand Down

0 comments on commit c14a351

Please sign in to comment.