Skip to content

Commit 8256ca6

Browse files
committed
wip
1 parent 3bdd363 commit 8256ca6

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/textual/binding.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def __init__(
8383
"""
8484

8585
def make_bindings(bindings: Iterable[BindingType]) -> Iterable[Binding]:
86+
bindings = list(bindings)
87+
# print(bindings)
8688
for binding in bindings:
8789
# If it's a tuple of length 3, convert into a Binding first
8890
if isinstance(binding, tuple):
@@ -112,11 +114,9 @@ def make_bindings(bindings: Iterable[BindingType]) -> Iterable[Binding]:
112114
priority=binding.priority,
113115
)
114116

115-
self.keys: dict[str, Binding] = (
116-
{binding.key: binding for binding in make_bindings(bindings)}
117-
if bindings
118-
else {}
119-
)
117+
self.keys: dict[str, list[Binding]] = {}
118+
for binding in make_bindings(bindings or {}):
119+
self.keys.setdefault(binding.key, []).append(binding)
120120

121121
def copy(self) -> _Bindings:
122122
"""Return a copy of this instance.
@@ -141,15 +141,24 @@ def merge(cls, bindings: Iterable[_Bindings]) -> _Bindings:
141141
Returns:
142142
New bindings.
143143
"""
144-
keys: dict[str, Binding] = {}
144+
keys: dict[str, list[Binding]] = {}
145145
for _bindings in bindings:
146-
keys.update(_bindings.keys)
147-
return _Bindings(keys.values())
146+
for key, key_bindings in _bindings.keys.items():
147+
keys.setdefault(key, []).extend(key_bindings)
148+
149+
new_bindings = _Bindings()
150+
new_bindings.keys = keys
151+
return new_bindings
148152

149153
@property
150154
def shown_keys(self) -> list[Binding]:
151155
"""A list of bindings for shown keys."""
152-
keys = [binding for binding in self.keys.values() if binding.show]
156+
keys = [
157+
binding
158+
for bindings in self.keys.values()
159+
for binding in bindings
160+
if binding.show
161+
]
153162
return keys
154163

155164
def bind(

src/textual/widgets/_footer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ def compose(self) -> ComposeResult:
170170
for binding, enabled in bindings:
171171
action_to_bindings[binding.action].append((binding, enabled))
172172

173+
self.log(action_to_bindings)
174+
173175
self.styles.grid_size_columns = len(action_to_bindings)
174176
for multi_bindings in action_to_bindings.values():
175177
binding, enabled = multi_bindings[0]

0 commit comments

Comments
 (0)