diff --git a/lua/grug-far/actions/syncLocations.lua b/lua/grug-far/actions/syncLocations.lua index 8ea7dcda..49e8142b 100644 --- a/lua/grug-far/actions/syncLocations.lua +++ b/lua/grug-far/actions/syncLocations.lua @@ -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 @@ -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 = {} diff --git a/lua/grug-far/rg/getArgs.lua b/lua/grug-far/rg/getArgs.lua index 0063d594..42109844 100644 --- a/lua/grug-far/rg/getArgs.lua +++ b/lua/grug-far/rg/getArgs.lua @@ -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 @@ -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) @@ -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) diff --git a/lua/grug-far/utils.lua b/lua/grug-far/utils.lua index 9c9934f5..8955a6ea 100644 --- a/lua/grug-far/utils.lua +++ b/lua/grug-far/utils.lua @@ -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