def yank(self, url: QUrl, context: HintContext) -> None: """Yank an element to the clipboard or primary selection.""" sel = (context.target == Target.yank_primary and utils.supports_selection()) flags = QUrl.FullyEncoded | QUrl.RemovePassword if url.scheme() == 'mailto': flags |= QUrl.RemoveScheme urlstr = url.toString(flags) # type: ignore[arg-type] new_content = urlstr # only second and consecutive yanks are to append to the clipboard if context.rapid and not context.first_run: try: old_content = utils.get_clipboard(selection=sel) except utils.ClipboardEmptyError: pass else: new_content = os.linesep.join([old_content, new_content]) utils.set_clipboard(new_content, selection=sel) msg = "Yanked URL to {}: {}".format( "primary selection" if sel else "clipboard", urlstr) message.info(msg)
def yank(self, url, context): """Yank an element to the clipboard or primary selection. Args: url: The URL to open as a QUrl. context: The HintContext to use. """ sel = (context.target == Target.yank_primary and utils.supports_selection()) flags = QUrl.FullyEncoded | QUrl.RemovePassword if url.scheme() == 'mailto': flags |= QUrl.RemoveScheme urlstr = url.toString(flags) new_content = urlstr # only second and consecutive yanks are to append to the clipboard if context.rapid and not context.first_run: try: old_content = utils.get_clipboard(selection=sel) except utils.ClipboardEmptyError: pass else: new_content = os.linesep.join([old_content, new_content]) utils.set_clipboard(new_content, selection=sel) msg = "Yanked URL to {}: {}".format( "primary selection" if sel else "clipboard", urlstr) message.info(msg)
def yank(self, url, context): """Yank an element to the clipboard or primary selection. Args: url: The URL to open as a QUrl. context: The HintContext to use. """ sel = context.target == Target.yank_primary and utils.supports_selection() urlstr = url.toString(QUrl.FullyEncoded | QUrl.RemovePassword) utils.set_clipboard(urlstr, selection=sel) msg = "Yanked URL to {}: {}".format("primary selection" if sel else "clipboard", urlstr) message.info(msg)
def yank(self, url, context): """Yank an element to the clipboard or primary selection. Args: url: The URL to open as a QUrl. context: The HintContext to use. """ sel = (context.target == Target.yank_primary and utils.supports_selection()) urlstr = url.toString(QUrl.FullyEncoded | QUrl.RemovePassword) utils.set_clipboard(urlstr, selection=sel) msg = "Yanked URL to {}: {}".format( "primary selection" if sel else "clipboard", urlstr) message.info(msg)
def completion_item_yank(self, sel=False): """Yank the current completion item into the clipboard. Args: sel: Use the primary selection instead of the clipboard. """ text = self._cmd.selectedText() if not text: index = self.currentIndex() if not index.isValid(): raise cmdutils.CommandError("No item selected!") text = self.model().data(index) if not utils.supports_selection(): sel = False utils.set_clipboard(text, selection=sel)
def prompt_yank(self, sel=False): """Yank URL to clipboard or primary selection. Args: sel: Use the primary selection instead of the clipboard. """ question = self._prompt.question if question.url is None: message.error('No URL found.') return if sel and utils.supports_selection(): target = 'primary selection' else: sel = False target = 'clipboard' utils.set_clipboard(question.url, sel) message.info("Yanked to {}: {}".format(target, question.url))
def yank_text(self, text, context): """Yank an element to the clipboard or primary selection. Args: text: The text to open as a QUrl. context: The HintContext to use. """ sel = (context.target == Target.yank_text_primary and utils.supports_selection()) inner = text.inner_xml() utils.set_clipboard(inner, selection=sel) msg = "Yanked text to {}: {}".format( "primary selection" if sel else "clipboard", inner) message.info(msg)