From bd6783c7e60c167d81fe7c34203f7f546258feed Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Mon, 18 Apr 2016 22:54:17 +0300 Subject: [PATCH 1/4] Add --pretty flag to :yank With --pretty, the URL is yanked in a "pretty form", with most percent-encoded characters decoded. Partially fixes #1372. --- qutebrowser/browser/commands.py | 10 +++++++--- tests/integration/data/title with spaces.html | 10 ++++++++++ tests/integration/features/yankpaste.feature | 12 ++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 tests/integration/data/title with spaces.html diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 278380578..d2afd4528 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -654,13 +654,14 @@ class CommandDispatcher: frame.scroll(dx, dy) @cmdutils.register(instance='command-dispatcher', scope='window') - def yank(self, title=False, sel=False, domain=False): + def yank(self, title=False, sel=False, domain=False, pretty=False): """Yank the current URL/title to the clipboard or primary selection. Args: sel: Use the primary selection instead of the clipboard. title: Yank the title instead of the URL. domain: Yank only the scheme, domain, and port number. + pretty: Yank the URL in pretty decoded form. """ if title: s = self._tabbed_browser.page_title(self._current_index()) @@ -672,8 +673,11 @@ class CommandDispatcher: ':' + str(port) if port > -1 else '') what = 'domain' else: - s = self._current_url().toString( - QUrl.FullyEncoded | QUrl.RemovePassword) + cur_url = self._current_url() + if pretty: + s = cur_url.toString(QUrl.RemovePassword) + else: + s = cur_url.toString(QUrl.FullyEncoded | QUrl.RemovePassword) what = 'URL' if sel and QApplication.clipboard().supportsSelection(): diff --git a/tests/integration/data/title with spaces.html b/tests/integration/data/title with spaces.html new file mode 100644 index 000000000..d5e2ab9da --- /dev/null +++ b/tests/integration/data/title with spaces.html @@ -0,0 +1,10 @@ + + + + + Test title + + + foo + + diff --git a/tests/integration/features/yankpaste.feature b/tests/integration/features/yankpaste.feature index 8f6c6552f..58ae304b0 100644 --- a/tests/integration/features/yankpaste.feature +++ b/tests/integration/features/yankpaste.feature @@ -33,6 +33,18 @@ Feature: Yanking and pasting. Then the message "Yanked domain to clipboard: http://localhost:(port)" should be shown And the clipboard should contain "http://localhost:(port)" + Scenario: Yanking fully encoded URL + When I open data/title with spaces.html + And I run :yank + Then the message "Yanked URL to clipboard: http://localhost:(port)/data/title%20with%20spaces.html" should be shown + And the clipboard should contain "http://localhost:(port)/data/title%20with%20spaces.html" + + Scenario: Yanking pretty decoded URL + When I open data/title with spaces.html + And I run :yank --pretty + Then the message "Yanked URL to clipboard: http://localhost:(port)/data/title with spaces.html" should be shown + And the clipboard should contain "http://localhost:(port)/data/title with spaces.html" + #### :paste Scenario: Pasting an URL From 045b54b94b130fb1ec8d1739ebb2c69d0ee1c600 Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Mon, 18 Apr 2016 23:11:27 +0300 Subject: [PATCH 2/4] Add commands to yank pretty decoded URLs yp and yP, yank to the clipboard and primary selection respectively --- qutebrowser/config/configdata.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 10dad1ce9..eb060ae63 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -1443,6 +1443,8 @@ KEY_DATA = collections.OrderedDict([ ('yank -ts', ['yT']), ('yank -d', ['yd']), ('yank -ds', ['yD']), + ('yank -p', ['yp']), + ('yank -ps', ['yP']), ('paste', ['pp']), ('paste -s', ['pP']), ('paste -t', ['Pp']), From 6c3b0219e76fe8eb5183c5d3a1574c7e66086351 Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Wed, 20 Apr 2016 17:25:26 +0300 Subject: [PATCH 3/4] Style fix --- qutebrowser/browser/commands.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index d2afd4528..f738157f2 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -673,11 +673,10 @@ class CommandDispatcher: ':' + str(port) if port > -1 else '') what = 'domain' else: - cur_url = self._current_url() - if pretty: - s = cur_url.toString(QUrl.RemovePassword) - else: - s = cur_url.toString(QUrl.FullyEncoded | QUrl.RemovePassword) + flags = QUrl.RemovePassword + if not pretty: + flags |= QUrl.FullyEncoded + s = self._current_url().toString(flags) what = 'URL' if sel and QApplication.clipboard().supportsSelection(): From 9ae826295b7bb64b728f962ae6e3c46718df48f9 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 20 Apr 2016 22:17:27 +0200 Subject: [PATCH 4/4] Update docs --- CHANGELOG.asciidoc | 1 + README.asciidoc | 2 +- doc/help/commands.asciidoc | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 0a725709b..2dafe1e88 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -30,6 +30,7 @@ Changed - qutebrowser got a new (slightly updated) logo - `:tab-focus` can now take a negative index to focus the nth tab counted from the right. +- `:yank` can now yank the pretty/decoded URL by adding `--pretty` v0.6.1 ----- diff --git a/README.asciidoc b/README.asciidoc index aca9172d3..d9912aa3d 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -166,6 +166,7 @@ Contributors, sorted by the number of commits in descending order: * Philipp Hansch * Kevin Velghe * Austin Anderson +* Panagiotis Ktistakis * Alexey "Averrin" Nabrodov * avk * ZDarian @@ -173,7 +174,6 @@ Contributors, sorted by the number of commits in descending order: * John ShaggyTwoDope Jenkins * Jimmy * Peter Vilim -* Panagiotis Ktistakis * Clayton Craft * Oliver Caldwell * Jonas Schürmann diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index bf0891904..ab8ad9796 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -794,7 +794,7 @@ Save open pages and quit. [[yank]] === yank -Syntax: +:yank [*--title*] [*--sel*] [*--domain*]+ +Syntax: +:yank [*--title*] [*--sel*] [*--domain*] [*--pretty*]+ Yank the current URL/title to the clipboard or primary selection. @@ -802,6 +802,7 @@ Yank the current URL/title to the clipboard or primary selection. * +*-t*+, +*--title*+: Yank the title instead of the URL. * +*-s*+, +*--sel*+: Use the primary selection instead of the clipboard. * +*-d*+, +*--domain*+: Yank only the scheme, domain, and port number. +* +*-p*+, +*--pretty*+: Yank the URL in pretty decoded form. [[yank-selected]] === yank-selected