debugloop / telescope-undo.nvim

A telescope extension to view and search your undo tree 🌴
MIT License
635 stars 11 forks source link

Unable to disable default key mappings #47

Closed pwnalone closed 6 months ago

pwnalone commented 6 months ago

Description

In Telescope, I have some default key mappings for all pickers, including:

Therefore, I would like to disable telescope-undo's default key mapping of <C-y> and use the one that I have setup in Telescope's default mappings option. I have tried the following configurations, but none of them work.

-- ERROR
opts = {
  extensions = {
    undo = {
      mappings = {
        i = {
          ["<C-y>"] = false,
        },
      },
    },
  },
}
-- ERROR
opts = {
  extensions = {
    undo = {
      mappings = {
        i = {
          ["<C-y>"] = "results_scrolling_up",
        },
      },
    },
  },
}
-- No error, but still doesn't work
opts = function(_, opts)
  opts.extensions = opts.extensions or {}
  opts.extensions.undo = {
    mappings = {
      i = {
        ["<C-y>"] = require("telescope.actions").results_scrolling_up,
      },
    },
  }
  return opts
end

NOTE: The above examples show partial configurations for Telescope using the Lazy plugin manager.

Is it possible to disable the default key mappings, and, if so, how?

Minimal Config

vim.g.mapleader = " "
vim.g.maplocalleader = " "

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  -- stylua: ignore
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  {
    "nvim-telescope/telescope.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "debugloop/telescope-undo.nvim",
    },
    cmd = "Telescope",
    keys = {
      { "<Leader>u", "<Cmd>Telescope undo<CR>" },
    },
    opts = {
      extensions = {
        undo = {
          mappings = {
            i = {
              ["<C-y>"] = false,
            },
          },
        },
      },
    },
    config = function(_, opts)
      require("telescope").setup(opts)
      require("telescope").load_extension("undo")
    end,
  },
})
debugloop commented 6 months ago

I can't test this myself right now, as I'm on vacation and only have my phone available. However, have you tried setting it to nil? Since you've already excellently outlined your issue, it might be sufficient to point you to the places where the configs are merged: https://github.com/debugloop/telescope-undo.nvim/blob/main/lua/telescope/_extensions/undo.lua#L36-L49

If that logic is faulty somehow, it should be in there. But at a glance I'd assume nil wshould work. I'll come around in two weeks time and get my hands on nvim again otherwise, sorry :)

pwnalone commented 6 months ago

Unfortunately, nil would not work because setting a table value to nil in Lua is the same as deleting the value from the table. It's not a huge deal for me to use different keymaps than those I'd prefer for a period of time, so I'm not in any rush to get this fixed, but since you pointed me to the relevant section of the code, I'll see if I can get something working on my own and will submit a PR if so.

Don't feel like you have to review it right away or anything. Enjoy your vacation!

debugloop commented 6 months ago

Ah, I see, thanks for going the extra mile here 🤟🏻

No problem doing that at the moment, I'm stuck on a ferry all day anyway, and reading some code is a nice past time in that case 👍🏻