Skip to content

Commit

Permalink
refactor: better function names
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Jun 6, 2024
1 parent b75af1f commit 3a89922
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lua/rip-substitute/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local M = {}
---@param userConfig? ripSubstituteConfig
function M.setup(userConfig) require("rip-substitute.config").setup(userConfig) end

function M.sub() require("rip-substitute.popup-win").substitute() end
function M.sub() require("rip-substitute.popup-win").openSubstitutionPopup() end

--------------------------------------------------------------------------------
return M
2 changes: 1 addition & 1 deletion lua/rip-substitute/popup-win.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ local function closePopupWin()
vim.api.nvim_buf_clear_namespace(0, state.incPreviewNs, 0, -1)
end

function M.substitute()
function M.openSubstitutionPopup()
-- IMPORTS & INITIALIZATION
local rg = require("rip-substitute.rg-operations")
local config = require("rip-substitute.config").config
Expand Down
12 changes: 6 additions & 6 deletions lua/rip-substitute/rg-operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end

---@return string
---@return string
local function getSearchAndReplace()
local function getSearchAndReplaceValuesFromPopup()
local config = require("rip-substitute.config").config
local state = require("rip-substitute.state").state

Expand All @@ -32,7 +32,7 @@ end
function M.executeSubstitution()
local state = require("rip-substitute.state").state
local config = require("rip-substitute.config").config
local toSearch, toReplace = getSearchAndReplace()
local toSearch, toReplace = getSearchAndReplaceValuesFromPopup()

-- notify on count
if config.notificationOnSuccess then
Expand Down Expand Up @@ -66,7 +66,7 @@ end

---@param rgArgs string[]
---@return Iter { lnum: number, col: number, text: string }
local function rgResultsIter(rgArgs)
local function rgResultsInViewportIter(rgArgs)
local rgResult = runRipgrep(rgArgs)
if rgResult.code ~= 0 then return vim.iter {} end -- empty iter on error
local rgLines = vim.split(vim.trim(rgResult.stdout), "\n")
Expand All @@ -93,13 +93,13 @@ end
function M.incrementalPreview()
local state = require("rip-substitute.state").state
vim.api.nvim_buf_clear_namespace(state.targetBuf, state.incPreviewNs, 0, -1)
local toSearch, toReplace = getSearchAndReplace()
local toSearch, toReplace = getSearchAndReplaceValuesFromPopup()
if toSearch == "" then return end

-- HIGHLIGHT SEARCH MATCHES
local rgArgs = { toSearch, "--line-number", "--column", "--only-matching" }
local searchMatchEndCols = {}
rgResultsIter(rgArgs):each(function(result)
rgResultsInViewportIter(rgArgs):each(function(result)
local endCol = result.col + #result.text
vim.api.nvim_buf_add_highlight(
state.targetBuf,
Expand All @@ -119,7 +119,7 @@ function M.incrementalPreview()
if toReplace == "" then return end

vim.list_extend(rgArgs, { "--replace=" .. toReplace })
rgResultsIter(rgArgs):each(function(result)
rgResultsInViewportIter(rgArgs):each(function(result)
local virtText = { result.text, "IncSearch" }
local endCol = table.remove(searchMatchEndCols, 1)
vim.api.nvim_buf_set_extmark(
Expand Down

0 comments on commit 3a89922

Please sign in to comment.