From 2409cabadf873fe432fbdc64016b0a90f5067970 Mon Sep 17 00:00:00 2001 From: Chris Grieser <73286100+chrisgrieser@users.noreply.github.com> Date: Wed, 5 Jun 2024 01:28:01 +0200 Subject: [PATCH] refactor: more variable name improvements --- lua/rip-substitute/popup-win.lua | 6 +++--- lua/rip-substitute/rg-operations.lua | 8 ++++---- lua/rip-substitute/state.lua | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lua/rip-substitute/popup-win.lua b/lua/rip-substitute/popup-win.lua index 54f3ec8..a2a4714 100644 --- a/lua/rip-substitute/popup-win.lua +++ b/lua/rip-substitute/popup-win.lua @@ -36,7 +36,7 @@ local function closePopupWin() if vim.api.nvim_buf_is_valid(state.popupBufNr) then vim.api.nvim_buf_delete(state.popupBufNr, { force = true }) end - vim.api.nvim_buf_clear_namespace(0, state.matchHlNs, 0, -1) + vim.api.nvim_buf_clear_namespace(0, state.incPreviewNs, 0, -1) end function M.substitute() @@ -47,7 +47,7 @@ function M.substitute() targetBuf = vim.api.nvim_get_current_buf(), targetWin = vim.api.nvim_get_current_win(), labelNs = vim.api.nvim_create_namespace("rip-substitute-labels"), - matchHlNs = vim.api.nvim_create_namespace("rip-substitute-match-hls"), + incPreviewNs = vim.api.nvim_create_namespace("rip-substitute-incpreview"), targetFile = vim.api.nvim_buf_get_name(0), popupBufNr = -999, -- placeholder value popupWinNr = -999, -- placeholder value @@ -109,7 +109,7 @@ function M.substitute() group = vim.api.nvim_create_augroup("rip-substitute-popup-changes", {}), callback = function() ensureOnly2LinesInPopup() - rg.highlightMatches() + rg.incrementalPreview() setPopupLabels() end, }) diff --git a/lua/rip-substitute/rg-operations.lua b/lua/rip-substitute/rg-operations.lua index bf8a09f..c1d2996 100644 --- a/lua/rip-substitute/rg-operations.lua +++ b/lua/rip-substitute/rg-operations.lua @@ -91,9 +91,9 @@ local function onEachRgResultInViewport(rgArgs, callback) :each(callback) end -function M.highlightMatches() +function M.incrementalPreview() local state = require("rip-substitute.state").state - vim.api.nvim_buf_clear_namespace(state.targetBuf, state.matchHlNs, 0, -1) + vim.api.nvim_buf_clear_namespace(state.targetBuf, state.incPreviewNs, 0, -1) local toSearch, toReplace = getSearchAndReplace() if toSearch == "" then return end @@ -103,7 +103,7 @@ function M.highlightMatches() local endCol = result.col + #result.text vim.api.nvim_buf_add_highlight( state.targetBuf, - state.matchHlNs, + state.incPreviewNs, toReplace == "" and "IncSearch" or "LspInlayHint", result.lnum, result.col, @@ -118,7 +118,7 @@ function M.highlightMatches() local virtText = { result.text, "IncSearch" } vim.api.nvim_buf_set_extmark( state.targetBuf, - state.matchHlNs, + state.incPreviewNs, result.lnum, result.col, { virt_text = { virtText }, virt_text_pos = "inline" } diff --git a/lua/rip-substitute/state.lua b/lua/rip-substitute/state.lua index 42560f0..43ec7d3 100644 --- a/lua/rip-substitute/state.lua +++ b/lua/rip-substitute/state.lua @@ -7,7 +7,7 @@ local M = {} ---@field popupBufNr number ---@field popupWinNr number ---@field labelNs number ----@field matchHlNs number +---@field incPreviewNs number M.state = {} ---@param newState ripSubstituteState