From 094b1a66a5ba2f8f911b8a3afb9fa79216a88d6a Mon Sep 17 00:00:00 2001 From: Alistair Pattison Date: Fri, 9 Oct 2026 17:44:31 -0400 Subject: [PATCH 1/2] use all free space in the tab bar for truncated tab titles --- docs/changelog.rst | 3 +++ kitty/tab_bar.py | 33 +++++++++++++++++++++++---------- kitty_tests/tab_bar.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5dc53dc9d..e80c55a3b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -379,6 +379,9 @@ Detailed list of changes - Speed up growing the GPU sprite cache, particularly on macOS (:pull:`10632`) +- Tab bar: Fix long tab titles being truncated while there is still unused + space at the end of the tab bar + 0.49.2 [2026-10-01] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 6ed914863..04528d6b8 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -1032,8 +1032,8 @@ class TabBar: ideal_tab_lengths = [i for i in range(len(data))] default_max_tab_length = max(1, (s.columns // max(1, len(data))) - 1) max_tab_lengths = [default_max_tab_length for _ in range(len(data))] + overhangs = [0 for _ in range(len(data))] active_idx = 0 - extra = 0 ed.for_layout = True for i, t in enumerate(data): s.cursor.x = 0 @@ -1043,19 +1043,32 @@ class TabBar: active_idx = i if tl < default_max_tab_length: max_tab_lengths[i] = tl - extra += default_max_tab_length - tl - if extra > 0: + elif tl > default_max_tab_length: + # A truncated tab can be drawn wider than its max length, for + # example by a separator after the title, so measure by how + # much. Only the first tab starts at column zero, where the + # powerline style draws an extra space. + s.cursor.x = start = min(i, 1) + draw_tab(i, t, [], default_max_tab_length) + overhangs[i] = max(0, s.cursor.x - start - default_max_tab_length) + + def space_left() -> int: + return s.columns - sum(min(tl, ml + oh) for tl, ml, oh in zip(ideal_tab_lengths, max_tab_lengths, overhangs)) + + extra = space_left() + if data and extra > 0: if ideal_tab_lengths[active_idx] > max_tab_lengths[active_idx]: d = min(extra, ideal_tab_lengths[active_idx] - max_tab_lengths[active_idx]) max_tab_lengths[active_idx] += d - extra -= d - if extra > 0: + # Hand out the remaining space evenly, repeating as a tab may need + # less than its share, leaving more for the others + while (extra := space_left()) > 0: over_achievers = tuple(i for i in range(len(data)) if ideal_tab_lengths[i] > max_tab_lengths[i]) - if over_achievers: - amt_per_over_achiever = extra // len(over_achievers) - if amt_per_over_achiever > 0: - for i in over_achievers: - max_tab_lengths[i] += amt_per_over_achiever + if not over_achievers: + break + amt, rem = divmod(extra, len(over_achievers)) + for n, i in enumerate(over_achievers): + max_tab_lengths[i] = min(ideal_tab_lengths[i], max_tab_lengths[i] + amt + (n < rem)) s.cursor.x = 0 s.erase_in_line(2, False) diff --git a/kitty_tests/tab_bar.py b/kitty_tests/tab_bar.py index a4dda2fa4..09d34e56e 100644 --- a/kitty_tests/tab_bar.py +++ b/kitty_tests/tab_bar.py @@ -592,3 +592,45 @@ class TestTabBar(BaseTest): lines(tab_title_max_lines=3, tab_title_wrap=0, tab_title_template='{title}\\nabcdefghijklmnop\\nx'), [f' t0 {separator}', f'abcdefghijk{separator}', f'x {separator}'], ) + + def test_horizontal_tab_bar_uses_free_space(self) -> None: + def line(titles: list[str], columns: int, **opts: str) -> str: + self.set_options({'tab_title_template': '{title}', **opts}) + central = region(0, 0, columns * 10, 180) + tab_bar = region(0, 180, columns * 10, 200) + with ( + patch('kitty.tab_bar.cell_size_for_window', return_value=(10, 20)), + patch('kitty.tab_bar.viewport_for_window', return_value=(central, tab_bar, columns * 10, 200, 10, 20)), + patch('kitty.tab_bar.set_tab_bar_render_data'), + patch('kitty.tab_bar.update_tab_bar_edge_colors', return_value=None), + patch('kitty.tab_bar.get_boss', return_value=DummyBoss()), + ): + tb = TabBar(1) + tb.layout() + tb.update(tuple(TabBarData(title=t, tab_id=i + 1, is_active=i == 0) for i, t in enumerate(titles))) + return str(tb.screen.line(0)).rstrip() + + # space not needed by short tabs goes to the long ones, instead of + # being left unused at the end of the tab bar + long_title = 'abcdefghijklmn' + for style, columns, titles in ( + ('separator', 60, ['1'] * 8 + [long_title] * 2), + ('powerline', 80, ['1'] * 5 + [long_title] * 3), + ('slant', 126, ['1'] * 9 + [long_title] * 4), + ): + text = line(titles, columns, tab_bar_style=style) + self.ae(text.count(long_title), titles.count(long_title), (style, text)) + self.assertNotIn('…', text) + + # tabs drawn more than one cell wider than their max length, by a wide + # separator or the leading space of the powerline style, must still + # fit, rather than the last one being replaced by the overflow marker + for columns, titles, opts in ( + (10, ['x' * 10] * 3, {'tab_bar_style': 'separator', 'tab_separator': ' ||'}), + (15, ['x' * 10, '~'], {'tab_bar_style': 'powerline'}), + ): + text = line(titles, columns, **opts) + self.assertFalse(text.endswith(' …'), (opts, text)) + + # no tabs + self.ae(line([], 60, tab_bar_style='separator'), '') From f82f4f437bf0e555373647b420f06736032de596 Mon Sep 17 00:00:00 2001 From: Alistair Pattison Date: Fri, 9 Oct 2026 20:12:55 -0400 Subject: [PATCH 2/2] add pr number to changelog entry --- docs/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index e80c55a3b..4a5a831cf 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -380,7 +380,7 @@ Detailed list of changes (:pull:`10632`) - Tab bar: Fix long tab titles being truncated while there is still unused - space at the end of the tab bar + space at the end of the tab bar (:pull:`10640`) 0.49.2 [2026-10-01]