Add --domain to yank to yank only the domain

... As I want to copy only the domain fairly frequently.

I also changed the message in the statusline to show the actual text being
copied, which I find helpful. But if you disagree, then just undo it (it's not
that important or anything).
This commit is contained in:
Martin Tournoij 2015-06-04 12:20:43 +02:00
parent e780efb3d9
commit 0132bea42b
3 changed files with 14 additions and 4 deletions

View File

@ -642,13 +642,14 @@ Save open pages and quit.
[[yank]]
=== yank
Syntax: +:yank [*--title*] [*--sel*]+
Syntax: +:yank [*--title*] [*--sel*] [*--domain*]+
Yank the current URL/title to the clipboard or primary selection.
==== optional arguments
* +*-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.
[[zoom]]
=== zoom

View File

@ -696,19 +696,26 @@ class CommandDispatcher:
frame.scroll(dx, dy)
@cmdutils.register(instance='command-dispatcher', scope='window')
def yank(self, title=False, sel=False):
def yank(self, title=False, sel=False, domain=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.
"""
clipboard = QApplication.clipboard()
if title:
s = self._tabbed_browser.page_title(self._current_index())
what = 'title'
elif domain:
s = '{}://{}'.format(self._current_url().scheme(),
self._current_url().host())
what = 'domain'
else:
s = self._current_url().toString(
QUrl.FullyEncoded | QUrl.RemovePassword)
what = 'URL'
if sel and clipboard.supportsSelection():
mode = QClipboard.Selection
target = "primary selection"
@ -717,8 +724,8 @@ class CommandDispatcher:
target = "clipboard"
log.misc.debug("Yanking to {}: '{}'".format(target, s))
clipboard.setText(s, mode)
what = 'Title' if title else 'URL'
message.info(self._win_id, "{} yanked to {}".format(what, target))
message.info(self._win_id, "Yanked {} to {}: {}".format(
what, target, s))
@cmdutils.register(instance='command-dispatcher', scope='window',
count='count')

View File

@ -1204,6 +1204,8 @@ KEY_DATA = collections.OrderedDict([
('yank -s', ['yY']),
('yank -t', ['yt']),
('yank -ts', ['yT']),
('yank -d', ['yd']),
('yank -ds', ['yD']),
('paste', ['pp']),
('paste -s', ['pP']),
('paste -t', ['Pp']),