diff --git a/lua/spectre/replace/sed.lua b/lua/spectre/replace/sed.lua index e81ca9e..d76e325 100644 --- a/lua/spectre/replace/sed.lua +++ b/lua/spectre/replace/sed.lua @@ -33,7 +33,7 @@ sed.replace = function(self, value) utils.escape_sed(value.search_text), utils.escape_sed(value.replace_text) ) - local args = vim.tbl_flatten({ + local args = utils.tbl_flatten({ self.state.args, t_sed, value.filename, diff --git a/lua/spectre/search/base.lua b/lua/spectre/search/base.lua index 1ac3889..7ff1341 100644 --- a/lua/spectre/search/base.lua +++ b/lua/spectre/search/base.lua @@ -1,5 +1,4 @@ ---@diagnostic disable: param-type-mismatch -local flatten = vim.tbl_flatten local Job = require('plenary.job') local log = require('spectre._log') local MAX_LINE_CHARS = 255 @@ -84,7 +83,7 @@ base.on_exit = function(self, value) end base.search = function(self, query) - local args = flatten({ + local args = utils.tbl_flatten({ -- query.search_text, self.state.args, }) @@ -99,7 +98,7 @@ base.search = function(self, query) -- no more args table.insert(args, '--') - args = flatten(args) + args = utils.tbl_flatten(args) if query.cwd == '' then query.cwd = nil diff --git a/lua/spectre/utils.lua b/lua/spectre/utils.lua index 4c6c116..3cdf55a 100644 --- a/lua/spectre/utils.lua +++ b/lua/spectre/utils.lua @@ -216,4 +216,9 @@ M.tbl_remove_dup = function(tbl) end return res end + +M.tbl_flatten = function(t) + return vim.fn.has('nvim-0.11') == 1 and vim.iter(t):flatten(math.huge):totable() or vim.tbl_flatten(t) +end + return M