Allows to paste multiple URLs

- The paste command will now open one tab/window per url if multiple
  URLs (separated by newline) are present in the clipboard
- Adds the tests for the new multitab functionality
- Changes test/integration/conftest.py to be able to insert newlines in
  the clipboard for the test
This commit is contained in:
Tarcisio Fedrizzi 2016-01-09 11:32:12 +01:00
parent 6327d0fe36
commit 1b31a3fee4
3 changed files with 72 additions and 6 deletions

View File

@ -825,12 +825,18 @@ class CommandDispatcher:
text = clipboard.text(mode)
if not text:
raise cmdexc.CommandError("{} is empty.".format(target))
log.misc.debug("{} contained: '{}'".format(target, text))
try:
url = urlutils.fuzzy_url(text)
except urlutils.InvalidUrlError as e:
raise cmdexc.CommandError(e)
self._open(url, tab, bg, window)
log.misc.debug("{} contained: '{}'".format(target,
text.replace('\n', '\\n')))
text_urls = enumerate([u for u in text.split('\n') if u != ''])
for i, text_url in text_urls:
if not window and i > 0:
tab = False
bg = True
try:
url = urlutils.fuzzy_url(text_url)
except urlutils.InvalidUrlError as e:
raise cmdexc.CommandError(e)
self._open(url, tab, bg, window)
@cmdutils.register(instance='command-dispatcher', scope='window',
count='count')

View File

@ -199,6 +199,7 @@ def selection_supported(qapp):
def fill_clipboard(qtbot, qapp, httpbin, what, content):
mode = _clipboard_mode(qapp, what)
content = content.replace('(port)', str(httpbin.port))
content = content.replace('\\n', '\n')
clipboard = qapp.clipboard()
with qtbot.waitSignal(clipboard.changed):

View File

@ -104,3 +104,62 @@ Feature: Yanking and pasting.
And I put "foo bar" into the clipboard
And I run :paste
Then the error "Invalid URL" should be shown
Scenario: Pasting multiple urls in a new tab
Given I have a fresh instance
When I run :tab-only
And I put "http://localhost:(port)/data/hello.txt\nhttp://localhost:(port)/data/hello2.txt\nhttp://localhost:(port)/data/hello3.txt" into the clipboard
And I run :paste -t
And I wait until data/hello.txt is loaded
And I wait until data/hello2.txt is loaded
And I wait until data/hello3.txt is loaded
Then the following tabs should be open:
- about:blank
- data/hello.txt (active)
- data/hello2.txt
- data/hello3.txt
Scenario: Pasting multiple urls in a background tab
Given I open about:blank
When I run :tab-only
And I put "http://localhost:(port)/data/hello.txt\nhttp://localhost:(port)/data/hello2.txt\nhttp://localhost:(port)/data/hello3.txt" into the clipboard
And I run :paste -b
And I wait until data/hello.txt is loaded
And I wait until data/hello2.txt is loaded
And I wait until data/hello3.txt is loaded
Then the following tabs should be open:
- about:blank (active)
- data/hello.txt
- data/hello2.txt
- data/hello3.txt
Scenario: Pasting multiple urls in new windows
Given I have a fresh instance
When I put "http://localhost:(port)/data/hello.txt\nhttp://localhost:(port)/data/hello2.txt\nhttp://localhost:(port)/data/hello3.txt" into the clipboard
And I run :paste -w
And I wait until data/hello.txt is loaded
And I wait until data/hello2.txt is loaded
And I wait until data/hello3.txt is loaded
Then the session should look like:
windows:
- tabs:
- active: true
history:
- active: true
url: about:blank
- tabs:
- active: true
history:
- active: true
url: http://localhost:*/data/hello.txt
- tabs:
- active: true
history:
- active: true
url: http://localhost:*/data/hello2.txt
- tabs:
- active: true
history:
- active: true
url: http://localhost:*/data/hello3.txt