From ff0e25f63ae98f7ab2735293a40f02e8cfc85d2a Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 8 Jun 2023 12:56:58 +0200 Subject: [PATCH] feat: allow to always render search highlight to prevent flickering when updating ui --- lua/flash/commands.lua | 1 - lua/flash/config.lua | 7 ++++++- lua/flash/highlight.lua | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lua/flash/commands.lua b/lua/flash/commands.lua index 974770b..9263a2b 100644 --- a/lua/flash/commands.lua +++ b/lua/flash/commands.lua @@ -13,7 +13,6 @@ function M.jump(opts) local state = State.new({ config = opts }) while true do - vim.cmd.redraw() local ok, n = pcall(vim.fn.getchar) if not ok then break diff --git a/lua/flash/config.lua b/lua/flash/config.lua index e817e45..888b8f1 100644 --- a/lua/flash/config.lua +++ b/lua/flash/config.lua @@ -27,9 +27,14 @@ local defaults = { -- to search with regular expressions abort_pattern = "[^a-zA-Z0-9_.()]", -- limit matches in a certain direction - direction = nil, ---@type "forward" | "backward" | nil + direction = "both", ---@type "forward" | "backward" | "both" }, ui = { + -- When using flash during search, flash will additionally + -- highlight the matches the same way as the search highlight. + -- This is useful to prevent flickring during search. + -- Especially with plugins like noice.nvim. + always_highlight_search = true, backdrop = true, priority = 500, }, diff --git a/lua/flash/highlight.lua b/lua/flash/highlight.lua index c00bb58..a948a1a 100644 --- a/lua/flash/highlight.lua +++ b/lua/flash/highlight.lua @@ -53,7 +53,7 @@ function M.update(state) for _, match in ipairs(state.results) do local buf = vim.api.nvim_win_get_buf(match.win) - if not state.is_search() then + if not state.is_search() or state.config.ui.always_highlight_search then vim.api.nvim_buf_set_extmark(buf, M.ns, match.from[1] - 1, match.from[2], { end_row = match.to[1] - 1, end_col = match.to[2] + 1,