mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #5233 from TomJGooding/fix-tabs-update-highlighting-when-tab-removed
fix(tabs): update highlighting when tab removed
This commit is contained in:
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
- Fixed duplicated key displays in the help panel https://github.com/Textualize/textual/issues/5037
|
||||
- Fixed `TextArea` mouse selection with tab characters https://github.com/Textualize/textual/issues/5212
|
||||
- Fixed `Tabs` not updating the highlighting after removing a tab https://github.com/Textualize/textual/issues/5218
|
||||
|
||||
### Added
|
||||
|
||||
|
||||
@@ -556,10 +556,12 @@ class Tabs(Widget, can_focus=True):
|
||||
async def do_remove() -> None:
|
||||
"""Perform the remove after refresh so the underline bar gets new positions."""
|
||||
await remove_tab.remove()
|
||||
if next_tab is not None:
|
||||
self.active = next_tab.id or ""
|
||||
if not self.query("#tabs-list > Tab"):
|
||||
self.active = ""
|
||||
elif next_tab is not None:
|
||||
self.active = next_tab.id or ""
|
||||
else:
|
||||
self._highlight_active(animate=False)
|
||||
|
||||
return AwaitComplete(do_remove())
|
||||
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
|
||||
<!-- Generated with Rich https://www.textualize.io -->
|
||||
<style>
|
||||
|
||||
@font-face {
|
||||
font-family: "Fira Code";
|
||||
src: local("FiraCode-Regular"),
|
||||
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
|
||||
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Fira Code";
|
||||
src: local("FiraCode-Bold"),
|
||||
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
|
||||
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
|
||||
font-style: bold;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.terminal-3499157445-matrix {
|
||||
font-family: Fira Code, monospace;
|
||||
font-size: 20px;
|
||||
line-height: 24.4px;
|
||||
font-variant-east-asian: full-width;
|
||||
}
|
||||
|
||||
.terminal-3499157445-title {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
font-family: arial;
|
||||
}
|
||||
|
||||
.terminal-3499157445-r1 { fill: #c5c8c6 }
|
||||
.terminal-3499157445-r2 { fill: #ddedf9;font-weight: bold }
|
||||
.terminal-3499157445-r3 { fill: #e0e0e0 }
|
||||
.terminal-3499157445-r4 { fill: #4f4f4f }
|
||||
.terminal-3499157445-r5 { fill: #0178d4 }
|
||||
.terminal-3499157445-r6 { fill: #ffa62b;font-weight: bold }
|
||||
.terminal-3499157445-r7 { fill: #495259 }
|
||||
</style>
|
||||
|
||||
<defs>
|
||||
<clipPath id="terminal-3499157445-clip-terminal">
|
||||
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-0">
|
||||
<rect x="0" y="1.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-1">
|
||||
<rect x="0" y="25.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-2">
|
||||
<rect x="0" y="50.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-3">
|
||||
<rect x="0" y="74.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-4">
|
||||
<rect x="0" y="99.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-5">
|
||||
<rect x="0" y="123.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-6">
|
||||
<rect x="0" y="147.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-7">
|
||||
<rect x="0" y="172.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-8">
|
||||
<rect x="0" y="196.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-9">
|
||||
<rect x="0" y="221.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-10">
|
||||
<rect x="0" y="245.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-11">
|
||||
<rect x="0" y="269.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-12">
|
||||
<rect x="0" y="294.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-13">
|
||||
<rect x="0" y="318.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-14">
|
||||
<rect x="0" y="343.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-15">
|
||||
<rect x="0" y="367.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-16">
|
||||
<rect x="0" y="391.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-17">
|
||||
<rect x="0" y="416.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-18">
|
||||
<rect x="0" y="440.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-19">
|
||||
<rect x="0" y="465.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-20">
|
||||
<rect x="0" y="489.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-21">
|
||||
<rect x="0" y="513.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-3499157445-line-22">
|
||||
<rect x="0" y="538.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
|
||||
<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-3499157445-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">TabsApp</text>
|
||||
<g transform="translate(26,22)">
|
||||
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
|
||||
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
|
||||
<circle cx="44" cy="0" r="7" fill="#28c840"/>
|
||||
</g>
|
||||
|
||||
<g transform="translate(9, 41)" clip-path="url(#terminal-3499157445-clip-terminal)">
|
||||
<rect fill="#0178d4" x="0" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#0178d4" x="12.2" y="1.5" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#0178d4" x="48.8" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="61" y="1.5" width="915" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="12.2" y="25.9" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="48.8" y="25.9" width="927.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="50.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="74.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="99.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="123.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="147.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="172.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="196.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="221.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="245.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="269.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="294.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="318.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="343.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="367.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="391.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="416.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="440.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="465.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="489.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="513.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="538.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="0" y="562.7" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="36.6" y="562.7" width="793" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="829.6" y="562.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="841.8" y="562.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="866.2" y="562.7" width="97.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="963.8" y="562.7" width="12.2" height="24.65" shape-rendering="crispEdges"/>
|
||||
<g class="terminal-3499157445-matrix">
|
||||
<text class="terminal-3499157445-r2" x="12.2" y="20" textLength="36.6" clip-path="url(#terminal-3499157445-line-0)">bar</text><text class="terminal-3499157445-r1" x="976" y="20" textLength="12.2" clip-path="url(#terminal-3499157445-line-0)">
|
||||
</text><text class="terminal-3499157445-r4" x="0" y="44.4" textLength="12.2" clip-path="url(#terminal-3499157445-line-1)">╸</text><text class="terminal-3499157445-r5" x="12.2" y="44.4" textLength="36.6" clip-path="url(#terminal-3499157445-line-1)">━━━</text><text class="terminal-3499157445-r4" x="48.8" y="44.4" textLength="927.2" clip-path="url(#terminal-3499157445-line-1)">╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</text><text class="terminal-3499157445-r1" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-3499157445-line-1)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-3499157445-line-2)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-3499157445-line-3)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-3499157445-line-4)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="142" textLength="12.2" clip-path="url(#terminal-3499157445-line-5)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-3499157445-line-6)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-3499157445-line-7)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-3499157445-line-8)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-3499157445-line-9)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="264" textLength="12.2" clip-path="url(#terminal-3499157445-line-10)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-3499157445-line-11)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-3499157445-line-12)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-3499157445-line-13)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-3499157445-line-14)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="386" textLength="12.2" clip-path="url(#terminal-3499157445-line-15)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-3499157445-line-16)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-3499157445-line-17)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-3499157445-line-18)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-3499157445-line-19)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="508" textLength="12.2" clip-path="url(#terminal-3499157445-line-20)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-3499157445-line-21)">
|
||||
</text><text class="terminal-3499157445-r1" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-3499157445-line-22)">
|
||||
</text><text class="terminal-3499157445-r6" x="0" y="581.2" textLength="36.6" clip-path="url(#terminal-3499157445-line-23)"> r </text><text class="terminal-3499157445-r3" x="36.6" y="581.2" textLength="793" clip-path="url(#terminal-3499157445-line-23)">Remove foo                                                       </text><text class="terminal-3499157445-r7" x="829.6" y="581.2" textLength="12.2" clip-path="url(#terminal-3499157445-line-23)">▏</text><text class="terminal-3499157445-r6" x="841.8" y="581.2" textLength="24.4" clip-path="url(#terminal-3499157445-line-23)">^p</text><text class="terminal-3499157445-r3" x="866.2" y="581.2" textLength="97.6" clip-path="url(#terminal-3499157445-line-23)"> palette</text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 13 KiB |
@@ -30,6 +30,8 @@ from textual.widgets import (
|
||||
SelectionList,
|
||||
Static,
|
||||
Switch,
|
||||
Tab,
|
||||
Tabs,
|
||||
TextArea,
|
||||
)
|
||||
from textual.widgets.text_area import BUILTIN_LANGUAGES, Selection, TextAreaTheme
|
||||
@@ -2547,3 +2549,25 @@ def test_help_panel_key_display_not_duplicated(snap_compare):
|
||||
|
||||
app = HelpPanelApp()
|
||||
assert snap_compare(app, run_before=run_before)
|
||||
|
||||
|
||||
def test_tabs_remove_tab_updates_highlighting(snap_compare):
|
||||
"""Regression test for https://github.com/Textualize/textual/issues/5218"""
|
||||
|
||||
class TabsApp(App):
|
||||
BINDINGS = [("r", "remove_foo", "Remove foo")]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Tabs(
|
||||
Tab("foo", id="foo"),
|
||||
Tab("bar", id="bar"),
|
||||
active="bar",
|
||||
)
|
||||
yield Footer()
|
||||
|
||||
def action_remove_foo(self) -> None:
|
||||
tabs = self.query_one(Tabs)
|
||||
tabs.remove_tab("foo")
|
||||
|
||||
app = TabsApp()
|
||||
assert snap_compare(app, press="r")
|
||||
|
||||
Reference in New Issue
Block a user