From 66adbc932391f500a824b0d5b0341241034591ce Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 2 Aug 2016 13:49:25 -0400 Subject: [PATCH 1/5] Add --implicit flag to :open --- qutebrowser/browser/commands.py | 14 +++++++----- tests/end2end/features/open.feature | 34 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index f47bcb00b..bced44db4 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -114,7 +114,8 @@ class CommandDispatcher: raise cmdexc.CommandError("No WebView available yet!") return widget - def _open(self, url, tab=False, background=False, window=False): + def _open(self, url, explicit=True, + tab=False, background=False, window=False): """Helper function to open a page. Args: @@ -130,9 +131,9 @@ class CommandDispatcher: tabbed_browser = self._new_tabbed_browser() tabbed_browser.tabopen(url) elif tab: - tabbed_browser.tabopen(url, background=False, explicit=True) + tabbed_browser.tabopen(url, background=False, explicit=explicit) elif background: - tabbed_browser.tabopen(url, background=True, explicit=True) + tabbed_browser.tabopen(url, background=True, explicit=explicit) else: widget = self._current_widget() widget.openurl(url) @@ -231,7 +232,8 @@ class CommandDispatcher: maxsplit=0, scope='window') @cmdutils.argument('url', completion=usertypes.Completion.url) @cmdutils.argument('count', count=True) - def openurl(self, url=None, bg=False, tab=False, window=False, count=None): + def openurl(self, url=None, implicit=False, + bg=False, tab=False, window=False, count=None): """Open a URL in the current/[count]th tab. Args: @@ -239,6 +241,8 @@ class CommandDispatcher: bg: Open in a new background tab. tab: Open in a new tab. window: Open in a new window. + implicit: If opening a new tab, treat the tab as implicit (like + clicking on a link). count: The tab index to open the URL in, or None. """ if url is None: @@ -259,7 +263,7 @@ class CommandDispatcher: message.error(self._win_id, str(e)) return if tab or bg or window: - self._open(url, tab, bg, window) + self._open(url, not implicit, tab, bg, window) else: curtab = self._cntwidget(count) if curtab is None: diff --git a/tests/end2end/features/open.feature b/tests/end2end/features/open.feature index 4264ccb9c..6a9daeabb 100644 --- a/tests/end2end/features/open.feature +++ b/tests/end2end/features/open.feature @@ -108,3 +108,37 @@ Feature: Opening pages When I run :quickmark-add http://localhost:(port)/data/numbers/8.txt quickmarktest And I run :open quickmarktest Then data/numbers/8.txt should be loaded + + Scenario: :open with URL (explicit) + Given I open about:blank + When I set tabs -> new-tab-position-explicit to right + And I set tabs -> new-tab-position to left + And I run :tab-only + And I run :open -t http://localhost:(port)/data/numbers/9.txt + And I wait until data/numbers/9.txt is loaded + Then the session should look like: + windows: + - tabs: + - history: + - url: about:blank + - active: true + history: + - active: true + url: http://localhost:*/data/numbers/9.txt + + Scenario: :open with URL (implicit) + Given I open about:blank + When I set tabs -> new-tab-position-explicit to right + And I set tabs -> new-tab-position to left + And I run :tab-only + And I run :open -t -i http://localhost:(port)/data/numbers/10.txt + And I wait until data/numbers/10.txt is loaded + Then the session should look like: + windows: + - tabs: + - active: true + history: + - active: true + url: http://localhost:*/data/numbers/10.txt + - history: + - url: about:blank From feed1ccda48f487aaae1456d093cf7918c1e4c59 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 2 Aug 2016 14:10:36 -0400 Subject: [PATCH 2/5] Change gO, xO, and ;O keybindings to open an implicit tab --- qutebrowser/config/configdata.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index b4b0af80e..f20b5bd97 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -1428,9 +1428,9 @@ KEY_DATA = collections.OrderedDict([ ('set-cmd-text -s :open', ['o']), ('set-cmd-text :open {url:pretty}', ['go']), ('set-cmd-text -s :open -t', ['O']), - ('set-cmd-text :open -t {url:pretty}', ['gO']), + ('set-cmd-text :open -t -i {url:pretty}', ['gO']), ('set-cmd-text -s :open -b', ['xo']), - ('set-cmd-text :open -b {url:pretty}', ['xO']), + ('set-cmd-text :open -b -i {url:pretty}', ['xO']), ('set-cmd-text -s :open -w', ['wo']), ('set-cmd-text :open -w {url:pretty}', ['wO']), ('open -t', ['ga', '']), @@ -1463,7 +1463,7 @@ KEY_DATA = collections.OrderedDict([ ('hint images', [';i']), ('hint images tab', [';I']), ('hint links fill :open {hint-url}', [';o']), - ('hint links fill :open -t {hint-url}', [';O']), + ('hint links fill :open -t -i {hint-url}', [';O']), ('hint links yank', [';y']), ('hint links yank-primary', [';Y']), ('hint --rapid links tab-bg', [';r']), @@ -1656,4 +1656,9 @@ CHANGED_KEY_COMMANDS = [ (re.compile(r'^download-remove --all$'), r'download-clear'), (re.compile(r'^hint links fill "([^"]*)"$'), r'hint links fill \1'), + + (re.compile(r'^set-cmd-text :open -([tb]) {url:pretty}$'), + r'set-cmd-text :open -\1 -i {url:pretty}'), + (re.compile(r'^hint links fill :open -t {hint-url}$'), + r'hint links fill :open -t -i {hint-url}'), ] From 299d4865d0e114444df3d040521c3a91725f0b22 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 2 Aug 2016 15:26:13 -0400 Subject: [PATCH 3/5] Move --implicit flag argument to the end of _open --- qutebrowser/browser/commands.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index bced44db4..12377166c 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -114,8 +114,8 @@ class CommandDispatcher: raise cmdexc.CommandError("No WebView available yet!") return widget - def _open(self, url, explicit=True, - tab=False, background=False, window=False): + def _open(self, url, tab=False, background=False, window=False, + explicit=True): """Helper function to open a page. Args: @@ -263,7 +263,7 @@ class CommandDispatcher: message.error(self._win_id, str(e)) return if tab or bg or window: - self._open(url, not implicit, tab, bg, window) + self._open(url, tab, bg, window, not implicit) else: curtab = self._cntwidget(count) if curtab is None: From 97a249d8a6392f531e4f76f047872fa0668ed7a6 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 2 Aug 2016 15:27:26 -0400 Subject: [PATCH 4/5] Rewrite tests in open.feature --- tests/end2end/features/open.feature | 93 +++++++++++------------------ 1 file changed, 34 insertions(+), 59 deletions(-) diff --git a/tests/end2end/features/open.feature b/tests/end2end/features/open.feature index 6a9daeabb..45012e639 100644 --- a/tests/end2end/features/open.feature +++ b/tests/end2end/features/open.feature @@ -43,31 +43,18 @@ Feature: Opening pages When I run :tab-only And I run :open -t http://localhost:(port)/data/numbers/4.txt And I wait until data/numbers/4.txt is loaded - Then the session should look like: - windows: - - tabs: - - history: - - url: about:blank - - active: true - history: - - active: true - url: http://localhost:*/data/numbers/4.txt + Then the following tabs should be open: + - about:blank + - data/numbers/4.txt (active) Scenario: Opening in a new background tab Given I open about:blank When I run :tab-only And I run :open -b http://localhost:(port)/data/numbers/5.txt And I wait until data/numbers/5.txt is loaded - Then the session should look like: - windows: - - tabs: - - active: true - history: - - active: true - url: about:blank - - history: - - active: true - url: http://localhost:*/data/numbers/5.txt + Then the following tabs should be open: + - about:blank (active) + - data/numbers/5.txt Scenario: :open with count Given I open about:blank @@ -86,11 +73,33 @@ Feature: Opening pages - active: true url: http://localhost:*/data/numbers/6.txt + Scenario: Opening in a new tab (explicit) + Given I open about:blank + When I set tabs -> new-tab-position-explicit to right + And I set tabs -> new-tab-position to left + And I run :tab-only + And I run :open -t http://localhost:(port)/data/numbers/7.txt + And I wait until data/numbers/7.txt is loaded + Then the following tabs should be open: + - about:blank + - data/numbers/7.txt (active) + + Scenario: Opening in a new tab (implicit) + Given I open about:blank + When I set tabs -> new-tab-position-explicit to right + And I set tabs -> new-tab-position to left + And I run :tab-only + And I run :open -t -i http://localhost:(port)/data/numbers/8.txt + And I wait until data/numbers/8.txt is loaded + Then the following tabs should be open: + - data/numbers/8.txt (active) + - about:blank + Scenario: Opening in a new window Given I open about:blank When I run :tab-only - And I run :open -w http://localhost:(port)/data/numbers/7.txt - And I wait until data/numbers/7.txt is loaded + And I run :open -w http://localhost:(port)/data/numbers/9.txt + And I wait until data/numbers/9.txt is loaded Then the session should look like: windows: - tabs: @@ -99,46 +108,12 @@ Feature: Opening pages - active: true url: about:blank - tabs: - - active: true - history: - - active: true - url: http://localhost:*/data/numbers/7.txt - - Scenario: Opening a quickmark - When I run :quickmark-add http://localhost:(port)/data/numbers/8.txt quickmarktest - And I run :open quickmarktest - Then data/numbers/8.txt should be loaded - - Scenario: :open with URL (explicit) - Given I open about:blank - When I set tabs -> new-tab-position-explicit to right - And I set tabs -> new-tab-position to left - And I run :tab-only - And I run :open -t http://localhost:(port)/data/numbers/9.txt - And I wait until data/numbers/9.txt is loaded - Then the session should look like: - windows: - - tabs: - - history: - - url: about:blank - active: true history: - active: true url: http://localhost:*/data/numbers/9.txt - Scenario: :open with URL (implicit) - Given I open about:blank - When I set tabs -> new-tab-position-explicit to right - And I set tabs -> new-tab-position to left - And I run :tab-only - And I run :open -t -i http://localhost:(port)/data/numbers/10.txt - And I wait until data/numbers/10.txt is loaded - Then the session should look like: - windows: - - tabs: - - active: true - history: - - active: true - url: http://localhost:*/data/numbers/10.txt - - history: - - url: about:blank + Scenario: Opening a quickmark + When I run :quickmark-add http://localhost:(port)/data/numbers/10.txt quickmarktest + And I run :open quickmarktest + Then data/numbers/10.txt should be loaded From af9e956cb695837f7e115f4601fbf4f7f5ca632d Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 2 Aug 2016 15:29:18 -0400 Subject: [PATCH 5/5] Remove config update code for --implicit flag --- qutebrowser/config/configdata.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index f20b5bd97..a99dcc8bf 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -1656,9 +1656,4 @@ CHANGED_KEY_COMMANDS = [ (re.compile(r'^download-remove --all$'), r'download-clear'), (re.compile(r'^hint links fill "([^"]*)"$'), r'hint links fill \1'), - - (re.compile(r'^set-cmd-text :open -([tb]) {url:pretty}$'), - r'set-cmd-text :open -\1 -i {url:pretty}'), - (re.compile(r'^hint links fill :open -t {hint-url}$'), - r'hint links fill :open -t -i {hint-url}'), ]