When using --keep-focus ensure active history list is not affected
Fixes #4987
This commit is contained in:
parent
b569c01b49
commit
c4c62c1505
@ -380,14 +380,14 @@ class Boss:
|
||||
if q:
|
||||
yield q
|
||||
|
||||
def set_active_window(self, window: Window, switch_os_window_if_needed: bool = False) -> Optional[int]:
|
||||
def set_active_window(self, window: Window, switch_os_window_if_needed: bool = False, for_keep_focus: bool = False) -> Optional[int]:
|
||||
for os_window_id, tm in self.os_window_map.items():
|
||||
for tab in tm:
|
||||
for w in tab:
|
||||
if w.id == window.id:
|
||||
if tab is not self.active_tab:
|
||||
tm.set_active_tab(tab)
|
||||
tab.set_active_window(w)
|
||||
tm.set_active_tab(tab, for_keep_focus=window.tabref() if for_keep_focus else None)
|
||||
tab.set_active_window(w, for_keep_focus=window if for_keep_focus else None)
|
||||
if switch_os_window_if_needed and current_os_window() != os_window_id:
|
||||
focus_os_window(os_window_id, True)
|
||||
return os_window_id
|
||||
|
||||
@ -476,7 +476,7 @@ def launch(
|
||||
if opts.color:
|
||||
apply_colors(new_window, opts.color)
|
||||
if opts.keep_focus and active:
|
||||
boss.set_active_window(active, switch_os_window_if_needed=True)
|
||||
boss.set_active_window(active, switch_os_window_if_needed=True, for_keep_focus=True)
|
||||
if opts.logo:
|
||||
new_window.set_logo(opts.logo, opts.logo_position or '', opts.logo_alpha)
|
||||
return new_window
|
||||
|
||||
@ -504,8 +504,8 @@ class Tab: # {{{
|
||||
attach_window(self.os_window_id, self.id, window.id)
|
||||
self._add_window(window)
|
||||
|
||||
def set_active_window(self, x: Union[Window, int]) -> None:
|
||||
self.windows.set_active_window_group_for(x)
|
||||
def set_active_window(self, x: Union[Window, int], for_keep_focus: Optional[Window] = None) -> None:
|
||||
self.windows.set_active_window_group_for(x, for_keep_focus=for_keep_focus)
|
||||
|
||||
def get_nth_window(self, n: int) -> Optional[Window]:
|
||||
if self.windows:
|
||||
@ -865,12 +865,16 @@ class TabManager: # {{{
|
||||
tab.relayout_borders()
|
||||
self.mark_tab_bar_dirty()
|
||||
|
||||
def set_active_tab(self, tab: Tab) -> bool:
|
||||
def set_active_tab(self, tab: Tab, for_keep_focus: Optional[Tab] = None) -> bool:
|
||||
try:
|
||||
idx = self.tabs.index(tab)
|
||||
except Exception:
|
||||
return False
|
||||
self.set_active_tab_idx(idx)
|
||||
h = self.active_tab_history
|
||||
if for_keep_focus and len(h) > 2 and h[-2] == for_keep_focus.id and h[-1] != for_keep_focus.id:
|
||||
h.pop()
|
||||
h.pop()
|
||||
return True
|
||||
|
||||
def next_tab(self, delta: int = 1) -> None:
|
||||
|
||||
@ -303,7 +303,7 @@ class WindowList:
|
||||
return self.id_map[self.groups[self.active_group_idx].base_window_id]
|
||||
return None
|
||||
|
||||
def set_active_window_group_for(self, x: WindowOrId) -> None:
|
||||
def set_active_window_group_for(self, x: WindowOrId, for_keep_focus: Optional[WindowType] = None) -> None:
|
||||
try:
|
||||
q = self.id_map[x] if isinstance(x, int) else x
|
||||
except KeyError:
|
||||
@ -311,6 +311,10 @@ class WindowList:
|
||||
for i, group in enumerate(self.groups):
|
||||
if q in group:
|
||||
self.set_active_group_idx(i)
|
||||
h = self.active_group_history
|
||||
if for_keep_focus and len(h) > 2 and h[-2] == for_keep_focus.id and h[-1] != for_keep_focus.id:
|
||||
h.pop()
|
||||
h.pop()
|
||||
break
|
||||
|
||||
def add_window(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user