Skip to content

Commit

Permalink
disabling sync for multiline search / replace
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Badragan committed May 13, 2024
1 parent 9ef931a commit 9673a36
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
20 changes: 20 additions & 0 deletions lua/grug-far/actions/syncLocations.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local renderResultsHeader = require('grug-far/render/resultsHeader')
local resultsList = require('grug-far/render/resultsList')
local utils = require('grug-far/utils')
local uv = vim.loop

-- note: this could use libuv and do async io if we find we need the perf boost
Expand Down Expand Up @@ -106,11 +107,30 @@ local function getActionMessage(err, count, total, time)
return msg .. count .. ' / ' .. total .. ' (buffer temporarily not modifiable)'
end

local function isMultilineSearchReplace(context)
local inputs = context.state.inputs
local multilineFlags = { '--multiline', '-U' }
if #inputs.flags > 0 then
for flag in string.gmatch(inputs.flags, "%S+") do
if utils.isBlacklistedFlag(flag, multilineFlags) then
return true
end
end
end
end


local function syncLocations(params)
local buf = params.buf
local context = params.context
local state = context.state
local startTime = uv.now()
if isMultilineSearchReplace(context) then
state.actionMessage = 'sync disabled for multline search/replace!'
renderResultsHeader(buf, context)
vim.notify('grug-far: ' .. state.actionMessage, vim.log.levels.INFO)
return
end

local extmarks = vim.api.nvim_buf_get_extmarks(0, context.locationsNamespace, 0, -1, {})
local changedFilesByFilename = {}
Expand Down
19 changes: 3 additions & 16 deletions lua/grug-far/rg/getArgs.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
local function isBlacklistedFlag(flag, blacklistedFlags)
if not blacklistedFlags then
return false
end

for i = 1, #blacklistedFlags do
local badFlag = blacklistedFlags[i]
if flag == badFlag or vim.startswith(flag, badFlag .. ' ') or vim.startswith(flag, badFlag .. '=') then
return true
end
end

return false
end
local utils = require('grug-far/utils')

local function getArgs(inputs, options, extraArgs, blacklistedFlags)
if #inputs.search < (options.minSearchChars or 1) then
Expand All @@ -25,7 +12,7 @@ local function getArgs(inputs, options, extraArgs, blacklistedFlags)
local extraUserArgs = options.extraRgArgs and vim.trim(options.extraRgArgs) or ''
if #extraUserArgs > 0 then
for arg in string.gmatch(extraUserArgs, "%S+") do
if isBlacklistedFlag(arg, blacklistedFlags) then
if utils.isBlacklistedFlag(arg, blacklistedFlags) then
table.insert(blacklisted, arg)
else
table.insert(args, arg)
Expand All @@ -35,7 +22,7 @@ local function getArgs(inputs, options, extraArgs, blacklistedFlags)

if #inputs.flags > 0 then
for flag in string.gmatch(inputs.flags, "%S+") do
if isBlacklistedFlag(flag, blacklistedFlags) then
if utils.isBlacklistedFlag(flag, blacklistedFlags) then
table.insert(blacklisted, flag)
else
table.insert(args, flag)
Expand Down
15 changes: 15 additions & 0 deletions lua/grug-far/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,19 @@ function M.strEllideAfter(str, n, prefix)
return (prefix or '') .. (#str > n and string.sub(str, 1, n) .. '...' or str)
end

function M.isBlacklistedFlag(flag, blacklistedFlags)
if not blacklistedFlags then
return false
end

for i = 1, #blacklistedFlags do
local badFlag = blacklistedFlags[i]
if flag == badFlag or vim.startswith(flag, badFlag .. ' ') or vim.startswith(flag, badFlag .. '=') then
return true
end
end

return false
end

return M

0 comments on commit 9673a36

Please sign in to comment.