nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
6.02k stars 462 forks source link

Bug: Hitting <C-l> does not immediately clear results from searchcount component #1245

Open camoz opened 4 months ago

camoz commented 4 months ago

Self Checks

How to reproduce the problem

  1. have lualine configured to use searchcount component
  2. search something in the buffer, e.g. input /a<CR>
  3. observe how searchcount component becomes visible
  4. press <C-l> to clear highlighting of current search results

Expected behaviour

searchcount component becomes instantly invisible.

Actual behaviour

searchcount component does not become instantly invisible. It becomes invisible after the remaining time until lualine refreshes.

Minimal config to reproduce the issue

Lualine default config with following changes:

require('lualine').setup {
  options = {
    icons_enabled = true,
    theme = 'auto',
    component_separators = { left = '', right = ''},
    section_separators = { left = '', right = ''},
    disabled_filetypes = {
      statusline = {},
      winbar = {},
    },
    ignore_focus = {},
    always_divide_middle = true,
    globalstatus = false,
    refresh = {
      statusline = 3000,
      tabline = 1000,
      winbar = 1000,
    }
  },
  sections = {
    lualine_a = {'mode'},
    lualine_b = {'branch', 'diff', 'diagnostics'},
    lualine_c = {'filename'},
    lualine_x = {'searchcount', 'encoding', 'fileformat', 'filetype'},
    lualine_y = {'progress'},
    lualine_z = {'location'}
  },
  inactive_sections = {
    lualine_a = {},
    lualine_b = {},
    lualine_c = {'filename'},
    lualine_x = {'location'},
    lualine_y = {},
    lualine_z = {}
  },
  tabline = {},
  winbar = {},
  inactive_winbar = {},
  extensions = {}
}

Additional information

Neovim 0.10 by default maps <C-l> to <Cmd>nohlsearch|diffupdate|normal! <C-L><CR>, see :nmap <C-l> and :help default-mappings.

Workaround:

-- Overwrite neovim's <C-l> mapping using : instead of <Cmd>
vim.keymap.set('n', '<C-l>', ':nohlsearch|diffupdate|normal! <C-L><CR>')

I think this works because :, unlike <Cmd>, triggers a mode change, and lualine refreshes on ModeChanged.