Merge branch 'hcraT-master'

This commit is contained in:
Florian Bruhin 2016-01-13 18:22:15 +01:00
commit 6014a963d4
8 changed files with 107 additions and 12 deletions

View File

@ -23,6 +23,11 @@ Added
- New `--quiet` argument for the `:debug-pyeval` command to not open a tab with
the results. Note `:debug-pyeval` is still only intended for debugging.
Changed
~~~~~~~
- Pasting multiple lines via `:paste` now opens each line in a new tab.
Fixed
~~~~~

View File

@ -160,6 +160,7 @@ Contributors, sorted by the number of commits in descending order:
* ZDarian
* John ShaggyTwoDope Jenkins
* Peter Vilim
* Tarcisio Fedrizzi
* Jonas Schürmann
* Panagiotis Ktistakis
* Jimmy

View File

@ -402,6 +402,8 @@ Syntax: +:paste [*--sel*] [*--tab*] [*--bg*] [*--window*]+
Open a page from the clipboard.
If the pasted text contains newlines, each line gets opened in its own tab.
==== optional arguments
* +*-s*+, +*--sel*+: Use the primary selection instead of the clipboard.
* +*-t*+, +*--tab*+: Open in a new tab.

View File

@ -809,6 +809,9 @@ class CommandDispatcher:
def paste(self, sel=False, tab=False, bg=False, window=False):
"""Open a page from the clipboard.
If the pasted text contains newlines, each line gets opened in its own
tab.
Args:
sel: Use the primary selection instead of the clipboard.
tab: Open in a new tab.
@ -825,12 +828,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

@ -168,6 +168,7 @@ def fuzzy_url(urlstr, cwd=None, relative=False, do_search=True):
Return:
A target QUrl to a search page or the original URL.
"""
urlstr = urlstr.strip()
expanded = os.path.expanduser(urlstr)
if os.path.isabs(expanded):
path = expanded
@ -181,11 +182,10 @@ def fuzzy_url(urlstr, cwd=None, relative=False, do_search=True):
else:
path = None
stripped = urlstr.strip()
if path is not None and os.path.exists(path):
log.url.debug("URL is a local file")
url = QUrl.fromLocalFile(path)
elif (not do_search) or is_url(stripped):
elif (not do_search) or is_url(urlstr):
# probably an address
log.url.debug("URL is a fuzzy address")
url = qurl_from_user_input(urlstr)
@ -194,7 +194,7 @@ def fuzzy_url(urlstr, cwd=None, relative=False, do_search=True):
try:
url = _get_search_url(urlstr)
except ValueError: # invalid search engine
url = qurl_from_user_input(stripped)
url = qurl_from_user_input(urlstr)
log.url.debug("Converting fuzzy term {} to URL -> {}".format(
urlstr, url.toDisplayString()))
if do_search and config.get('general', 'auto-search'):

View File

@ -25,6 +25,7 @@ import json
import os.path
import logging
import collections
import textwrap
import pytest
import yaml
@ -207,6 +208,13 @@ def fill_clipboard(qtbot, qapp, httpbin, what, content):
clipboard.setText(content, mode)
@bdd.when(bdd.parsers.re(r'I put the following lines into the '
r'(?P<what>primary selection|clipboard):\n'
r'(?P<content>.+)$', flags=re.DOTALL))
def fill_clipboard_multiline(qtbot, qapp, httpbin, what, content):
fill_clipboard(qtbot, qapp, httpbin, what, textwrap.dedent(content))
## Then

View File

@ -104,3 +104,69 @@ 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 put the following lines into the clipboard:
http://localhost:(port)/data/hello.txt
http://localhost:(port)/data/hello2.txt
http://localhost:(port)/data/hello3.txt
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 the following lines into the clipboard:
http://localhost:(port)/data/hello.txt
http://localhost:(port)/data/hello2.txt
http://localhost:(port)/data/hello3.txt
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 the following lines into the clipboard:
http://localhost:(port)/data/hello.txt
http://localhost:(port)/data/hello2.txt
http://localhost:(port)/data/hello3.txt
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

View File

@ -166,13 +166,17 @@ class TestFuzzyUrl:
assert not os_mock.path.exists.called
assert url == QUrl('http://foo')
def test_file_absolute(self, os_mock):
@pytest.mark.parametrize('path, expected', [
('/foo', QUrl('file:///foo')),
('/bar\n', QUrl('file:///bar')),
])
def test_file_absolute(self, path, expected, os_mock):
"""Test with an absolute path."""
os_mock.path.exists.return_value = True
os_mock.path.isabs.return_value = True
url = urlutils.fuzzy_url('/foo')
assert url == QUrl('file:///foo')
url = urlutils.fuzzy_url(path)
assert url == expected
@pytest.mark.posix
def test_file_absolute_expanded(self, os_mock):