diff --git a/qutebrowser/browser/history.py b/qutebrowser/browser/history.py index 1fc48d894..bdc9a5334 100644 --- a/qutebrowser/browser/history.py +++ b/qutebrowser/browser/history.py @@ -38,23 +38,26 @@ class Entry: Attributes: atime: The time the page was accessed. url: The URL which was accessed as QUrl. - hidden: If True, don't save this entry to disk + redirect: If True, don't save this entry to disk """ - def __init__(self, atime, url, title, hidden=False): + def __init__(self, atime, url, title, redirect=False): self.atime = float(atime) self.url = url self.title = title - self.hidden = hidden + self.redirect = redirect qtutils.ensure_valid(url) def __repr__(self): return utils.get_repr(self, constructor=True, atime=self.atime, url=self.url_str(), title=self.title, - hidden=self.hidden) + redirect=self.redirect) def __str__(self): - elems = [str(int(self.atime)), self.url_str()] + atime = str(int(self.atime)) + if self.redirect: + atime += '-r' # redirect flag + elems = [atime, self.url_str()] if self.title: elems.append(self.title) return ' '.join(elems) @@ -63,7 +66,7 @@ class Entry: return (self.atime == other.atime and self.title == other.title and self.url == other.url and - self.hidden == other.hidden) + self.redirect == other.redirect) def url_str(self): """Get the URL as a lossless string.""" @@ -91,7 +94,18 @@ class Entry: "https://github.com/The-Compiler/qutebrowser/issues/" "670".format(data)) atime = atime.lstrip('\0') - return cls(atime, url, title) + + if '-' in atime: + atime, flags = atime.split('-') + else: + flags = '' + + if not set(flags).issubset('r'): + raise ValueError("Invalid flags {!r}".format(flags)) + + redirect = 'r' in flags + + return cls(atime, url, title, redirect=redirect) class WebHistoryInterface(QWebHistoryInterface): @@ -230,8 +244,8 @@ class WebHistory(QObject): for entry in self._temp_history.values(): self._add_entry(entry) - if not entry.hidden: - self._new_history.append(entry) + self._new_history.append(entry) + if not entry.redirect: self.add_completion_item.emit(entry) self._temp_history.clear() @@ -270,25 +284,26 @@ class WebHistory(QObject): self._saved_count = 0 self.cleared.emit() - def add_url(self, url, title="", *, hidden=False, atime=None): + def add_url(self, url, title="", *, redirect=False, atime=None): """Called by WebKit when an URL should be added to the history. Args: url: An url (as QUrl) to add to the history. - hidden: Whether to hide the entry from the on-disk history + redirect: Whether the entry was redirected to another URL + (hidden in completion) atime: Override the atime used to add the entry """ if config.get('general', 'private-browsing'): return if atime is None: atime = time.time() - entry = Entry(atime, url, title, hidden=hidden) + entry = Entry(atime, url, title, redirect=redirect) if self._initial_read_done: self._add_entry(entry) - if not entry.hidden: + self._new_history.append(entry) + self.item_added.emit(entry) + if not entry.redirect: self.add_completion_item.emit(entry) - self._new_history.append(entry) - self.item_added.emit(entry) else: self._add_entry(entry, target=self._temp_history) diff --git a/qutebrowser/browser/webview.py b/qutebrowser/browser/webview.py index 36c3f508f..dd80a1fee 100644 --- a/qutebrowser/browser/webview.py +++ b/qutebrowser/browser/webview.py @@ -155,7 +155,7 @@ class WebView(QWebView): not self._orig_url.matches(self.cur_url, no_formatting)): # 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, self.title(), hidden=True) + history.add_url(self._orig_url, self.title(), redirect=True) history.add_url(self.cur_url, self.title()) def _init_page(self): diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 9740af1b7..b58f4ae6e 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -74,7 +74,8 @@ class UrlCompletionModel(base.BaseCompletionModel): self._max_history = config.get('completion', 'web-history-max-items') history = utils.newest_slice(self._history, self._max_history) for entry in history: - self._add_history_entry(entry) + if not entry.redirect: + self._add_history_entry(entry) self._history.add_completion_item.connect(self.on_history_item_added) self._history.cleared.connect(self.on_history_cleared) diff --git a/tests/end2end/features/history.feature b/tests/end2end/features/history.feature index 66567b90c..fab89f1fc 100644 --- a/tests/end2end/features/history.feature +++ b/tests/end2end/features/history.feature @@ -21,6 +21,7 @@ Feature: Page history When I open redirect-to?url=data/title.html without waiting And I wait until data/title.html is loaded Then the history file should contain: + r http://localhost:(port)/redirect-to?url=data/title.html Test title http://localhost:(port)/data/title.html Test title Scenario: History item with spaces in URL diff --git a/tests/end2end/features/test_history_bdd.py b/tests/end2end/features/test_history_bdd.py index c0f41a0ed..871dbcb98 100644 --- a/tests/end2end/features/test_history_bdd.py +++ b/tests/end2end/features/test_history_bdd.py @@ -37,8 +37,11 @@ def check_history(quteproc, httpbin, expected): if not line.strip(): continue print('history line: ' + line) - line = line.split(' ', maxsplit=1)[1] # Strip off timestamp + atime, line = line.split(' ', maxsplit=1) line = line.rstrip() + if '-' in atime: + flags = atime.split('-')[1] + line = '{} {}'.format(flags, line) lines.append(line) assert lines == expected diff --git a/tests/manual/history/visited.html b/tests/manual/history/visited.html index 3af5ab988..904b32ad0 100644 --- a/tests/manual/history/visited.html +++ b/tests/manual/history/visited.html @@ -5,8 +5,10 @@
After visiting a link, it should turn purple.
-When closing/reopening qutebrowser, the link still should be purple.
+