Only update tab/window title on scroll if needed
This way, if {scroll_pos} is not in the window/tab title template, we don't redraw anything unnecessarily. See #2233
This commit is contained in:
parent
280dddda6b
commit
dd927ded6b
@ -173,8 +173,18 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
return widgets
|
return widgets
|
||||||
|
|
||||||
def _update_window_title(self):
|
def _update_window_title(self, field=None):
|
||||||
"""Change the window title to match the current tab."""
|
"""Change the window title to match the current tab.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
idx: The tab index to update.
|
||||||
|
field: A field name which was updated. If given, the title
|
||||||
|
is only set if the given field is in the template.
|
||||||
|
"""
|
||||||
|
title_format = config.val.window.title_format
|
||||||
|
if field is not None and ('{' + field + '}') not in title_format:
|
||||||
|
return
|
||||||
|
|
||||||
idx = self.currentIndex()
|
idx = self.currentIndex()
|
||||||
if idx == -1:
|
if idx == -1:
|
||||||
# (e.g. last tab removed)
|
# (e.g. last tab removed)
|
||||||
@ -183,7 +193,6 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
fields = self.get_tab_fields(idx)
|
fields = self.get_tab_fields(idx)
|
||||||
fields['id'] = self._win_id
|
fields['id'] = self._win_id
|
||||||
|
|
||||||
title_format = config.val.window.title_format
|
|
||||||
title = title_format.format(**fields)
|
title = title_format.format(**fields)
|
||||||
self.window().setWindowTitle(title)
|
self.window().setWindowTitle(title)
|
||||||
|
|
||||||
@ -696,8 +705,8 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
log.webview.debug("Not updating scroll position because index is "
|
log.webview.debug("Not updating scroll position because index is "
|
||||||
"-1")
|
"-1")
|
||||||
return
|
return
|
||||||
self._update_window_title()
|
self._update_window_title('scroll_pos')
|
||||||
self._update_tab_title(idx)
|
self._update_tab_title(idx, 'scroll_pos')
|
||||||
|
|
||||||
def _on_renderer_process_terminated(self, tab, status, code):
|
def _on_renderer_process_terminated(self, tab, status, code):
|
||||||
"""Show an error when a renderer process terminated."""
|
"""Show an error when a renderer process terminated."""
|
||||||
|
@ -121,21 +121,29 @@ class TabWidget(QTabWidget):
|
|||||||
"""Get the tab title user data."""
|
"""Get the tab title user data."""
|
||||||
return self.tabBar().page_title(idx)
|
return self.tabBar().page_title(idx)
|
||||||
|
|
||||||
def _update_tab_title(self, idx):
|
def _update_tab_title(self, idx, field=None):
|
||||||
"""Update the tab text for the given tab."""
|
"""Update the tab text for the given tab.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
idx: The tab index to update.
|
||||||
|
field: A field name which was updated. If given, the title
|
||||||
|
is only set if the given field is in the template.
|
||||||
|
"""
|
||||||
tab = self.widget(idx)
|
tab = self.widget(idx)
|
||||||
|
if tab.data.pinned:
|
||||||
|
fmt = config.val.tabs.title.format_pinned
|
||||||
|
else:
|
||||||
|
fmt = config.val.tabs.title.format
|
||||||
|
|
||||||
|
if (field is not None and
|
||||||
|
(fmt is None or ('{' + field + '}') not in fmt)):
|
||||||
|
return
|
||||||
|
|
||||||
fields = self.get_tab_fields(idx)
|
fields = self.get_tab_fields(idx)
|
||||||
fields['title'] = fields['title'].replace('&', '&&')
|
fields['title'] = fields['title'].replace('&', '&&')
|
||||||
fields['index'] = idx + 1
|
fields['index'] = idx + 1
|
||||||
|
|
||||||
fmt = config.val.tabs.title.format
|
title = '' if fmt is None else fmt.format(**fields)
|
||||||
fmt_pinned = config.val.tabs.title.format_pinned
|
|
||||||
|
|
||||||
if tab.data.pinned:
|
|
||||||
title = '' if fmt_pinned is None else fmt_pinned.format(**fields)
|
|
||||||
else:
|
|
||||||
title = '' if fmt is None else fmt.format(**fields)
|
|
||||||
|
|
||||||
self.tabBar().setTabText(idx, title)
|
self.tabBar().setTabText(idx, title)
|
||||||
|
|
||||||
def get_tab_fields(self, idx):
|
def get_tab_fields(self, idx):
|
||||||
|
Loading…
Reference in New Issue
Block a user