From 8635dc884830ab7b4334acfa93ccb84311cabb4a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 27 Sep 2014 23:13:27 +0200 Subject: [PATCH] Make it possible to go back/forward in a new tab. --- doc/TODO | 6 ------ qutebrowser/browser/commands.py | 26 ++++++++++++++++++++------ qutebrowser/config/configdata.py | 2 ++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/doc/TODO b/doc/TODO index 942f799cd..98d78bc14 100644 --- a/doc/TODO +++ b/doc/TODO @@ -270,12 +270,6 @@ Other [n]gc Clear tab n or of current tab, clears the history of the tab and loads about:blank. (command clear_tab, aliases: clear). -th -Go back in a new tab (command tab_hist_back, aliases: tabback, tba). - -tl -Go forward in a new tab (command tab_hist_forward, aliases: tabforward, tfo). - c/ Find forward, ignore case (command find_forward_ic, alias: iffind). diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index a7c6633a1..f47e29608 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -299,25 +299,39 @@ class CommandDispatcher: qtutils.deserialize(history, newtab.history()) return newtab + def _back_forward(self, tab, bg, count, forward): + """Helper function for :back/:forward.""" + if tab or bg: + widget = self.tab_clone(bg) + else: + widget = self._current_widget() + for _ in range(count): + if forward: + widget.go_forward() + else: + widget.go_back() + @cmdutils.register(instance='command-dispatcher') - def back(self, count=1): + def back(self, tab=False, bg=False, count=1): """Go back in the history of the current tab. Args: + tab: Go back in a new tab. + bg: Go back in a background tab. count: How many pages to go back. """ - for _ in range(count): - self._current_widget().go_back() + self._back_forward(tab, bg, count, forward=False) @cmdutils.register(instance='command-dispatcher') - def forward(self, count=1): + def forward(self, tab=False, bg=False, count=1): """Go forward in the history of the current tab. Args: + tab: Go forward in a new tab. + bg: Go back in a background tab. count: How many pages to go forward. """ - for _ in range(count): - self._current_widget().go_forward() + self._back_forward(tab, bg, count, forward=True) def _navigate_incdec(self, url, tab, incdec): """Helper method for :navigate when `where' is increment/decrement. diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 2528375c0..27778b986 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -890,7 +890,9 @@ KEY_DATA = collections.OrderedDict([ ('tab-clone', ['gC']), ('reload', ['r']), ('back', ['H', '']), + ('back -t', ['th']), ('forward', ['L']), + ('forward -t', ['tl']), ('hint', ['f']), ('hint all tab', ['F']), ('hint all tab-bg', [';b']),