chipsenkbeil / org-roam.nvim

Port of org-roam to neovim using orgmode
MIT License
107 stars 9 forks source link

[TRACKER] hyperlink highlighting w/ mouse #3

Closed chipsenkbeil closed 6 months ago

chipsenkbeil commented 6 months ago
  1. Requires enabling vim.opt.mousemoveevent = true, which is off by default.
  2. Sets a buffer-level keymap in normal mode for <MouseMove>.
  3. Uses vim.fn.getmousepos() to give us a position within a window, which we then translate to figure out if we're over a link.
  4. For 3, we need a org-roam.utils.link_under_cursor function to give us a link object.

From piemenu/example.lua:

vim.api.nvim_create_autocmd({ "FileType" }, {
  group = group,
  pattern = { "piemenu" },
  callback = function()
    vim.o.mousemoveevent = true
    vim.keymap.set("n", "<MouseMove>", [[<Cmd>lua require("piemenu").highlight()<CR>]], { buffer = true })
    vim.keymap.set("n", "<LeftDrag>", [[<Cmd>lua require("piemenu").highlight()<CR>]], { buffer = true })
    vim.keymap.set("n", "<LeftRelease>", [[<Cmd>lua require("piemenu").finish()<CR>]], { buffer = true })
    vim.keymap.set("n", "<RightMouse>", [[<Cmd>lua require("piemenu").cancel()<CR>]], { buffer = true })
  end,
})
chipsenkbeil commented 6 months ago

An issue I found is that the mousemove event only triggers when the buffer is in focus. I'm wondering if this needs to be a global autocmd and then we detect which buffer we're over.

chipsenkbeil commented 6 months ago

Resolved by #10 where it seems that attaching to buffers for keymappings does work for mouse despite buffers being unfocused. It also added a lot more custom logic to handle detecting when the mouse is over the concealed text and not the raw text.