Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lens flicker on file write #63

Closed
MunifTanjim opened this issue Jun 2, 2023 · 6 comments
Closed

Lens flicker on file write #63

MunifTanjim opened this issue Jun 2, 2023 · 6 comments

Comments

@MunifTanjim
Copy link

  • nvim --version:
  • Operating system/version:

Describe the bug
A clear and concise description of what the bug is.

To Reproduce using nvim -u mini.lua

Example:
cat mini.lua

-- packer
use {'kevinhwang91/nvim-hlslens'}

require('hlslens').setup()

local kopts = {noremap = true, silent = true}

vim.api.nvim_set_keymap('n', 'n',
    [[<Cmd>execute('normal! ' . v:count1 . 'n')<CR><Cmd>lua require('hlslens').start()<CR>]],
    kopts)
vim.api.nvim_set_keymap('n', 'N',
    [[<Cmd>execute('normal! ' . v:count1 . 'N')<CR><Cmd>lua require('hlslens').start()<CR>]],
    kopts)
vim.api.nvim_set_keymap('n', '*', [[*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', '#', [[#<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', 'g*', [[g*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', 'g#', [[g#<Cmd>lua require('hlslens').start()<CR>]], kopts)

vim.api.nvim_set_keymap('x', '*', [[*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('x', '#', [[#<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('x', 'g*', [[g*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('x', 'g#', [[g#<Cmd>lua require('hlslens').start()<CR>]], kopts)

vim.api.nvim_set_keymap('n', '<Leader>l', ':noh<CR>', kopts)

Steps to reproduce the behavior:

  1. Search for something using * or /
  2. Clear highlight using :nohl
  3. Write the file using :w
  4. Keep repeating step 3, sometimes the highlights and lens will be visible for a short time

Expected behavior

Saving a file shouldn't cause flicker.

Screenshots
If applicable, add screenshots to help explain your problem.

Kapture 2023-06-02 at 16 15 39

Additional context
Add any other context about the problem here.

event:on('CmdlineLeave', function(e)
local typ, abort = e.cmdtype, e.abort
self:detach(typ, abort)
render:start(true)
end, self.disposables)

The flicker is triggered from this code.

@kevinhwang91
Copy link
Owner

Can't reproduce it, maybe some script change your hlsearch.

@MunifTanjim
Copy link
Author

MunifTanjim commented Jun 2, 2023

Okay, I reproduced it like this:

  vim.api.nvim_create_autocmd("BufWritePre", {
    callback = function()
      vim.wait(2000)
    end,
  })
  • Search for something using * or /
  • Clear highlight using :nohl
  • Write the file using :w
  • When the vim.wait is happening, move the cursor (e.g. press j)
  • Every once in a while search highlight and lens will flicker

Here vim.wait(2000) is artificially delaying the file save. But in my actual config it happens because of lsp code formatting that runs before the buffer is written.

Kapture 2023-06-02 at 22 28 37

@kevinhwang91
Copy link
Owner

Sorry, still can't rerpoduce it.

@mortymacs
Copy link

mortymacs commented Jun 4, 2024

I have the same problem. When I save a file, it shows the lens quickly on every line and then disappears.
My config:

require("hlslens").setup()

Nvim version:

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1693350652

@Rekwass
Copy link

Rekwass commented Sep 20, 2024

I am able to reproduce the issue with the following config:
minimal.lua

vim.env.LAZY_STDPATH = '.repro'
load(vim.fn.system('curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua'))()

vim.api.nvim_create_autocmd("BufWritePre", {
    callback = function()
        vim.wait(10)
        vim.cmd("m +1")
        vim.cmd("m -2")
    end,
})

require('lazy.minit').repro {
    spec = {
        {
            'kevinhwang91/nvim-hlslens',
            config = function()
                require('hlslens').setup()
            end,
            lazy = false,
        },
    },
}

NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1725453128

In order to see the flickering follow these steps:

  1. Create a file and add a couple lines to highlight
    main.cpp
int main() {
  int foo = 1;
  int bar = 2;

  int foobar = foo + bar;

  return foobar;
}
  1. Open this file with the minimal.lua configuration with nvim --clean -u minimal.lua main.cpp
  2. Highlight a word. int for example
  3. Then disable highlight with :noh
  4. Save the file with :w. Repeat this step as it is really inconsistent

nvim-hlslens highlight flickering

I worked around the issue with this answer on stackoverflow.

@kevinhwang91
Copy link
Owner

I am able to reproduce the issue with the following config: minimal.lua

vim.env.LAZY_STDPATH = '.repro'
load(vim.fn.system('curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua'))()

vim.api.nvim_create_autocmd("BufWritePre", {
    callback = function()
        vim.wait(10)
        vim.cmd("m +1")
        vim.cmd("m -2")
    end,
})

require('lazy.minit').repro {
    spec = {
        {
            'kevinhwang91/nvim-hlslens',
            config = function()
                require('hlslens').setup()
            end,
            lazy = false,
        },
    },
}

NVIM v0.10.1 Build type: Release LuaJIT 2.1.1725453128

In order to see the flickering follow these steps:

  1. Create a file and add a couple lines to highlight
    main.cpp
int main() {
  int foo = 1;
  int bar = 2;

  int foobar = foo + bar;

  return foobar;
}
  1. Open this file with the minimal.lua configuration with nvim --clean -u minimal.lua main.cpp
  2. Highlight a word. int for example
  3. Then disable highlight with :noh
  4. Save the file with :w. Repeat this step as it is really inconsistent

nvim-hlslens highlight flickering nvim-hlslens highlight flickering

I worked around the issue with this answer on stackoverflow.

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants