Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url.yank_ignored_parameters only works for :yank but not for hint links yank #7693

Open
amalgame21 opened this issue May 6, 2023 · 2 comments · May be fixed by #7879
Open

url.yank_ignored_parameters only works for :yank but not for hint links yank #7693

amalgame21 opened this issue May 6, 2023 · 2 comments · May be fixed by #7879
Labels
component: hints Issues related to hinting ("f" key). easy Issues which are likely to be a good fit for first-time contributors. priority: 2 - low Issues which are currently not very important.

Comments

@amalgame21
Copy link

url.yank_ignored_parameters only works for :yank (yy) but not for :hint links yank
It would be greate if it can also be supported. Thanks!

@The-Compiler
Copy link
Member

Agreed it makes sense to support them for both!

The code for :yank is here:

def _yank_url(self, what):
"""Helper method for yank() to get the URL to copy."""
assert what in ['url', 'pretty-url'], what
if what == 'pretty-url':
flags = QUrl.UrlFormattingOption.RemovePassword | QUrl.ComponentFormattingOption.DecodeReserved
else:
flags = QUrl.UrlFormattingOption.RemovePassword | QUrl.ComponentFormattingOption.FullyEncoded
url = QUrl(self._current_url())
url_query = QUrlQuery()
url_query_str = url.query()
if '&' not in url_query_str and ';' in url_query_str:
url_query.setQueryDelimiters('=', ';')
url_query.setQuery(url_query_str)
for key in dict(url_query.queryItems()):
if key in config.val.url.yank_ignored_parameters:
url_query.removeQueryItem(key)
url.setQuery(url_query)
return url.toString(flags) # type: ignore[arg-type]

and the code for hint links yank here:

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.ComponentFormattingOption.FullyEncoded | QUrl.UrlFormattingOption.RemovePassword
if url.scheme() == 'mailto':
flags |= QUrl.UrlFormattingOption.RemoveScheme # type: ignore[operator]
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, replace='rapid-hints' if context.rapid else None)

I suppose it would be good to unify the two a bit, e.g. via a new utility function in qutebrowser/utils/urlutils.py to get the text to yank for a given QUrl.

@The-Compiler The-Compiler added easy Issues which are likely to be a good fit for first-time contributors. component: hints Issues related to hinting ("f" key). priority: 2 - low Issues which are currently not very important. labels May 9, 2023
@amalgame21
Copy link
Author

It would be great if it also apply to :hint all, or provide a switch to do that to open URLs with ignored parameter on new tab by hint, thanks!

michaelfm1211 added a commit to michaelfm1211/qutebrowser that referenced this issue Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: hints Issues related to hinting ("f" key). easy Issues which are likely to be a good fit for first-time contributors. priority: 2 - low Issues which are currently not very important.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants