Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REGRESSION] An empty string as RE replaces/overwrites/erases current content of the search register #5076

Closed
schragge opened this issue Jan 10, 2024 · 2 comments · Fixed by #5080
Labels

Comments

@schragge
Copy link

Version of Kakoune

v2023.08.05-190-g9b166e80

Reproducer

Consider the sequence s\w+<ret> ... s<ret> ... s<ret>. The first s selects whole words, then the second s selects them again. The third s should have selected them once again (this is how it worked in v2023.08.05), instead it doesn't select anything as the empty string from the second s replaced the RE and shifted it to history. For this to work, now I have to recall the RE from history: s\w+<ret> ... s<ret> ... s<c-p><ret>. And if s<ret> were a part of a macro that macro would now fail after the first iteration.

More annoyingly, now fails the following, relatively common to me idiom: */<ret>n. * puts selections to the search register, then /<ret> selects the next occurrence after each selection, then n moves the main selection to the next occurrence after it. For this to work, now I have to repeat *: */<ret>*n.

It gets even more annoying if we're dealing with a more complicated RE that cannot be easily reproduced with *. E.g.

/\d+<ret>/<ret>N

/\d+<ret> selects a number, then /<ret> selects the next number after each selection, then N additionally selects another number after the main selection. For this to work, now I have to

/\d+<ret>/<ret>Z,/<c-p><ret><a-z>a

Outcome

After a search command with an empty RE was once used (s<ret>, /<ret>, etc.), subsequent similar searches don't find anything.

Expectations

The original RE is being kept in the search register, so that subsequent n, N, s<ret>, /<ret>, etc. continue to work.

Additional information

I guess either a2c4159 or c2fb073 may be relevant. Or both.

@krobelus
Copy link
Contributor

thanks for finding this; I think I had hit this before but didn't track it down.

A fix is

diff --git a/src/normal.cc b/src/normal.cc
index 902c98e45..1032a776c 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -866,7 +866,8 @@ void regex_prompt(Context& context, String prompt, char reg, T func)
                         RegisterManager::instance()[reg].set(context, str.str());
                     break;
                 case PromptEvent::Validate:
-                    RegisterManager::instance()[reg].set(context, str.str());
+                    if (not str.empty())
+                        RegisterManager::instance()[reg].set(context, str.str());
                     context.push_jump();
                     break;
                 }

@schragge
Copy link
Author

Confirming your patch fixes the issue, thank you.

@mawww mawww closed this as completed in 20b0ead Jan 17, 2024
evannjohnson pushed a commit to evannjohnson/kakoune-ev that referenced this issue Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants