MagicDuck / grug-far.nvim

Find And Replace plugin for neovim
MIT License
832 stars 25 forks source link

A directory path in `Flags` appends extra text to files #154

Closed mikavilpas closed 3 months ago

mikavilpas commented 3 months ago

Just discovered something weird. If I replace some text in files and have the Flags field set to ., the replacing seems to append extra contents at the end of the file.

Reproduction script (run with nvim -u repro.lua):

Details

```lua -- You can use this file to reproduce an issue with your configuration. local root = vim.fn.fnamemodify('./.repro', ':p') -- set stdpaths to use .repro for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name end -- bootstrap lazy local lazypath = root .. '/plugins/lazy.nvim' if not vim.loop.fs_stat(lazypath) then vim.fn.system({ 'git', 'clone', '--filter=blob:none', 'https://github.com/folke/lazy.nvim.git', lazypath, }) end vim.opt.runtimepath:prepend(lazypath) vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- install the following plugins ---@type LazySpec local plugins = { 'folke/tokyonight.nvim', { -- same initialization as in LazyVim -- https://github.com/LazyVim/LazyVim/blob/bcbab77f0c5851e6d73f275f2d27c3baa4f6aa68/lua/lazyvim/plugins/editor.lua#L130C1-L151C5 'MagicDuck/grug-far.nvim', opts = { headerMaxWidth = 80 }, cmd = 'GrugFar', keys = { { 'sr', function() local grug = require('grug-far') local ext = vim.bo.buftype == '' and vim.fn.expand('%:e') grug.grug_far({ transient = true, prefills = { filesFilter = ext and ext ~= '' and '*.' .. ext or nil, }, }) end, mode = { 'n', 'v' }, desc = 'Search and Replace', }, }, }, } require('lazy').setup(plugins, { root = root .. '/plugins', }) vim.cmd.colorscheme('tokyonight') -- add anything else here ```

I ran this and replaced with r (space r) image

It seems to add other files in the directory to the end image

My global .rgignore

.git
.oh-my-zsh/
node_modules
MagicDuck commented 3 months ago

So I ended up doing some thinking about this and due to the way things are structured for replace, the reliable way to make things work and also reduce confusion is to add another field, Paths: to the UI. Here is an example:

image

This change is now in!

You can fill that input with the prefills.paths option, and it can contain multiple paths separated by space. Also, it supports paths containing spaces with the following syntax: ./john\ doe/subdir/

Here's another screenshots with empty, placeholder showing supported syntax:

image
MagicDuck commented 3 months ago

Let me know if that works for you! 😄

mikavilpas commented 3 months ago

Thanks, it seems to resolve this issue!

MagicDuck commented 3 months ago

great! Thanks for confirming!