endaaman / tym

Lua-configurable terminal emulator
MIT License
185 stars 14 forks source link

Feature Request: Open uri with ctrl + click #83

Closed xlucn closed 2 years ago

xlucn commented 2 years ago

This is my exact problem: I want to use ctrl+button1 to open uris, otherwise treat uris as normal text, for example I can select them with cursor. Something like this from termite.

I tried something like this (and others):

tym.set_hooks({
    ['clicked'] = function(button, uri)
        if uri and button == 1 then
            if tym.check_mod_state('<Ctrl>') then
                tym.open(uri)
            end
            return true
        end
    end,
})

But I can't achieve all these at the same time:

  1. only open uri with ctrl + button1
  2. single click will not trigger uri open
  3. single click will work (e.g. select text) as usual on all text, including uri

The issue is, if the function doesn't return true on single click, the default hook will be triggered and open the uri, but otherwise (return true) clicking does absolutely nothing on url including selecting the text.

endaaman commented 2 years ago

Your request makes sense. Surely, there is no way to disable URI opening but work as normal text , so I fixed the specification.

Please check the diff 4162a328556449a417864a5181c1732e169e44de.

xlucn commented 2 years ago

That works, thanks! I will close this issue then.

P.S. The hook now should be a little different:

tym.set_hooks({
    ['clicked'] = function(button, uri)
        if button == 1 and uri then
            if tym.check_mod_state('<Ctrl>') then
                tym.open(uri)
                return true
            end
        end
    end,
})