folke / flash.nvim

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

bug: label highlight group in char mode overrides match #218

Open simonmandlik opened 1 year ago

simonmandlik commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.9.1

Operating system/version

MacOS 13.4.1

Describe the bug

Even if labels are not used in char mode, to properly color matches, one has to use highlight group for label, which also takes precedence over the match one.

Steps To Reproduce

  1. nvim -u repro.lua
  2. Insert "test test"
  3. "ft"

I see the following:

image

that is, highlight group is not used at all.

When I uncomment the label highlight group, both label and match are used, but the foreground is taken from the label hl

image

Expected Behavior

I would expect that defining match would be enough, and see the following:

image

Repro

local root = vim.fn.fnamemodify("./.repro", ":p")
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
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)

local plugins = {
    {
        "folke/flash.nvim",
        opts = {
            modes = {
                char = {
                    jump_labels = false,
                    highlight = {
                        backdrop = false,
                        groups = {
                            match = "Blue",
                            label = "Red",
                        },
                    }
                }
            }
        }
    }
}

require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd[[set termguicolors]]
vim.cmd[[hi Blue guibg=blue guifg=blue]]
vim.cmd[[hi Red guifg=red]]
simonmandlik commented 1 year ago

I dug deeper and the difference can be seen better when running "tt"

image

Now, the label hlg highlights matched character, and the match hlg highlights next positions. I am confused and would expect it to be the other way around

savchenko commented 11 months ago

UPDATE: See the next comment.


The bug is non-obvious until one tries t instead of f.

Might be something to do with the priorities logic? E.g. here cursor is at the search, fe:

image

Looks like the label indeed overwrites both current and match.

:Inspect executed via kbd>@:</kbd with highlights visible reveals that it's there, under the FlashCursor:

image

te makes match highlight group clearly visible:

image

FlashCursor gets inverted when nVim is in focus. Hence it's possible to "fix" this for fF:

image

...but it will be reversed back when using tT:

image

Having separate highlight group for tT or (better!) keeping unified, non-inversed behaviour throughout would help.

savchenko commented 10 months ago

@simonmandlik, think I have solved it. Config below works perfectly as expected:

char = {
    enabled = true,
    keys = { 'f', 'F', 't', 'T' },
    search = { wrap = true },
    jump = { register = false },
    autohide = false,
    jump_labels = false,
    multi_line = true,

    label = {
        style = "overlay",
        current = false,
        after = false,
        before = false,
        distance = false,
    },

    highlight = {
        backdrop = true,
        matches = true,
        priority = 5000,
        groups = {
            label = 'GreenHighlight', -- :hi for f/F
            match = 'GreenHighlight', -- :hi for t/T
        },
    },

You can adjust label and match highlight groups to your own preference.

Screenshots

f/F

ff

image

t/T

t,

image

github-actions[bot] commented 4 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.

simonmandlik commented 4 months ago

please keep

github-actions[bot] commented 3 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.

simonmandlik commented 3 months ago

please keep

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.

simonmandlik commented 2 months ago

please keep

github-actions[bot] commented 1 month 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.

simonmandlik commented 1 month ago

please keep

github-actions[bot] commented 1 week 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.

simonmandlik commented 1 week ago

please keep