From cc5667f2683103f9ce64dba0f96aae65a0817d3a Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Tue, 9 Aug 2016 20:14:44 +1000 Subject: [PATCH 1/3] Add code to save and restore the old tab position --- qutebrowser/mainwindow/tabbedbrowser.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index dcac67ad3..bd8a22fe5 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -34,7 +34,7 @@ from qutebrowser.utils import (log, usertypes, utils, qtutils, objreg, urlutils, message) -UndoEntry = collections.namedtuple('UndoEntry', ['url', 'history']) +UndoEntry = collections.namedtuple('UndoEntry', ['url', 'history', 'index']) class TabDeletedError(Exception): @@ -260,7 +260,7 @@ class TabbedBrowser(tabwidget.TabWidget): window=self._win_id) if tab.url().isValid(): history_data = tab.history.serialize() - entry = UndoEntry(tab.url(), history_data) + entry = UndoEntry(tab.url(), history_data, idx) self._undo_stack.append(entry) elif tab.url().isEmpty(): # There are some good reasons why a URL could be empty @@ -297,13 +297,13 @@ class TabbedBrowser(tabwidget.TabWidget): use_current_tab = (only_one_tab_open and no_history and last_close_url_used) - url, history_data = self._undo_stack.pop() + url, history_data, idx = self._undo_stack.pop() if use_current_tab: self.openurl(url, newtab=False) newtab = self.widget(0) else: - newtab = self.tabopen(url, background=False) + newtab = self.tabopen(url, background=False, idx=idx) newtab.history.deserialize(history_data) @@ -342,7 +342,7 @@ class TabbedBrowser(tabwidget.TabWidget): @pyqtSlot('QUrl') @pyqtSlot('QUrl', bool) - def tabopen(self, url=None, background=None, explicit=False): + def tabopen(self, url=None, background=None, explicit=False, idx=None): """Open a new tab with a given URL. Inner logic for open-tab and open-tab-bg. @@ -358,6 +358,7 @@ class TabbedBrowser(tabwidget.TabWidget): - Tabs from clicked links etc. are to the right of the current. - Explicitly opened tabs are at the very right. + idx: The index where the new tab should be opened. Return: The opened WebView instance. @@ -376,7 +377,8 @@ class TabbedBrowser(tabwidget.TabWidget): tab = browsertab.create(win_id=self._win_id, parent=self) self._connect_tab_signals(tab) - idx = self._get_new_tab_idx(explicit) + if idx is None: + idx = self._get_new_tab_idx(explicit) self.insertTab(idx, tab, "") if url is not None: From 66dcc391bab7145feb4b81ced0535c620876a0d6 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Wed, 10 Aug 2016 21:12:02 +1000 Subject: [PATCH 2/3] Add tests to check :undo opens in the old position --- tests/end2end/features/tabs.feature | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/end2end/features/tabs.feature b/tests/end2end/features/tabs.feature index 42ad9152d..40c5215d4 100644 --- a/tests/end2end/features/tabs.feature +++ b/tests/end2end/features/tabs.feature @@ -703,6 +703,53 @@ Feature: Tab management Then the error "Nothing to undo!" should be shown And the error "Nothing to undo!" should be shown + Scenario: Undo a tab closed by index + When I open data/numbers/1.txt + And I open data/numbers/2.txt in a new tab + And I open data/numbers/3.txt in a new tab + And I run :tab-close with count 1 + And I run :undo + Then the following tabs should be open: + - data/numbers/1.txt (active) + - data/numbers/2.txt + - data/numbers/3.txt + + Scenario: Undo a tab closed after switching tabs + When I open data/numbers/1.txt + And I open data/numbers/2.txt in a new tab + And I open data/numbers/3.txt in a new tab + And I run :tab-close with count 1 + And I run :tab-focus 2 + And I run :undo + Then the following tabs should be open: + - data/numbers/1.txt (active) + - data/numbers/2.txt + - data/numbers/3.txt + + Scenario: Undo a tab closed after rearranging tabs + When I open data/numbers/1.txt + And I open data/numbers/2.txt in a new tab + And I open data/numbers/3.txt in a new tab + And I run :tab-close with count 1 + And I run :tab-focus 2 + And I run :tab-move with count 1 + And I run :undo + Then the following tabs should be open: + - data/numbers/1.txt (active) + - data/numbers/3.txt + - data/numbers/2.txt + + Scenario: Undo a tab closed after new tab opened + When I open data/numbers/1.txt + And I open data/numbers/2.txt in a new tab + And I run :tab-close with count 1 + And I open data/numbers/3.txt in a new tab + And I run :undo + Then the following tabs should be open: + - data/numbers/1.txt (active) + - data/numbers/2.txt + - data/numbers/3.txt + # last-close Scenario: last-close = blank From a07e520f6b1da90a9187a26ebb6500bcc1ba3351 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 10 Aug 2016 17:50:24 +0200 Subject: [PATCH 3/3] Update docs --- CHANGELOG.asciidoc | 1 + README.asciidoc | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 744cf8d8b..cd4c84e98 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -61,6 +61,7 @@ Changed - Word hints now are more clever about getting the element text from some elements. - Completions for `:help` and `:bind` now also show hidden commands - The `:buffer` completion now also filters using the first column (id). +- `:undo` has been improved to reopen tabs at the position they were closed. Removed ~~~~~~~ diff --git a/README.asciidoc b/README.asciidoc index be816198d..06fbb74e7 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -213,6 +213,7 @@ Contributors, sorted by the number of commits in descending order: * adam * Samir Benmendil * Regina Hug +* Michael Hoang * Mathias Fussenegger * Marcelo Santos * Jean-Louis Fuchs