hydra.nvim icon indicating copy to clipboard operation
hydra.nvim copied to clipboard

`config.exit = true` not working

Open williamhCode opened this issue 8 months ago • 0 comments

Setting config.exit = true doesn't override the default options. The heads for h, e, r doesn't exit, and I have to explicitly set exit to true for each head to achieve the same effect.

image
local toggle_conf = function(key, option)
  return { key, function()
    vim.opt[option] = not vim.o[option]
  end, { desc = option } }
end

Hydra({
  name = "Options",
  hint = [[
    ^ ^        Options
    ^
    _w_ %{wrap} wrap
    _h_ %{hls} hlsearch
    _e_ %{ea} equalalways
    _r_ %{rnu} relative number        ^
  ]],
  config = {
    exit = true,
    invoke_on_body = true,
    hint = {
      funcs = {
        hls = function()
          return vim.o.hlsearch and "[x]" or "[ ]"
        end,
        ea = function()
          return vim.o.equalalways and "[x]" or "[ ]"
        end,
      }
    }
  },
  mode = "n",
  body = "<leader>o",
  heads = {
    { "w", function()
      if vim.o.wrap ~= true then
        vim.o.wrap = true
        vim.keymap.set("n", "k", function()
          return vim.v.count > 0 and "k" or "gk"
        end, { expr = true, desc = "k or gk" })
        vim.keymap.set("n", "j", function()
          return vim.v.count > 0 and "j" or "gj"
        end, { expr = true, desc = "j or gj" })
      else
        vim.o.wrap = false
        vim.keymap.del("n", "k")
        vim.keymap.del("n", "j")
      end
    end, { desc = "wrap", exit = true } },
    toggle_conf("h", "hlsearch"),
    toggle_conf("e", "equalalways"),
    toggle_conf("r", "relativenumber"),
    { "<leader>o", nil, { desc = false, exit = true } },
    { "<Esc>", nil, { desc = false, exit = true } }
  }
})

williamhCode avatar Nov 04 '23 03:11 williamhCode