From a073daa268b2c910fea5a50d00e40353159d4e3b Mon Sep 17 00:00:00 2001 From: Chris Grieser <73286100+chrisgrieser@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:50:21 +0200 Subject: [PATCH] refactor(incrementalPreview): only use one hlgroup --- README.md | 10 +--------- lua/rip-substitute/config.lua | 15 +++++++++------ lua/rip-substitute/rg-operations.lua | 8 +++----- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 86f0856..da5ab35 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,6 @@ Search & replace in the current buffer with a modern UI and modern regex flavor. A substitute for vim's `:substitute` using `ripgrep`. -> [!NOTE] -> This plugin is still in early development. Its features and options are -> subject to change. - https://github.com/chrisgrieser/nvim-rip-substitute/assets/73286100/4afad8d8-c0d9-4ba6-910c-0510d4b9b669 ## Table of Contents @@ -115,11 +111,7 @@ require("rip-substitute").setup { insertModeConfirm = "", -- (except this one, obviously) }, incrementalPreview = { - hlGroups = { - replacement = "IncSearch", - activeSearch = "IncSearch", - inactiveSearch = "LspInlayHint", - }, + matchHlGroup = "IncSearch", rangeBackdrop = { enabled = true, blend = 50, -- between 0 and 100 diff --git a/lua/rip-substitute/config.lua b/lua/rip-substitute/config.lua index 56c61cb..7f22f03 100644 --- a/lua/rip-substitute/config.lua +++ b/lua/rip-substitute/config.lua @@ -1,4 +1,5 @@ local M = {} +local notify = require("rip-substitute.utils").notify -------------------------------------------------------------------------------- ---@class ripSubstituteConfig @@ -23,11 +24,7 @@ local defaultConfig = { insertModeConfirm = "", -- (except this one, obviously) }, incrementalPreview = { - hlGroups = { - replacement = "IncSearch", - activeSearch = "IncSearch", - inactiveSearch = "LspInlayHint", - }, + matchHlGroup = "IncSearch", rangeBackdrop = { enabled = true, blend = 50, -- between 0 and 100 @@ -59,7 +56,13 @@ function M.setup(userConfig) local fallback = defaultConfig.popupWin.border M.config.popupWin.border = fallback local msg = ('Border "none" is not supported, falling back to %q'):format(fallback) - require("rip-substitute.utils").notify(msg, "warn") + notify(msg, "warn") + end + + -- DEPRECATION + if M.config.incrementalPreview.hlGroups then + local msg = "`incrementalPreview.hlGroups.{name}` is deprecated, use `incrementalPreview.matchHlGroup` instead." + notify(msg, "warn") end end diff --git a/lua/rip-substitute/rg-operations.lua b/lua/rip-substitute/rg-operations.lua index 551542b..ed551d7 100644 --- a/lua/rip-substitute/rg-operations.lua +++ b/lua/rip-substitute/rg-operations.lua @@ -96,13 +96,11 @@ function M.incrementalPreviewAndMatchCount(viewStartLnum, viewEndLnum) local state = require("rip-substitute.state").state state.matchCount = 0 vim.api.nvim_buf_clear_namespace(state.targetBuf, state.incPreviewNs, 0, -1) + local hlGroup = require("rip-substitute.config").config.incrementalPreview.matchHlGroup local toSearch, toReplace = getSearchAndReplaceValuesFromPopup() if toSearch == "" then return end - local opts = require("rip-substitute.config").config.incrementalPreview - local hl = opts.hlGroups - -- DETERMINE MATCHES local rgArgs = { toSearch, "--line-number", "--column", "--only-matching" } local code, searchMatches = runRipgrep(rgArgs) @@ -152,7 +150,7 @@ function M.incrementalPreviewAndMatchCount(viewStartLnum, viewEndLnum) vim.api.nvim_buf_add_highlight( state.targetBuf, state.incPreviewNs, - hl.activeSearch, + hlGroup, match.lnum, match.col, matchEndCol @@ -182,7 +180,7 @@ function M.incrementalPreviewAndMatchCount(viewStartLnum, viewEndLnum) vim.iter(replacements):slice(viewStartIdx, viewEndIdx):map(parseRgResult):each(function(repl) local matchEndCol = table.remove(matchEndcolsInViewport, 1) - local virtText = { repl.text, hl.replacement } + local virtText = { repl.text, hlGroup } vim.api.nvim_buf_set_extmark( state.targetBuf, state.incPreviewNs,