File tree 3 files changed +33
-1
lines changed
3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
6
6
and this project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
7
7
8
+ ## Unreleased
9
+
10
+ ### Fixed
11
+
12
+ - Fixed a crash when setting keymap before app mount https://github.com/Textualize/textual/issues/5742
13
+
8
14
## [ 3.1.0] - 2025-04-12
9
15
10
16
### Fixed
Original file line number Diff line number Diff line change @@ -1818,7 +1818,8 @@ def refresh_bindings(self) -> None:
1818
1818
See [actions](/guide/actions#dynamic-actions) for how to use this method.
1819
1819
1820
1820
"""
1821
- self .screen .refresh_bindings ()
1821
+ if self ._is_mounted :
1822
+ self .screen .refresh_bindings ()
1822
1823
1823
1824
async def action_toggle (self , attribute_name : str ) -> None :
1824
1825
"""Toggle an attribute on the node.
Original file line number Diff line number Diff line change @@ -192,3 +192,28 @@ def on_mount(self) -> None:
192
192
await pilot .press ("i" )
193
193
assert parent_counter == 1
194
194
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
You can’t perform that action at this time.
0 commit comments