mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-20 15:12:37 +00:00
Merge branch 'pr-10640'
This commit is contained in:
commit
7eb0e1877a
3 changed files with 68 additions and 10 deletions
|
|
@ -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 (:pull:`10640`)
|
||||
|
||||
|
||||
0.49.2 [2026-10-01]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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'), '')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue