chrishrb / gx.nvim

Implementation of gx without the need of netrw
Apache License 2.0
186 stars 19 forks source link

54 allow selecting handler if there are multiple handlers matching #55

Closed chrishrb closed 3 months ago

reegnz commented 3 months ago

wow, that was fast!

I tested the PR branch with the following two user-defined handlers that match the same URL:

        cve_nist = {
          name = "cve-nist",
          handle = function(mode, line, _)
            local id = require("gx.helper").find(line, mode, "(CVE[%d-]+)")
            if id then
              return "https://nvd.nist.gov/vuln/detail/" .. id
            end
          end,
        },

        cve_details = {
          name = "cve-details",
          handle = function(mode, line, _)
            local id = require("gx.helper").find(line, mode, "(CVE[%d-]+)")
            if id then
              return "https://www.cvedetails.com/cve/" .. id
            end
          end,
        },

Works great!

image
reegnz commented 3 months ago

One nitpick: I think I prefer when doing gx in visual select mode to give me the option to do a google search with the selection. Default could be to just evaluate the other handlers, but allow me to force a google search link if I want to always have that option when visual-selecting.

Eg.: I'm selecting a line that has: This is the CVE-2023-5528. If I just put my cursor on the cve in normal mode it opens the nist database of CVE-s, that's fine. But if I do a visual selection of the line, Maybe I'm interested in the google search results too, otherwise I'd not do a visual selection.

We can take that discussion into a separate issue though, I'm already more than happy with this change as-is.

chrishrb commented 3 months ago

I like that idea, so I added the line of code that was necessary 👍 For simplicity, I suggest not to add another option to turn on/off this behavior.

reegnz commented 3 months ago

Nice, thanks! Just tested and works great.