folke / flash.nvim

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

bug: vim.highlight.on_yank not triggered #122

Closed ranebrown closed 1 year ago

ranebrown commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.10.0-dev-617+g2d40f5e84

Operating system/version

macOS 13.4.1

Describe the bug

The TextYankPost autocommand calling vim.highlight.on_yank({ higroup = "Visual", on_visual = false }) does not seem to be triggered when using flash.

Steps To Reproduce

  1. Type any text and then do yt<char> and the yanked text is not highlighted
  2. Operation like yy correctly highlights the yanked line

Expected Behavior

Text is highlighted on yank.

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",
    {
        "folke/flash.nvim",
        opts = {
            modes = {
                char = {
                    jump_labels = true,
                    config = function(opts)
                        local op_pend = vim.fn.mode(true):find("no")
                        local skip_op = vim.v.operator == "y" or vim.v.operator == "d"
                        local should_hide = op_pend and skip_op
                        opts.autohide = should_hide
                        opts.jump_labels = opts.jump_labels
                            and vim.v.count == 0
                            and not should_hide
                    end,
                    highlight = { backdrop = false },
                },
            },
        },
    },
    -- add any other plugins here
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

vim.api.nvim_create_autocmd({ "TextYankPost" }, {
    pattern = { "*" },
    callback = function()
        vim.highlight.on_yank({ higroup = "Visual", on_visual = false })
    end,
})
folke commented 1 year ago

That's because you set yank highlights for visual to false