folke / flash.nvim

Navigate your code with search labels, enhanced character motions and Treesitter integration
Apache License 2.0
2.47k stars 33 forks source link

bug: unexpected result when using `f` in macro when `multi_line = false` #310

Closed debugloop closed 2 months ago

debugloop commented 8 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.9.5

Operating system/version

NixOS unstable @ ae5c332cbb5827f6b1f02572496b141021de335f

Describe the bug

As the title says, macros don't work quite as expected if multi_line is set to false. See repro.lua and the provided steps.

Steps To Reproduce

  1. nvim -u repro.lua repro.lua
  2. 76Gzz (goto example section)
  3. qafadwj0q (record macro to delete add, reset position on next line)
  4. QQQQ (observe how it fails from the second repetition)
  5. Set multi_line to true or remove it from the config, observe how it works then.

Expected Behavior

Macros should work the same as stock vim and especially independent from seemingly unrelated config.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    "folke/tokyonight.nvim",
    -- add any other plugins here
    {
        "folke/flash.nvim",
        lazy = true,
        keys = {
            "f",
            "F",
            "t",
            "T",
            ";",
            ",",
            {
                "S",
                mode = { "n", "x", "o" },
                function()
                    require("flash").jump()
                end,
                desc = "Flash jump",
            },
            {
                "<c-s>",
                mode = { "c" },
                function()
                    require("flash").toggle()
                end,
                desc = "toggle Flash search",
            },
        },
        opts = {
            modes = {
                search = {
                    enabled = false,
                    highlight = { backdrop = true },
                },
                char = {
                    enabled = true,
                    keys = { "f", "F", "t", "T", ",", ";" },
                    char_actions = function(motion)
                        return {
                            [";"] = "right",
                            [","] = "left",
                            [motion:lower()] = "right",
                            [motion:upper()] = "left",
                        }
                    end,
                    multi_line = false,
                    highlight = { backdrop = false },
                },
            },
        },
    },
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here (start the repro steps here)
-- add anything else here
-- add anything else here
-- add anything else here
-- add anything else here
konosubakonoakua commented 4 months ago

I also encountered macro replay issues with char mode on.

-- aaa 1 bbb 2 ccc 3
-- aaa 1 bbb 2 ccc 3
-- aaa 1 bbb 2 ccc 3
-- aaa 1 bbb 2 ccc 3
-- aaa 1 bbb 2 ccc 3

I recorded a macro to modify all number to #. Press qq for starting, then press 0, then f1r# then f2r# then f3r#, then <esc>. Use @q for replaying, got totally wrong result belowing.

-- aaa # bbb # ccc #
-- aaa # bbb 2 ccc 3
-- aaa # bbb 2 ccc 3
-- aaa # bbb 2 ccc 3
-- aaa 1 bbb 2 ccc 3

It should be

-- aaa # bbb # ccc #
-- aaa # bbb # ccc #
-- aaa 1 bbb 2 ccc 3
-- aaa 1 bbb 2 ccc 3
-- aaa 1 bbb 2 ccc 3

Disable multiline mode not working. Disabling char mode is working.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 2 months ago

This issue was closed because it has been stalled for 7 days with no activity.