Skip to content

Commit d15cfa0

Browse files
authored
Merge pull request #4543 from Textualize/multi-keys
fix multi keys
2 parents c3e0010 + f179f10 commit d15cfa0

File tree

5 files changed

+191
-1
lines changed

5 files changed

+191
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [0.63.1] - 2024-05-22
9+
10+
### Fixed
11+
12+
- Fixed display of multiple bindings https://github.com/Textualize/textual/pull/4543
13+
814
## [0.63.0] - 2024-05-22
915

1016
### Fixed

src/textual/widgets/_footer.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from __future__ import annotations
22

3+
from collections import defaultdict
4+
35
import rich.repr
46
from rich.text import Text
57

68
from ..app import ComposeResult
9+
from ..binding import Binding
710
from ..containers import ScrollableContainer
811
from ..reactive import reactive
912
from ..widget import Widget
@@ -132,8 +135,15 @@ def compose(self) -> ComposeResult:
132135
for (_, binding, enabled) in self.screen.active_bindings.values()
133136
if binding.show
134137
]
135-
self.styles.grid_size_columns = len(bindings)
138+
action_to_bindings: defaultdict[str, list[tuple[Binding, bool]]] = defaultdict(
139+
list
140+
)
136141
for binding, enabled in bindings:
142+
action_to_bindings[binding.action].append((binding, enabled))
143+
144+
self.styles.grid_size_columns = len(bindings)
145+
for multi_bindings in action_to_bindings.values():
146+
binding, enabled = multi_bindings[0]
137147
yield FooterKey(
138148
binding.key,
139149
binding.key_display or self.app.get_key_display(binding.key),

tests/snapshot_tests/__snapshots__/test_snapshots.ambr

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27047,6 +27047,164 @@
2704727047

2704827048
'''
2704927049
# ---
27050+
# name: test_multi_keys
27051+
'''
27052+
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
27053+
<!-- Generated with Rich https://www.textualize.io -->
27054+
<style>
27055+
27056+
@font-face {
27057+
font-family: "Fira Code";
27058+
src: local("FiraCode-Regular"),
27059+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
27060+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
27061+
font-style: normal;
27062+
font-weight: 400;
27063+
}
27064+
@font-face {
27065+
font-family: "Fira Code";
27066+
src: local("FiraCode-Bold"),
27067+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
27068+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
27069+
font-style: bold;
27070+
font-weight: 700;
27071+
}
27072+
27073+
.terminal-1053129485-matrix {
27074+
font-family: Fira Code, monospace;
27075+
font-size: 20px;
27076+
line-height: 24.4px;
27077+
font-variant-east-asian: full-width;
27078+
}
27079+
27080+
.terminal-1053129485-title {
27081+
font-size: 18px;
27082+
font-weight: bold;
27083+
font-family: arial;
27084+
}
27085+
27086+
.terminal-1053129485-r1 { fill: #e1e1e1 }
27087+
.terminal-1053129485-r2 { fill: #c5c8c6 }
27088+
.terminal-1053129485-r3 { fill: #fea62b;font-weight: bold }
27089+
.terminal-1053129485-r4 { fill: #a7a9ab }
27090+
.terminal-1053129485-r5 { fill: #e2e3e3 }
27091+
</style>
27092+
27093+
<defs>
27094+
<clipPath id="terminal-1053129485-clip-terminal">
27095+
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
27096+
</clipPath>
27097+
<clipPath id="terminal-1053129485-line-0">
27098+
<rect x="0" y="1.5" width="976" height="24.65"/>
27099+
</clipPath>
27100+
<clipPath id="terminal-1053129485-line-1">
27101+
<rect x="0" y="25.9" width="976" height="24.65"/>
27102+
</clipPath>
27103+
<clipPath id="terminal-1053129485-line-2">
27104+
<rect x="0" y="50.3" width="976" height="24.65"/>
27105+
</clipPath>
27106+
<clipPath id="terminal-1053129485-line-3">
27107+
<rect x="0" y="74.7" width="976" height="24.65"/>
27108+
</clipPath>
27109+
<clipPath id="terminal-1053129485-line-4">
27110+
<rect x="0" y="99.1" width="976" height="24.65"/>
27111+
</clipPath>
27112+
<clipPath id="terminal-1053129485-line-5">
27113+
<rect x="0" y="123.5" width="976" height="24.65"/>
27114+
</clipPath>
27115+
<clipPath id="terminal-1053129485-line-6">
27116+
<rect x="0" y="147.9" width="976" height="24.65"/>
27117+
</clipPath>
27118+
<clipPath id="terminal-1053129485-line-7">
27119+
<rect x="0" y="172.3" width="976" height="24.65"/>
27120+
</clipPath>
27121+
<clipPath id="terminal-1053129485-line-8">
27122+
<rect x="0" y="196.7" width="976" height="24.65"/>
27123+
</clipPath>
27124+
<clipPath id="terminal-1053129485-line-9">
27125+
<rect x="0" y="221.1" width="976" height="24.65"/>
27126+
</clipPath>
27127+
<clipPath id="terminal-1053129485-line-10">
27128+
<rect x="0" y="245.5" width="976" height="24.65"/>
27129+
</clipPath>
27130+
<clipPath id="terminal-1053129485-line-11">
27131+
<rect x="0" y="269.9" width="976" height="24.65"/>
27132+
</clipPath>
27133+
<clipPath id="terminal-1053129485-line-12">
27134+
<rect x="0" y="294.3" width="976" height="24.65"/>
27135+
</clipPath>
27136+
<clipPath id="terminal-1053129485-line-13">
27137+
<rect x="0" y="318.7" width="976" height="24.65"/>
27138+
</clipPath>
27139+
<clipPath id="terminal-1053129485-line-14">
27140+
<rect x="0" y="343.1" width="976" height="24.65"/>
27141+
</clipPath>
27142+
<clipPath id="terminal-1053129485-line-15">
27143+
<rect x="0" y="367.5" width="976" height="24.65"/>
27144+
</clipPath>
27145+
<clipPath id="terminal-1053129485-line-16">
27146+
<rect x="0" y="391.9" width="976" height="24.65"/>
27147+
</clipPath>
27148+
<clipPath id="terminal-1053129485-line-17">
27149+
<rect x="0" y="416.3" width="976" height="24.65"/>
27150+
</clipPath>
27151+
<clipPath id="terminal-1053129485-line-18">
27152+
<rect x="0" y="440.7" width="976" height="24.65"/>
27153+
</clipPath>
27154+
<clipPath id="terminal-1053129485-line-19">
27155+
<rect x="0" y="465.1" width="976" height="24.65"/>
27156+
</clipPath>
27157+
<clipPath id="terminal-1053129485-line-20">
27158+
<rect x="0" y="489.5" width="976" height="24.65"/>
27159+
</clipPath>
27160+
<clipPath id="terminal-1053129485-line-21">
27161+
<rect x="0" y="513.9" width="976" height="24.65"/>
27162+
</clipPath>
27163+
<clipPath id="terminal-1053129485-line-22">
27164+
<rect x="0" y="538.3" width="976" height="24.65"/>
27165+
</clipPath>
27166+
</defs>
27167+
27168+
<rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="992" height="633.6" rx="8"/><text class="terminal-1053129485-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">MApp</text>
27169+
<g transform="translate(26,22)">
27170+
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
27171+
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
27172+
<circle cx="44" cy="0" r="7" fill="#28c840"/>
27173+
</g>
27174+
27175+
<g transform="translate(9, 41)" clip-path="url(#terminal-1053129485-clip-terminal)">
27176+
<rect fill="#1e1e1e" x="0" y="1.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="25.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="50.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="74.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="99.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="123.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="147.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="172.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="196.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="221.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="245.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="269.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="294.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="318.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="343.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="367.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="391.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="416.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="440.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="465.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="489.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="513.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="538.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="0" y="562.7" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="36.6" y="562.7" width="85.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="122" y="562.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="134.2" y="562.7" width="841.8" height="24.65" shape-rendering="crispEdges"/>
27177+
<g class="terminal-1053129485-matrix">
27178+
<text class="terminal-1053129485-r2" x="976" y="20" textLength="12.2" clip-path="url(#terminal-1053129485-line-0)">
27179+
</text><text class="terminal-1053129485-r2" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-1053129485-line-1)">
27180+
</text><text class="terminal-1053129485-r2" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-1053129485-line-2)">
27181+
</text><text class="terminal-1053129485-r2" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-1053129485-line-3)">
27182+
</text><text class="terminal-1053129485-r2" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-1053129485-line-4)">
27183+
</text><text class="terminal-1053129485-r2" x="976" y="142" textLength="12.2" clip-path="url(#terminal-1053129485-line-5)">
27184+
</text><text class="terminal-1053129485-r2" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-1053129485-line-6)">
27185+
</text><text class="terminal-1053129485-r2" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-1053129485-line-7)">
27186+
</text><text class="terminal-1053129485-r2" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-1053129485-line-8)">
27187+
</text><text class="terminal-1053129485-r2" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-1053129485-line-9)">
27188+
</text><text class="terminal-1053129485-r2" x="976" y="264" textLength="12.2" clip-path="url(#terminal-1053129485-line-10)">
27189+
</text><text class="terminal-1053129485-r2" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-1053129485-line-11)">
27190+
</text><text class="terminal-1053129485-r2" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-1053129485-line-12)">
27191+
</text><text class="terminal-1053129485-r2" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-1053129485-line-13)">
27192+
</text><text class="terminal-1053129485-r2" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-1053129485-line-14)">
27193+
</text><text class="terminal-1053129485-r2" x="976" y="386" textLength="12.2" clip-path="url(#terminal-1053129485-line-15)">
27194+
</text><text class="terminal-1053129485-r2" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-1053129485-line-16)">
27195+
</text><text class="terminal-1053129485-r2" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-1053129485-line-17)">
27196+
</text><text class="terminal-1053129485-r2" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-1053129485-line-18)">
27197+
</text><text class="terminal-1053129485-r2" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-1053129485-line-19)">
27198+
</text><text class="terminal-1053129485-r2" x="976" y="508" textLength="12.2" clip-path="url(#terminal-1053129485-line-20)">
27199+
</text><text class="terminal-1053129485-r2" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-1053129485-line-21)">
27200+
</text><text class="terminal-1053129485-r2" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-1053129485-line-22)">
27201+
</text><text class="terminal-1053129485-r3" x="0" y="581.2" textLength="36.6" clip-path="url(#terminal-1053129485-line-23)">&#160;o&#160;</text><text class="terminal-1053129485-r4" x="36.6" y="581.2" textLength="85.4" clip-path="url(#terminal-1053129485-line-23)">Options</text>
27202+
</g>
27203+
</g>
27204+
</svg>
27205+
27206+
'''
27207+
# ---
2705027208
# name: test_multiple_css
2705127209
'''
2705227210
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from textual.app import App, ComposeResult
2+
from textual.binding import Binding
3+
from textual.widgets import Footer
4+
5+
class MApp(App):
6+
BINDINGS = [Binding("o,ctrl+o", "options", "Options")]
7+
def compose(self) -> ComposeResult:
8+
yield Footer()
9+
10+
if __name__ == "__main__":
11+
MApp().run()

tests/snapshot_tests/test_snapshots.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,3 +1264,8 @@ def test_dynamic_bindings(snap_compare):
12641264
def test_grid_gutter(snap_compare):
12651265
# https://github.com/Textualize/textual/issues/4522
12661266
assert snap_compare(SNAPSHOT_APPS_DIR / "grid_gutter.py")
1267+
1268+
1269+
def test_multi_keys(snap_compare):
1270+
# https://github.com/Textualize/textual/issues/4542
1271+
assert snap_compare(SNAPSHOT_APPS_DIR / "multi_keys.py")

0 commit comments

Comments
 (0)