Skip to content

Commit e25d7fa

Browse files
committed
snapshot
1 parent b7579b8 commit e25d7fa

File tree

5 files changed

+210
-9
lines changed

5 files changed

+210
-9
lines changed

src/textual/screen.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,19 +340,18 @@ def active_bindings(self) -> dict[str, ActiveBinding]:
340340
# Note that None has a different meaning, which is why there is an `is False`
341341
# rather than a truthy check.
342342
continue
343+
enabled = bool(action_state)
343344
if existing_key_and_binding := bindings_map.get(key):
344345
# This key has already been bound
345-
_, existing_binding, _ = existing_key_and_binding
346346
# Replace priority bindings
347-
if binding.priority and not existing_binding.priority:
348-
bindings_map[key] = ActiveBinding(
349-
namespace, binding, bool(action_state)
350-
)
347+
if (
348+
binding.priority
349+
and not existing_key_and_binding.binding.priority
350+
):
351+
bindings_map[key] = ActiveBinding(namespace, binding, enabled)
351352
else:
352353
# New binding
353-
bindings_map[key] = ActiveBinding(
354-
namespace, binding, bool(action_state)
355-
)
354+
bindings_map[key] = ActiveBinding(namespace, binding, enabled)
356355

357356
return bindings_map
358357

Lines changed: 156 additions & 0 deletions
Loading
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from textual.app import App, ComposeResult
2+
from textual.widget import Widget
3+
from textual.widgets import Footer, Switch
4+
from textual.binding import Binding
5+
6+
7+
class MyWidget(Widget, can_focus=True):
8+
BINDINGS = [
9+
Binding("space", "app.bell", "Bell (Widget)"),
10+
Binding("a", "app.notify('a widget')", "widget"),
11+
Binding("b", "app.notify('b widget')", "widget"),
12+
]
13+
14+
DEFAULT_CSS = """
15+
MyWidget {
16+
border: solid green;
17+
height: 5;
18+
}
19+
"""
20+
21+
22+
class BindApp(App):
23+
BINDINGS = [
24+
Binding("space", "app.bell", "Bell (App)"),
25+
Binding("c", "app.notify('c app')", "app"),
26+
Binding("a", "app.notify('a app')", "app"),
27+
Binding("b", "app.notify('b app')", "app"),
28+
]
29+
30+
def compose(self) -> ComposeResult:
31+
yield MyWidget()
32+
yield Switch()
33+
yield Footer()
34+
35+
def action_notify(self, msg: str):
36+
self.notify(msg)
37+
38+
39+
if __name__ == "__main__":
40+
app = BindApp()
41+
app.run()

tests/snapshot_tests/test_snapshots.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,3 +1405,8 @@ def test_remove_tab_no_animation(snap_compare):
14051405
def test_auto_height_scrollbar(snap_compare):
14061406
"""Regression test for https://github.com/Textualize/textual/issues/4778"""
14071407
assert snap_compare(SNAPSHOT_APPS_DIR / "data_table_auto_height.py")
1408+
1409+
1410+
def test_bind_override(snap_compare):
1411+
"""Regression test for https://github.com/Textualize/textual/issues/4755"""
1412+
assert snap_compare(SNAPSHOT_APPS_DIR / "bind_override.py")

tests/test_binding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_bindings_get_key_spaced_list(more_bindings):
4545
def test_bindings_merge_simple(bindings):
4646
left = BindingsMap([BINDING1])
4747
right = BindingsMap([BINDING2])
48-
assert BindingsMap.merge([left, right]).key_to_bindings == bindings.keys
48+
assert BindingsMap.merge([left, right]).key_to_bindings == bindings.key_to_bindings
4949

5050

5151
def test_bindings_merge_overlap():

0 commit comments

Comments
 (0)