File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 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.
55The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
66and this project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
77
8+ ## Unreleased
9+
10+ ### Fixed
11+
12+ - Fixed a crash when setting keymap before app mount https://github.com/Textualize/textual/issues/5742
13+
814## [ 3.1.0] - 2025-04-12
915
1016### Fixed
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments