Skip to content

Commit dca32c4

Browse files
authored
Merge branch 'main' into fix-tint
2 parents 57e1e0d + 8415e07 commit dca32c4

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
89
## [3.1.1] - 2024-04-22
910

1011
### Fixed
1112

1213
- Fixed issue with tint filter https://github.com/Textualize/textual/pull/5757
14+
- Fixed a crash when setting keymap before app mount https://github.com/Textualize/textual/issues/5742
1315

1416
## [3.1.0] - 2025-04-12
1517

src/textual/dom.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,8 @@ def refresh_bindings(self) -> None:
18181818
See [actions](/guide/actions#dynamic-actions) for how to use this method.
18191819
18201820
"""
1821-
self.screen.refresh_bindings()
1821+
if self._is_mounted:
1822+
self.screen.refresh_bindings()
18221823

18231824
async def action_toggle(self, attribute_name: str) -> None:
18241825
"""Toggle an attribute on the node.

tests/test_keymap.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,28 @@ def on_mount(self) -> None:
192192
await pilot.press("i")
193193
assert parent_counter == 1
194194
assert child_counter == 1
195+
196+
197+
async def test_set_keymap_before_app_mount():
198+
"""Ensure we can set the keymap before mount without crash.
199+
200+
https://github.com/Textualize/textual/issues/5742
201+
"""
202+
203+
worked = False
204+
205+
class MyApp(App[None]):
206+
207+
BINDINGS = [Binding(key="x", action="test", id="test")]
208+
209+
def __init__(self) -> None:
210+
super().__init__()
211+
self.update_keymap({"test": "y"})
212+
213+
def action_test(self) -> None:
214+
nonlocal worked
215+
worked = True
216+
217+
async with MyApp().run_test() as pilot:
218+
await pilot.press("y")
219+
assert worked is True

0 commit comments

Comments
 (0)