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: Lose the label of the first match #158

Closed ycycyyc closed 1 year ago

ycycyyc commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.2-dev-112+g65fc17b34

Operating system/version

macos 13.04

Describe the bug

In some cases(When I want to adjust the position of the label to the first character of the matching string), the label corresponding to the first matched string cannot be seen.

Steps To Reproduce

  1. Create a new file with the following code:
    
    packge main

func main() { return }

2. open file and search "main" by typing "/", got:
<img width="149" alt="image" src="https://github.com/folke/flash.nvim/assets/30541266/44e9a50a-610f-4852-af17-42bb2ddb1c9d">

3. The label corresponding to the first matching string cannot be seen, while the label corresponding to the second string is 'd'.

### Expected Behavior

May I ask if this is expected behavior and is there a way to display this label?
Can provide a configuration item to show the label if the cursor is on the same position.
code: https://github.com/folke/flash.nvim/blob/v1.17.0/lua/flash/highlight.lua#L118

### Repro

```Lua
local lazypath = vim.fn.stdpath("data") .. "/lazy/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",
                "--branch=stable", -- latest stable release
                lazypath,
        })
end

vim.opt.rtp:prepend(lazypath)

require("lazy").setup({

        {
                "folke/flash.nvim",
                event = "VeryLazy",
                opts = {
                        label = {
                                current = true,
                                after = false, ---@type boolean|number[]
                                before = { 0, 0 }, ---@type boolean|number[]
                        },
                },
        },
})
folke commented 1 year ago

I fixed a related bug so that labels will use the correct hl_group, but this won't fix your issue.

If you do / and then type slowly, you'll see that the label actually gets rendered, but the regular Neovim search then unfortunately quickly overwrites it with the default search highlights.

There doesn't seem to be a proper way to prevent this.

You could try disabling hlsearch, or similar settings, but I'm not sure that will work as intended.

ycycyyc commented 1 year ago

Thanks for the reply! Disabling hlsearch does not take effect after updating this plugin. Looks like it can't be solved.

folke commented 1 year ago

If you use the s mapping, then highlights will be shown correctly

ycycyyc commented 1 year ago

thanks, i'll try it.