diffconflicts icon indicating copy to clipboard operation
diffconflicts copied to clipboard

Compatibility with folding

Open giuseppelettieri opened this issue 1 year ago • 2 comments

Thank you for this really useful plugin. However, I am getting confusing results when folding is enabled. I think that the :g commands don't look inside the folds, so they may delete unintended lines when the diff markers somehow end up inside a fold. I have solved the issue by adding silent execute "normal! zR" and silent execute "normal! zM" around the delete commands, but I am no vimscript expert by any means and I guess there should be a better way.

giuseppelettieri avatar Jan 26 '24 16:01 giuseppelettieri

Hi! I'm glad you like it and thanks for the report. I need a bit more information, or perhaps a way to reproduce the problem, because that raises questions for me:

  1. Folds are entirely cosmetic and shouldn't affect :g at all, so it's interesting that showing/hiding folds solves the problem for you -- I wonder if something is causing the diffconflicts commands to get run at the wrong time or on the wrong buffer and folding is having some affect on that.

    Can you think of any plugins or autocommands in your config that may reposition the cursor when creating splits or new buffers, possibly for specific filetypes?

  2. What kind of folding is affecting that file? Vimdiff functionality usually(?) turns on diff folding to hide everything but the conflicts. I wonder if some kind of filetype-specific folding is taking precedence and causing trouble.

    If it's filetype-specific you might be able to see different behavior with a different kind of file. You can try the text file attached below by opening it directly then running :DiffConflicts once it's open. Does it behave the same broken way or not?

poem.txt

whiteinge avatar Jan 27 '24 03:01 whiteinge

Hi @whiteinge , thanks for the reply. I have moved away my ~/.vim directory and tried with a clean vim as distributed in Ubuntu 23.04 (2:9.0.1000-4ubuntu3.3). I can reproduce the effect with the following small file

void f() {
<<<<<<< A
        x++;
=======
        x--;
>>>>>>> B
}
<<<<<<< C
int y;
=======
double y;
>>>>>>> D
int z;

I load the file, set its filetype to C, and then set foldmethod=syntax. The f() function gets folded, hiding the diff markers inside it. Now I run :g/^<<<<<<< /,/^=======\r\?$/d and this is the result:

void f() {
double y;
>>>>>>> D
int z;

It looks like vim saw the <<<<<<< inside f(), but then missed the first ======= and went straight to the second one. If I open the folds before running :g I get the expected result:

void f() {
        x--;
>>>>>>> B
}
double y;
>>>>>>> D
int z;

It looks like a bug in vim to me, since it is inconsistent in what it sees or doesn't see.

giuseppelettieri avatar Jan 27 '24 14:01 giuseppelettieri

Thanks, those steps are great and I can reproduce it now. Very strange result -- I've never seen folds affect an operation like that. You may be right about it being a bug.

Will you give the PR above a try? In my testing it side-steps the bug by overriding any foldmethod value before the edits are attempted.

whiteinge avatar Jan 29 '24 06:01 whiteinge

Will you give the PR above a try? In my testing it side-steps the bug by overriding any foldmethod value before the edits are attempted.

yes, it seems to be working

giuseppelettieri avatar Jan 30 '24 09:01 giuseppelettieri