Skip to content

Commit

Permalink
refactor(incrementalPreview): only use one hlgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Jun 26, 2024
1 parent b648bc0 commit a073daa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -115,11 +111,7 @@ require("rip-substitute").setup {
insertModeConfirm = "<C-CR>", -- (except this one, obviously)
},
incrementalPreview = {
hlGroups = {
replacement = "IncSearch",
activeSearch = "IncSearch",
inactiveSearch = "LspInlayHint",
},
matchHlGroup = "IncSearch",
rangeBackdrop = {
enabled = true,
blend = 50, -- between 0 and 100
Expand Down
15 changes: 9 additions & 6 deletions lua/rip-substitute/config.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local M = {}
local notify = require("rip-substitute.utils").notify
--------------------------------------------------------------------------------

---@class ripSubstituteConfig
Expand All @@ -23,11 +24,7 @@ local defaultConfig = {
insertModeConfirm = "<C-CR>", -- (except this one, obviously)
},
incrementalPreview = {
hlGroups = {
replacement = "IncSearch",
activeSearch = "IncSearch",
inactiveSearch = "LspInlayHint",
},
matchHlGroup = "IncSearch",
rangeBackdrop = {
enabled = true,
blend = 50, -- between 0 and 100
Expand Down Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions lua/rip-substitute/rg-operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a073daa

Please sign in to comment.