Add timestamp to :undo completion

This commit is contained in:
Florian Bruhin 2020-07-29 20:34:30 +02:00
parent f42cc99595
commit 8afe27885b
3 changed files with 18 additions and 7 deletions

View File

@ -280,12 +280,14 @@ def undo(*, info):
"""A model to complete undo entries."""
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=info.win_id)
model = completionmodel.CompletionModel(column_widths=(6, 94, 0))
model = completionmodel.CompletionModel(column_widths=(6, 84, 10))
timestamp_format = config.val.completion.timestamp_format
entries = [
(
str(idx),
', '.join(entry.url.toDisplayString() for entry in group)
', '.join(entry.url.toDisplayString() for entry in group),
group[-1].created_at.strftime(timestamp_format)
)
for idx, group in
enumerate(reversed(tabbed_browser.undo_stack), start=1)

View File

@ -23,6 +23,7 @@ import collections
import functools
import weakref
import typing
import datetime
import attr
from PyQt5.QtWidgets import QSizePolicy, QWidget, QApplication
@ -47,6 +48,7 @@ class _UndoEntry:
history = attr.ib()
index = attr.ib()
pinned = attr.ib()
created_at = attr.ib(attr.Factory(datetime.datetime.now))
class TabDeque:

View File

@ -1269,11 +1269,14 @@ def test_forward_completion(tab_with_history, info):
def test_undo_completion(tabbed_browser_stubs, info):
"""Test :undo completion."""
entry1 = tabbedbrowser._UndoEntry(url=QUrl('https://example.org/'),
history=None, index=None, pinned=None)
history=None, index=None, pinned=None,
created_at=datetime(2020, 1, 1))
entry2 = tabbedbrowser._UndoEntry(url=QUrl('https://example.com/'),
history=None, index=None, pinned=None)
history=None, index=None, pinned=None,
created_at=datetime(2020, 1, 2))
entry3 = tabbedbrowser._UndoEntry(url=QUrl('https://example.net/'),
history=None, index=None, pinned=None)
history=None, index=None, pinned=None,
created_at=datetime(2020, 1, 2))
# Most recently closed is at the end
tabbed_browser_stubs[0].undo_stack = [
@ -1288,7 +1291,11 @@ def test_undo_completion(tabbed_browser_stubs, info):
# undo stack.
_check_completions(model, {
"Closed tabs": [
("1", "https://example.com/, https://example.net/", None),
("2", "https://example.org/", None),
("1",
"https://example.com/, https://example.net/",
"2020-01-02 00:00"),
("2",
"https://example.org/",
"2020-01-01 00:00"),
],
})