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 simulate key #4798

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Fixed issues in Kitty terminal after exiting app https://github.com/Textualize/textual/issues/4779
- Fixed exception when removing Selects https://github.com/Textualize/textual/pull/4786
- Fixed issue with non-clickable Footer keys https://github.com/Textualize/textual/pull/4798

## [0.73.0] - 2024-07-18

Expand Down
2 changes: 1 addition & 1 deletion src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3029,7 +3029,7 @@ def simulate_key(self, key: str) -> None:
Args:
key: Key to simulate. May also be the name of a key, e.g. "space".
"""
self.call_later(self._check_bindings, key)
self.post_message(events.Key(key, None))

async def _check_bindings(self, key: str, priority: bool = False) -> bool:
"""Handle a key press.
Expand Down
58 changes: 58 additions & 0 deletions tests/footer/test_footer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widget import Widget
from textual.widgets import Button, Footer


async def test_footer_bindings() -> None:
app_binding_count = 0

class TestWidget(Widget, can_focus=True):
BINDINGS = [
Binding("b", "widget_binding", "Overridden Binding"),
]

DEFAULT_CSS = """
TestWidget {
border: tall $background;
width: 50%;
height: 50%;
content-align: center middle;

&:focus {
border: tall $accent;
}
}
"""

def action_widget_binding(self) -> None:
assert False, "should never be called since there is a priority binding"

class PriorityBindingApp(App):
BINDINGS = [
Binding("b", "app_binding", "Priority Binding", priority=True),
]

CSS = """
Screen {
align: center middle;
}
"""

def compose(self) -> ComposeResult:
yield TestWidget()
yield Button("Move Focus")
yield Footer()

def action_app_binding(self) -> None:
nonlocal app_binding_count
app_binding_count += 1

app = PriorityBindingApp()
async with app.run_test() as pilot:
await pilot.pause()
assert app_binding_count == 0
await pilot.click("Footer", offset=(1, 0))
assert app_binding_count == 1
await pilot.click("Footer")
assert app_binding_count == 2
Loading