Skip to content

Commit 748fc07

Browse files
authored
Merge pull request #5724 from Textualize/refresh-keymap-bindings
Refresh keymap bindings
2 parents 3581413 + 9000305 commit 748fc07

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
119119

120120
- Fixed OptionList.add_options exhausting iterator https://github.com/Textualize/textual/pull/5540
121121
- Fixed screen not refreshing after pop https://github.com/Textualize/textual/pull/5543
122+
- Fixed footer / key panel not updating when keymaps are applied https://github.com/Textualize/textual/pull/5724
122123

123124
## [2.0.1] - 2025-02-16
124125

src/textual/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,6 +3710,7 @@ def set_keymap(self, keymap: Keymap) -> None:
37103710
keymap: A mapping of binding IDs to key strings.
37113711
"""
37123712
self._keymap = keymap
3713+
self.refresh_bindings()
37133714

37143715
def update_keymap(self, keymap: Keymap) -> None:
37153716
"""Update the App's keymap, merging with `keymap`.
@@ -3721,6 +3722,7 @@ def update_keymap(self, keymap: Keymap) -> None:
37213722
keymap: A mapping of binding IDs to key strings.
37223723
"""
37233724
self._keymap = {**self._keymap, **keymap}
3725+
self.refresh_bindings()
37243726

37253727
def handle_bindings_clash(
37263728
self, clashed_bindings: set[Binding], node: DOMNode

tests/test_binding.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
InvalidBinding,
1111
NoBinding,
1212
)
13+
from textual.screen import Screen
1314

1415
BINDING1 = Binding("a,b", action="action1", description="description1")
1516
BINDING2 = Binding("c", action="action2", description="description2")
@@ -102,3 +103,27 @@ class BrokenApp(App):
102103

103104
class BrokenApp(App):
104105
BINDINGS = [(", ,", "foo", "Broken")]
106+
107+
108+
async def test_keymap_update() -> None:
109+
"""Check that when keymaps are updated, the bindings_updated signal is sent."""
110+
111+
bindings_updated: list[Screen] = []
112+
113+
class KeymapApp(App):
114+
BINDINGS = [Binding("q", "quit", "Quit", id="quit")]
115+
116+
def signal_bindings_updated(screen: Screen) -> None:
117+
bindings_updated.append(screen)
118+
119+
app = KeymapApp()
120+
async with app.run_test() as pilot:
121+
await pilot.pause()
122+
app.screen.bindings_updated_signal.subscribe(app, signal_bindings_updated)
123+
assert not bindings_updated
124+
app.set_keymap({"quit": "f1"})
125+
await pilot.pause()
126+
assert bindings_updated == [app.screen]
127+
app.set_keymap({"quit": "f1"})
128+
await pilot.pause()
129+
assert bindings_updated == [app.screen, app.screen]

0 commit comments

Comments
 (0)