ggandor / leap.nvim

Neovim's answer to the mouse 🦘
MIT License
4.18k stars 45 forks source link

Repeat mappings: leap backward will suddenly only leap forward #202

Open teocns opened 5 months ago

teocns commented 5 months ago

Repeat mappings are bound to Enter and Shift-Enter and work as expected, however Shift-Enter will stop working (under mysterious circumstances) and behave like Enter, the forward movement.

It usually occurs after intensive buffer / window / tab switching, and will never regain functionality on any buffer unless restarting vim.

Any ideas what could be causing this? Any debugging logs you recommend

{
  "ggandor/leap.nvim",
  keys = {
    { "s", mode = { "n", "x", "o" }, desc = "Leap forward to" },
    { "S", mode = { "n", "x", "o" }, desc = "Leap backward to" },
    { "gs", mode = { "n", "x", "o" }, desc = "Leap from windows" },
  },
  config = function(_, opts)
    local leap = require "leap"
    for k, v in pairs(opts) do
      leap.opts[k] = v
    end
    leap.add_default_mappings()
    require("leap").add_repeat_mappings("<enter>", "<s-enter>", {
      relative_directions = true,
      modes = { "n", "x", "o" },
    })
    vim.keymap.del({ "x", "o" }, "x")
    vim.keymap.del({ "x", "o" }, "X")
  end,
}

Output of Redir map <s-enter> after the functionality broke:

o  <S-CR>      * <Lua 2085: ~/.local/share/nvim/lazy/leap.nvim/lua/leap/user.lua:59>
                 Repeat leap in opposite direction
x  <S-CR>      * <Lua 2084: ~/.local/share/nvim/lazy/leap.nvim/lua/leap/user.lua:59>
                 Repeat leap in opposite direction
n  <S-CR>      * <Lua 2083: ~/.local/share/nvim/lazy/leap.nvim/lua/leap/user.lua:59>
                 Repeat leap in opposite direction
ggandor commented 5 months ago

Lazy's keys can cause problems (https://github.com/ggandor/leap.nvim/issues/191), and it's unnecessary, Leap lazy-loads itself, so as a very first step, I'd remove that from the config.

teocns commented 5 months ago

Lazy's keys can cause problems (#191), and it's unnecessary, Leap lazy-loads itself, so as a very first step, I'd remove that from the config.

Will give a try with event = "VeryLazy", though this slightly increases startup time. Keep you posted

teocns commented 5 months ago

Hey @ggandor! Seems that did not change much, the issue persists occasionally and I still could not figure the cause.

One important note: once the issue presents, doesn't matter the direction (bk/fwd), repeating the leap motion in the opposite direction won't work.

Repeating the motion does work; just not in the right direction

For example, I could be leaping forward s{a}{b} <CR> <CR> and then intend to return at the starting position with <S-CR> <S-CR>: under the buggy circumstance it will leap forward twice instead. A fresh motion with S{a}{b} <CR> will begin leaping backwards, but <S-CR> won't leap forward instead, as you'd expect. The functionality is permanently disrupted and restarting neovim is inevitable at this point.

Pasting here current configuration of what I suspect might be interfering.

nvim-surround ``` { "kylechui/nvim-surround", event = "VeryLazy", config = function() require("nvim-surround").setup {} end, -- Commented them out as suggested | nothing has changed -- keys = { -- { "cs",desc = "Change surrounding" }, -- { "ds",desc = "Delete surrounding" }, -- { "ys", mode = { "n", "x", "o" }, desc = "Add surrounding", noremap = true, nowait = true }, -- { "cs",desc = "Change surrounding" }, -- { "ds",desc = "Delete surrounding" }, -- { "ys",desc = "Add surrounding" }, -- }, } ```
leap.nvim ``` { "ggandor/leap.nvim", event = "VeryLazy", config = function(_, opts) local leap = require "leap" for k, v in pairs(opts) do -- brogramerr leap.opts[k] = v end leap.add_default_mappings() require("leap").add_repeat_mappings("", "", { -- False by default. If set to true, the keys will work like the -- native semicolon/comma, i.e., forward/backward is understood in -- relation to the last motion. relative_directions = true, -- By default, all modes are included. modes = { "n", "x", "o" }, }) vim.keymap.del({ "x", "o" }, "x") vim.keymap.del({ "x", "o" }, "X") end, } ```
which-key: require("which-key.health").check() ``` WhichKey: checking conflicting keymaps ~ - WARNING conflicting keymap exists for mode **"n"**, lhs: **" w"** - rhs: ` ` - WARNING conflicting keymap exists for mode **"n"**, lhs: **" a"** - rhs: ` ` - WARNING conflicting keymap exists for mode **"n"**, lhs: **" q"** - rhs: ` ` - WARNING conflicting keymap exists for mode **"n"**, lhs: **" s"** - rhs: ` ` - WARNING conflicting keymap exists for mode **"n"**, lhs: **" uf"** - rhs: ` ` - WARNING conflicting keymap exists for mode **"n"**, lhs: **"ys"** - rhs: `(nvim-surround-normal)` - WARNING conflicting keymap exists for mode **"n"**, lhs: **"yS"** - rhs: `(nvim-surround-normal-line)` - WARNING conflicting keymap exists for mode **"n"**, lhs: **"t"** - rhs: ` ` - WARNING conflicting keymap exists for mode **"n"**, lhs: **"M"** - rhs: ` ` ```
ggandor commented 5 months ago

Okay, next one: use set_repeat_keys instead of add_repeat_mappings (the latter is deprecated, and the former is heavily refactored, doesn't use autocommands at all, so there is some chance it will fix the bug). (Btw add_default_mappings is also deprecated, but that's irrelevant for now.)

Also, what are your settings for opts.special_keys?

teocns commented 5 months ago

Seems it started working with the porposed changed, at least for now! I haven't touched opts.special_keys so it has to be defualt.

Thanks!

teocns commented 5 months ago

Sorry, unfortunately after further usage I've found out that the issue still occurs. What additional info could help you narrow down the scope of the issue?

teocns commented 4 months ago

@ggandor do we have any news on this?

ggandor commented 3 months ago

I cannot reproduce, and I have no further idea about what could be the cause. My hunch is that this is not a Leap problem, but Shift-Enter is somehow not recognized anymore as separate from Enter. It's simple to confirm this, try another key (like backspace) for a while.