Find/Replace does not work
Find/Replace does not replace the found string correctly. With the sample code such as:
public class Test {
public void a(int x) throws MyException {}
public void b(int y, int b) throws MyException {}
}
Do as follows:
- Try to find "MyException" in code (Direction: forward, Scope: all, Options: wrap search)
- When the first matching "MyException" word is found/highlighted, click "Replace/Find" or "Replace" to replace with "SomeOtherException"
- IDE skips the highlighted word and replaces the second "MyException" word with "SomeOtherException", which is not correct
This problem appears at least in:
- Eclipse JEE 2024-03
- Eclipse JEE 2024-06
As I've wrote on original ticket in JDT UI, I can't reproduce on master. Please try latest SDK build from https://download.eclipse.org/eclipse/downloads/drops4/I20240708-1800/ and it is reproducible there, make sure all the steps needed are given in the ticket description.
Hey @TT1x1, thank you for the feedback! Is this possibly related to https://github.com/eclipse-platform/eclipse.platform.ui/issues/2011? Let's figure this bug out :)
@HeikoKlare @Wittmaxi i can reproduce the issue in I20241230-1800. It boils down to, that after searching a string a follow up replace will not replace the already found text, which is not intuitive. Especially if the file contains only a single match nothing will be replaced. In an intuitive workflow i would first search a text and then try to replace the already found match.
Unfortunately, I cannot reproduce this issue. I know that we have fixed the original issue some time ago (which was that not the current but a subsequent match of the find string was replaced). Note that the original issue was not related to the overlay-based UI of the find/replace functionality but to both the the overlay- and dialog-based.
In the current SDK, I can perform a search (via search-as-you-type or via explicit search) and then perform a replace that properly replaces the highlighted string:
@jukzi Can you give a concrete reproducer for the issue? May it be related to regex search? That one is currently a bit more unintuitive to use, as it does not support search-as-you-type. And is the issue really specific to the overlay (as indicated by the changed title) or can we also reproduce it with the dialog?
i opened org.eclipse.text.tests.templates.GlobalTemplateVariablesDateTest, enabled regexp searched "expected", tried to replace with "expected\r" - did not work. then tried to replace with "expected\r\n" -> does not work either.
Thank you cor the clarification. I see, then it is related to the unintuitive behavior of the regex search. With regex search enabled, search-as-you-type is currently disabled. This means, you need to trigger a search manually (by clicking on the backward/forward search button or pressing Enter within the find input field) and then you can do a replace. I completely agree that this is quite unintuitive, so we need to improve this. I justed wanted to explain the behavior to show that it is not completely broken but works with an according workflow.
Maybe we could simply enable search-as-you-type for regular expressions (at least that option would be the most consistent/intuitive one). I think we implemented it this way because the dialog disabled incremental search when regex search was enabled, but I am not sure whether we validated if there is some good reason for actually doing it this way:
Closing this one as the original issue has been fixed and the currently discussed issue is already documented in:
- #1911