diff --git a/docs/changelog.rst b/docs/changelog.rst index 125e94785..991f6906f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -125,6 +125,8 @@ Detailed list of changes 0.50.1 [unreleased] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- Vertical tab bar: Fix clicking the blank line below a tab not activating the tab (:iss:`10810`) + - :doc:`Custom shaders `: Add ``screen-shake`` and ``screen-shake-random`` shaders that shake the window in which a bell occurs, for example, to shake the window when a shell command fails diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 214c8b209..fdb82a5a1 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -811,6 +811,8 @@ class TabBar: self.data_buffer_size = 0 self.blank_rects: tuple[Border, ...] = () self.tab_extents: Sequence[TabExtent] = () + # Number of blank lines left after each tab in a vertical tab bar + self.vertical_tab_spacing = 0 self.window_drop_insert_before: int | None = None self.tab_drop_insert_before: int | None = None self.laid_out_once = False @@ -1164,6 +1166,7 @@ class TabBar: s = self.screen self.last_laid_out_tabs = data self.tab_extents = () + self.vertical_tab_spacing = 0 s.cursor.x = s.cursor.y = 0 s.erase_in_display(2, False) if not data: @@ -1255,6 +1258,7 @@ class TabBar: s.cursor.fg = as_rgb(0xFF0000) s.draw('…') self.tab_extents = tuple(cr) + self.vertical_tab_spacing = spacing self.draw_drop_insert_marker() return self._update_edge_defaults(True) @@ -1310,6 +1314,12 @@ class TabBar: for te in self.tab_extents: if te.contains(x, y): return te.tab_id + if self.is_vertical and self.vertical_tab_spacing: + # The blank line after a tab belongs to it, so that clicking + # just below a tab's title still activates the tab. + for te in self.tab_extents: + if te.tab_id > 0 and te.x.start <= x <= te.x.end and te.y.end < y <= te.y.end + self.vertical_tab_spacing: + return te.tab_id return 0 def drag_axis_coordinate(self, x: int, y: int) -> int: diff --git a/kitty_tests/tab_bar.py b/kitty_tests/tab_bar.py index d02725cda..e6bf5f9e5 100644 --- a/kitty_tests/tab_bar.py +++ b/kitty_tests/tab_bar.py @@ -285,18 +285,35 @@ class TestTabBar(BaseTest): def test_vertical_tab_bar_tab_spacing(self) -> None: # a blank line is left between tabs while there is room for it, but not - # above the first tab, and the gaps are not part of any tab's extent so - # clicking one activates nothing + # above the first tab. The gaps are not part of any tab's drawn extent, + # but for clicks the gap after a tab belongs to that tab. tb = self.vertical_tab_bar(num_tabs=3) self.ae(self.screen_lines(tb)[:6], ['t0', '', 't1', '', 't2', '']) self.ae(tuple(te.y for te in tb.tab_extents), (CellRange(0, 0), CellRange(2, 2), CellRange(4, 4))) self.ae(tb.tab_id_at(5, 10), 1) - self.ae(tb.tab_id_at(5, 30), 0) + self.ae(tb.tab_id_at(5, 30), 1) self.ae(tb.tab_id_at(5, 50), 2) + self.ae(tb.tab_id_at(5, 90), 3) + self.ae(tb.tab_id_at(5, 110), 3) + self.ae(tb.tab_id_at(5, 130), 0) # the gap uses the tab bar background, not the neighbouring tab's self.ae(int(tb.screen.line(1).cursor_from(0).bg), 0) + # the gap above the new tab button belongs to the tab above it, while + # the line below the button is empty tab bar space + tb = self.vertical_tab_bar(num_tabs=2) + with patch('kitty.tab_bar.update_tab_bar_edge_colors', return_value=None), patch('kitty.tab_bar.get_boss', return_value=DummyBoss()): + tb.update(tuple(tb.last_laid_out_tabs) + (TabBarData(title='+'),)) + self.ae(tuple(te.tab_id for te in tb.tab_extents)[:2], (1, 2)) + self.ae(tb.tab_id_at(5, 70), 2) + self.assertLess(tb.tab_id_at(5, 90), 0) + self.ae(tb.tab_id_at(5, 110), 0) + + # no gaps, no extra hit area + tb = self.vertical_tab_bar(num_tabs=8, height=160) + self.ae(tb.tab_id_at(5, 150), 8) + # spacing applies between multi-line tabs too tb = self.vertical_tab_bar(num_tabs=2, tab_title_max_lines=2, tab_title_template='{title}\\nbr') self.ae(self.screen_lines(tb)[:6], ['t0', 'br', '', 't1', 'br', ''])