From 81bb260f8c19e23616340c6c2807c4b45784ff5e Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 13 Nov 2024 21:06:30 +0000 Subject: [PATCH 1/5] fix(tabs): update highlighting when tab removed --- src/textual/widgets/_tabs.py | 1 + tests/snapshot_tests/test_snapshots.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/textual/widgets/_tabs.py b/src/textual/widgets/_tabs.py index 94df1352a4..736e425b5c 100644 --- a/src/textual/widgets/_tabs.py +++ b/src/textual/widgets/_tabs.py @@ -561,6 +561,7 @@ async def do_remove() -> None: self.active = next_tab.id or "" if not self.query("#tabs-list > Tab"): self.active = "" + self._highlight_active(animate=False) return AwaitComplete(do_remove()) diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 41f4778747..aa75d2b491 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -30,6 +30,8 @@ SelectionList, Static, Switch, + Tab, + Tabs, TextArea, ) from textual.widgets.text_area import BUILTIN_LANGUAGES, Selection, TextAreaTheme @@ -2547,3 +2549,25 @@ async def run_before(pilot: Pilot): 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") From 16ccf07401eb9a84c5e41a496bee6fdde5fec608 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 13 Nov 2024 21:38:18 +0000 Subject: [PATCH 2/5] add snapshot --- ...t_tabs_remove_tab_updates_highlighting.svg | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/snapshot_tests/__snapshots__/test_snapshots/test_tabs_remove_tab_updates_highlighting.svg diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_tabs_remove_tab_updates_highlighting.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_tabs_remove_tab_updates_highlighting.svg new file mode 100644 index 0000000000..571a28f6f4 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_tabs_remove_tab_updates_highlighting.svg @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TabsApp + + + + + + + + + + bar +━╸━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + + + + + + + + + + + + + + + + + + + + r Remove foo                                                       ^p palette + + + From 300913bee988f46d61198d70b8039a6d6cfb6d3a Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 13 Nov 2024 21:50:19 +0000 Subject: [PATCH 3/5] call _highlight_active only if active unchanged --- src/textual/widgets/_tabs.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/textual/widgets/_tabs.py b/src/textual/widgets/_tabs.py index 736e425b5c..e73a37c654 100644 --- a/src/textual/widgets/_tabs.py +++ b/src/textual/widgets/_tabs.py @@ -557,11 +557,12 @@ def remove_tab(self, tab_or_id: Tab | str | None) -> AwaitComplete: 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 = "" - self._highlight_active(animate=False) + elif next_tab is not None: + self.active = next_tab.id or "" + else: + self._highlight_active(animate=False) return AwaitComplete(do_remove()) From 7db3e581d21d115b043ffdfadcaa7c659be6b557 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:09:55 +0000 Subject: [PATCH 4/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76279be25a..591e02d1f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fixed duplicated key displays in the help panel https://github.com/Textualize/textual/issues/5037 +- Fixed `Tabs` not updating the highlighting after removing a tab https://github.com/Textualize/textual/issues/5218 ### Added From 46a9fa0e680cfd58b646b76d319bf3e70a24c3c8 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Fri, 15 Nov 2024 17:44:50 +0000 Subject: [PATCH 5/5] update snapshot --- ...t_tabs_remove_tab_updates_highlighting.svg | 122 +++++++++--------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_tabs_remove_tab_updates_highlighting.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_tabs_remove_tab_updates_highlighting.svg index 571a28f6f4..918d739aca 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots/test_tabs_remove_tab_updates_highlighting.svg +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_tabs_remove_tab_updates_highlighting.svg @@ -19,137 +19,137 @@ font-weight: 700; } - .terminal-1887710738-matrix { + .terminal-3499157445-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-1887710738-title { + .terminal-3499157445-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-1887710738-r1 { fill: #e0e0e0 } -.terminal-1887710738-r2 { fill: #c5c8c6 } -.terminal-1887710738-r3 { fill: #ddedf9;font-weight: bold } -.terminal-1887710738-r4 { fill: #4f4f4f } -.terminal-1887710738-r5 { fill: #0178d4 } -.terminal-1887710738-r6 { fill: #ffa62b;font-weight: bold } -.terminal-1887710738-r7 { fill: #495259 } + .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 } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - TabsApp + TabsApp - - - - bar -━╸━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - - - - - - - - - - - - - - - - - - - - - r Remove foo                                                       ^p palette + + + + bar +━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + + + + + + + + + + + + + + + + + + + + r Remove foo                                                       ^p palette