From e6ee00d4e76edac8cbcabe0f442a5ec34450d1f6 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 23 Jun 2023 09:13:39 +0200 Subject: [PATCH] feat(config): allow custom window filters. Added non-focusable windows by default --- README.md | 11 ++++++++++- lua/flash/cache.lua | 9 +++++++-- lua/flash/config.lua | 11 ++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 967224d..9d88007 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,16 @@ Install the plugin with your preferred package manager: mode = "exact", -- behave like `incsearch` incremental = false, - filetype_exclude = { "notify", "noice" }, + -- Excluded filetypes and custom window filters + ---@type (string|fun(win:window))[] + exclude = { + "notify", + "cmp_menu", + function(win) + -- exclude non-focusable windows + return not vim.api.nvim_win_get_config(win).focusable + end, + }, -- Optional trigger character that needs to be typed before -- a jump label can be used. It's NOT recommended to set this, -- unless you know what you're doing diff --git a/lua/flash/cache.lua b/lua/flash/cache.lua index ff4a0df..a981c0c 100644 --- a/lua/flash/cache.lua +++ b/lua/flash/cache.lua @@ -101,8 +101,13 @@ function M:_update_wins() wins = vim.tbl_filter(function(w) local buf = vim.api.nvim_win_get_buf(w) local ft = vim.bo[buf].filetype - if ft and vim.tbl_contains(self.state.opts.search.filetype_exclude, ft) then - return false + + for _, exclude in ipairs(self.state.opts.search.exclude) do + if type(exclude) == "string" and exclude == ft then + return false + elseif type(exclude) == "function" and exclude(w) then + return false + end end return w ~= self.state.win end, wins) diff --git a/lua/flash/config.lua b/lua/flash/config.lua index 4e7d75d..97ee1d7 100644 --- a/lua/flash/config.lua +++ b/lua/flash/config.lua @@ -28,7 +28,16 @@ local defaults = { mode = "exact", -- behave like `incsearch` incremental = false, - filetype_exclude = { "notify", "noice", "cmp_menu" }, + -- Excluded filetypes and custom window filters + ---@type (string|fun(win:window))[] + exclude = { + "notify", + "cmp_menu", + function(win) + -- exclude non-focusable windows + return not vim.api.nvim_win_get_config(win).focusable + end, + }, -- Optional trigger character that needs to be typed before -- a jump label can be used. It's NOT recommended to set this, -- unless you know what you're doing