From cd21f6326ed0c40f2b741f45ce579e71910400ac Mon Sep 17 00:00:00 2001 From: Jimmy Date: Mon, 4 Apr 2016 18:06:46 +1200 Subject: [PATCH] Save redirect links that are clicked on to history. This allows webkit to color links that are clicked on but never rendered as visited too. It also means if you get redirected from eg http://site.com to http://site.com/ you have essentially duplicates in your history. This makes the history completion a bit noisier. I suppose normalising paths before checking for duplicates might help. Also note that otter has an isTypedIn flag which might be used for dealing with this. --- qutebrowser/browser/webview.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/webview.py b/qutebrowser/browser/webview.py index 2512160e3..b05fc84ea 100644 --- a/qutebrowser/browser/webview.py +++ b/qutebrowser/browser/webview.py @@ -119,6 +119,7 @@ class WebView(QWebView): self.destroyed.connect(functools.partial( cfg.changed.disconnect, self.init_neighborlist)) self.cur_url = QUrl() + self._orig_url = QUrl() self.progress = 0 self.registry = objreg.ObjectRegistry() self.tab_id = next(tab_id_gen) @@ -148,8 +149,13 @@ class WebView(QWebView): @pyqtSlot() def on_initial_layout_completed(self): """Add url to history now that we have displayed something.""" - objreg.get('web-history').add_url( - self.url().toDisplayString(), self.title()) + history = objreg.get('web-history') + if not self._orig_url.matches(self.cur_url, + QUrl.UrlFormattingOption(0)): + # If the url of the page is different than the url of the link + # originally clicked, save them both. + history.add_url(self._orig_url.toDisplayString()) + history.add_url(self.cur_url.toDisplayString(), self.title()) def _init_page(self): """Initialize the QWebPage used by this view.""" @@ -190,6 +196,8 @@ class WebView(QWebView): log.webview.debug("load status for {}: {}".format(repr(self), val)) self.load_status = val self.load_status_changed.emit(val.name) + if val == LoadStatus.loading: + self._orig_url = self.cur_url def _set_bg_color(self): """Set the webpage background color as configured."""