luukvbaal / statuscol.nvim

Status column plugin that provides a configurable 'statuscolumn' and click handlers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make clickhandlers config table more granular

axieax opened this issue · comments

Hi, thanks for the awesome plugin!

I'm looking to customize the right click action on the foldcolumn since I'm using the treesitter foldexpr so folds cannot be deleted anyways. My desired behavior is to open a fold preview using the fold-preview.nvim plugin when I right click on a fold character. However, I'm having trouble overriding the default behaviour, especially since the builtin FoldOpen and FoldClose clickhandlers are separate and both use a private function.

Is there a way to easily achieve the desired customization? Thanks in advance!

Currently if you overwrite a clickhandler you need to implement all buttons/modifiers in it.
So you would indeed need to copy the builtin handlers in your cfg.clickhandlers.FoldOpen/Close and modify what you want to change.

Perhaps we can refactor the clickhandler config to contain button/modifier tables to make overwriting a single button simpler.

I'm not sure we want to do that though. It gets quite messy, in terms of documentation and implementation...
What you want is possible, you just have to refactor the private function to its 3 separate Open/Close/Other clauses modify the right click part.

It would be nice if the function used for each click can be exposed publically, so they can be easily overridden, such as like this.

They are exposed publicly. The fold builtin actions just map to the same action so they call a common (private) function. That doesn't stop you from changing i.e. the FoldOpen handler separately.

Sorry I was referring to "functions for each click" such as this.

An alternative solution could be to allow users to customize the click callback function directly on each component, and handle the Lua function mappings behind the scene.

Well yeah I started implementing that when you opened this issue. But it doesn't allow you to do anything that is not already possible, would be a breaking change and make the default options table/documentation a lot more convoluted. I'm not sure if it's worth it.

An alternative solution could be to allow users to customize the click callback function directly on each component

I'm not sure what you mean by this btw, that sounds exactly like what is possible now.

But yeah I don't think I want to facilitate configuring each button separately through cfg.clickhandlers. That would result in an unruly large config table (too large for documentation I think). This times 16 currently:

   cfg.clickhandlers = {
-    Lnum                    = builtin.lnum_click,
+    Lnum = {
+      l = builtin.lnum_l_click,
+      m = builtin.lnum_m_click,
+      r = builtin.lnum_r_click,
+    },

Just configure FoldOpen/Close directly and include each button you want to overwrite:

require("statuscol").setup({
  clickhandlers = {
    FoldOpen = function(args)
      if args.button == "l" then
        vim.cmd("norm! z"..(args.mods:find("c") and "O" or "o"))
      elseif args.button == "r" then
        require("fold-preview").toggle_preview()
      end
    end,
  }
})

I guess the default cfg.clickhandlers could be omitted from the documentation though. The table at the bottom of the README conveys the same information. I'll reconsider once more.

Thanks, this was much simpler than I thought :))