feat(tab-bar): add clickable close buttons to tabs
Tabs could only be closed with the keyboard or the middle mouse button, which is not discoverable. Draw a small cross at the start of each horizontal tab, close the tab when it is clicked, and avoid starting a drag from the button.
This commit is contained in:
3 files changed
+64
-6
No files matched your search
+26
-5
@@ -677,17 +677,38 @@ class TestTabBar(BaseTest):
|
||||
def horizontal_tab_bar_line(self, titles: list[str], columns: int, boss: object | None = None, **opts: object) -> str:
|
||||
return str(self.horizontal_tab_bar(titles, columns, boss, **opts).screen.line(0)).rstrip()
|
||||
|
||||
def test_horizontal_tab_bar_close_buttons(self) -> None:
|
||||
tb = self.horizontal_tab_bar(['one', 'two'], 40, tab_bar_style='separator')
|
||||
line = str(tb.screen.line(0))
|
||||
self.ae(line.count('×'), 2)
|
||||
# each close button is two cells wide, at the start of its tab
|
||||
self.ae(set(tb.close_button_cells.values()), {1, 2})
|
||||
for (cell_x, row), tab_id in tb.close_button_cells.items():
|
||||
px = tb.window_geometry.left + cell_x * tb.cell_width + 1
|
||||
py = tb.window_geometry.top + row * tb.cell_height + 1
|
||||
self.ae(tb.close_tab_id_at(px, py), tab_id)
|
||||
# clicking the title itself does not close the tab
|
||||
for te in tb.tab_extents:
|
||||
px = tb.window_geometry.left + te.x.end * tb.cell_width
|
||||
py = tb.window_geometry.top + 1
|
||||
self.ae(tb.close_tab_id_at(px, py), 0)
|
||||
self.ae(tb.close_tab_id_at(0, 0), 0)
|
||||
|
||||
# vertical tab bars keep closing with the middle mouse button
|
||||
self.ae(self.vertical_tab_bar().close_button_cells, {})
|
||||
|
||||
def test_horizontal_tab_bar_uses_free_space(self) -> None:
|
||||
line = self.horizontal_tab_bar_line
|
||||
# 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'
|
||||
# two extra cells per tab are needed for its close button
|
||||
for style, columns, titles in (
|
||||
('fade', 25, ['1', long_title]),
|
||||
('fade', 35, ['1'] * 2 + [long_title]),
|
||||
('separator', 60, ['1'] * 8 + [long_title] * 2),
|
||||
('powerline', 80, ['1'] * 5 + [long_title] * 3),
|
||||
('slant', 126, ['1'] * 9 + [long_title] * 4),
|
||||
('fade', 29, ['1', long_title]),
|
||||
('fade', 41, ['1'] * 2 + [long_title]),
|
||||
('separator', 80, ['1'] * 8 + [long_title] * 2),
|
||||
('powerline', 96, ['1'] * 5 + [long_title] * 3),
|
||||
('slant', 152, ['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))
|
||||
|
||||
Reference in new issue
Block a user