Merge remote-tracking branch 'origin/pr/4292'

This commit is contained in:
Florian Bruhin 2018-10-05 16:20:08 +02:00
commit 95f816c224
2 changed files with 13 additions and 9 deletions

View File

@ -1397,7 +1397,7 @@ Close all windows except for the current one.
[[yank]] [[yank]]
=== yank === yank
Syntax: +:yank [*--sel*] [*--keep*] ['what']+ Syntax: +:yank [*--sel*] [*--keep*] [*--quiet*] ['what']+
Yank something to the clipboard or primary selection. Yank something to the clipboard or primary selection.
@ -1416,6 +1416,7 @@ Yank something to the clipboard or primary selection.
==== optional arguments ==== optional arguments
* +*-s*+, +*--sel*+: Use the primary selection instead of the clipboard. * +*-s*+, +*--sel*+: Use the primary selection instead of the clipboard.
* +*-k*+, +*--keep*+: Stay in visual mode after yanking the selection. * +*-k*+, +*--keep*+: Stay in visual mode after yanking the selection.
* +*-q*+, +*--quiet*+: Don't show information message.
[[zoom]] [[zoom]]
=== zoom === zoom

View File

@ -817,7 +817,7 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('what', choices=['selection', 'url', 'pretty-url', @cmdutils.argument('what', choices=['selection', 'url', 'pretty-url',
'title', 'domain']) 'title', 'domain'])
def yank(self, what='url', sel=False, keep=False): def yank(self, what='url', sel=False, keep=False, quiet=False):
"""Yank something to the clipboard or primary selection. """Yank something to the clipboard or primary selection.
Args: Args:
@ -831,6 +831,7 @@ class CommandDispatcher:
sel: Use the primary selection instead of the clipboard. sel: Use the primary selection instead of the clipboard.
keep: Stay in visual mode after yanking the selection. keep: Stay in visual mode after yanking the selection.
quiet: Don't show information message.
""" """
if what == 'title': if what == 'title':
s = self._tabbed_browser.widget.page_title(self._current_index()) s = self._tabbed_browser.widget.page_title(self._current_index())
@ -844,10 +845,10 @@ class CommandDispatcher:
what = 'URL' # For printing what = 'URL' # For printing
elif what == 'selection': elif what == 'selection':
def _selection_callback(s): def _selection_callback(s):
if not s: if not s and not quiet:
message.info("Nothing to yank") message.info("Nothing to yank")
return return
self._yank_to_target(s, sel, what, keep) self._yank_to_target(s, sel, what, keep, quiet)
caret = self._current_widget().caret caret = self._current_widget().caret
caret.selection(callback=_selection_callback) caret.selection(callback=_selection_callback)
@ -855,9 +856,9 @@ class CommandDispatcher:
else: # pragma: no cover else: # pragma: no cover
raise ValueError("Invalid value {!r} for `what'.".format(what)) raise ValueError("Invalid value {!r} for `what'.".format(what))
self._yank_to_target(s, sel, what, keep) self._yank_to_target(s, sel, what, keep, quiet)
def _yank_to_target(self, s, sel, what, keep): def _yank_to_target(self, s, sel, what, keep, quiet):
if sel and utils.supports_selection(): if sel and utils.supports_selection():
target = "primary selection" target = "primary selection"
else: else:
@ -866,10 +867,12 @@ class CommandDispatcher:
utils.set_clipboard(s, selection=sel) utils.set_clipboard(s, selection=sel)
if what != 'selection': if what != 'selection':
message.info("Yanked {} to {}: {}".format(what, target, s)) if not quiet:
message.info("Yanked {} to {}: {}".format(what, target, s))
else: else:
message.info("{} {} yanked to {}".format( if not quiet:
len(s), "char" if len(s) == 1 else "chars", target)) message.info("{} {} yanked to {}".format(
len(s), "char" if len(s) == 1 else "chars", target))
if not keep: if not keep:
modeman.leave(self._win_id, KeyMode.caret, "yank selected", modeman.leave(self._win_id, KeyMode.caret, "yank selected",
maybe=True) maybe=True)