nvim-hlslens icon indicating copy to clipboard operation
nvim-hlslens copied to clipboard

Lens flicker on file write

Open MunifTanjim opened this issue 2 years ago • 4 comments
trafficstars

  • 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.

https://github.com/kevinhwang91/nvim-hlslens/blob/5e3e9088fba7508cee3612ee50b14dfdd3ab19af/lua/hlslens/cmdline/init.lua#L330-L334

The flicker is triggered from this code.

MunifTanjim avatar Jun 02 '23 10:06 MunifTanjim

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

kevinhwang91 avatar Jun 02 '23 11:06 kevinhwang91

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

MunifTanjim avatar Jun 02 '23 16:06 MunifTanjim

Sorry, still can't rerpoduce it.

kevinhwang91 avatar Jun 06 '23 10:06 kevinhwang91

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

mortymacs avatar Jun 04 '24 10:06 mortymacs