Add --implicit flag to :open

This commit is contained in:
Marshall Lochbaum 2016-08-02 13:49:25 -04:00
parent 0345e62348
commit 66adbc9323
2 changed files with 43 additions and 5 deletions

View File

@ -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:

View File

@ -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