Merge branch 'add_option_to_not_switch_to_previous_when_closing_current_tab' of https://github.com/ddddavidmartin/kitty

This commit is contained in:
Kovid Goyal 2019-04-03 14:23:14 +05:30
commit c9644039b1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 27 additions and 8 deletions

View File

@ -28,6 +28,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Allow setting OS window size in session files
- Add an option :opt:`tab_switch_strategy` to control which
tab becomes active when the current tab is closed (:pull:`1524`)
- Allow specifying a value of ``none`` for the :opt:`selection_foreground`
which will cause kitty to not change text color in selections (:iss:`1358`)

View File

@ -631,6 +631,13 @@ o('tab_bar_min_tabs', 2, option_type=lambda x: max(1, positive_int(x)), long_tex
The minimum number of tabs that must exist before the tab bar is shown
'''))
o('tab_switch_strategy', 'previous', option_type=choices('previous', 'left', 'last'), long_text=_('''
The algorithm to use when switching to a tab when the current tab is closed.
The default of :code:`previous` will switch to the last used tab. A value of
:code:`left` will switch to the tab to the left of the closed tab. A value
of :code:`last` will switch to the right-most tab.
'''))
def tab_fade(x):
return tuple(map(unit_float, x.split()))

View File

@ -552,16 +552,25 @@ class TabManager: # {{{
def remove(self, tab):
self._remove_tab(tab)
next_active_tab = -1
while self.active_tab_history and next_active_tab < 0:
tab_id = self.active_tab_history.pop()
if tab_id == tab.id:
continue
for idx, qtab in enumerate(self.tabs):
if qtab.id == tab_id:
next_active_tab = idx
break
while True:
try:
self.active_tab_history.remove(tab.id)
except ValueError:
break
if self.opts.tab_switch_strategy == 'previous':
while self.active_tab_history and next_active_tab < 0:
tab_id = self.active_tab_history.pop()
for idx, qtab in enumerate(self.tabs):
if qtab.id == tab_id:
next_active_tab = idx
break
elif self.opts.tab_switch_strategy == 'left':
next_active_tab = max(0, self.active_tab_idx - 1)
if next_active_tab < 0:
next_active_tab = max(0, min(self.active_tab_idx, len(self.tabs) - 1))
self._set_active_tab(next_active_tab)
self.mark_tab_bar_dirty()
tab.destroy()