wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

Adjust hyperlink rules to handle links containing ")" appropriately (#3803)

Open nobeans opened this issue 10 months ago • 6 comments

The current hyperlink rules match eagerly for link that contain ")" like this:

- (http://localhost/foo)
   ^^^^^^^^^^^^^^^^^^^^^ --> "http://localhost/foo)"
- [FOO](http://localhost/foo)
        ^^^^^^^^^^^^^^^^^^^^^ --> "http://localhost/foo)"

This PR makes hyperlink rules match them appropriately like this:

- (http://localhost/foo)
   ^^^^^^^^^^^^^^^^^^^^ --> "http://localhost/foo"
- [FOO](http://localhost/foo)
        ^^^^^^^^^^^^^^^^^^^^ --> "http://localhost/foo"

See #3803 for more context.

nobeans avatar Aug 28 '23 03:08 nobeans

I think this change breaks "normal" links (ie, surrounded by whitespace). I haven't tested the actual patch, but changed my config to include the regex:

config.hyperlink_rules = wezterm.default_hyperlink_rules()
if config.hyperlink_rules[4].regex == "\\b\\w+://\\S+[)/a-zA-Z0-9-]+" then
        config.hyperlink_rules[4].regex = '[^(]\\b(\\w+://\\S+[)/a-zA-Z0-9-]+)'
end

You can see what happens from the logs (patched config, then default config):

16:27:38.527  INFO   wezterm_gui::termwindow > clicking  https://accounts.myq-cloud.com/api/v6.0/accounts
16:27:49.942  INFO   wezterm_gui::termwindow > clicking https://accounts.myq-cloud.com/api/v6.0/accounts

That is, an extra leading space is captured.

I also noticed that any links already in the buffer will not be recalculated, so testing requires something like pasting the link in again, which left me confused for a while. Hopefully I haven't muddled anything up while I've been switching configs around. (Now back to debugging my Home Assistant :))

rcloran avatar Sep 28 '23 23:09 rcloran

I think this change breaks "normal" links

Oh, I messed up -- you even mentioned that problem in the review response to @wez... Adding config.hyperlink_rules[4].format = '$1' and ...highlight = 1 fixes it.

rcloran avatar Sep 29 '23 01:09 rcloran

Hello, any progress here? :))

arcstur avatar Dec 16 '23 12:12 arcstur

I'm not sure either. If there's an issue, I'm open to fixing it...?

nobeans avatar Dec 18 '23 13:12 nobeans

I just haven't had time to review this

wez avatar Dec 20 '23 15:12 wez

I got a similar issue, but the actual link is appended another ".html".

What shows in the console:

  -  For more details, please see the link (https://foo.com/bar/baz.html)

What shows in the chrome address box: https://foo.com/bar/baz.html).html

Tigerfyj avatar Feb 06 '24 07:02 Tigerfyj