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

Find/Replace overlay: immediate replace after selected text #2011 #2052

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

Wittmaxi
Copy link

@Wittmaxi Wittmaxi commented Jul 8, 2024

Work around for a bug of the Editor's implementation of the
FindReplaceTargetExtension3; when initializing the search with an
already selected string, force the overlay to search for it again so
that the Editor can then later replace it if required.

fixes #2011

Copy link
Contributor

github-actions bot commented Jul 8, 2024

Test Results

 1 815 files  ±0   1 815 suites  ±0   1h 35m 4s ⏱️ + 1m 15s
 7 677 tests +2   7 448 ✅ +1  228 💤 ±0  1 ❌ +1 
24 192 runs  +6  23 442 ✅ +5  749 💤 ±0  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 866fba1. ± Comparison against base commit 816820a.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality is sound and aligns with the FindReplaceOverlay. Test is a proper regression test. Thank you!

Just one thing: I do not understand the commit message. Where is the bug in the implementation of the IFindReplaceTargetExtension3? And if that was the case, why not fix that implementation?

@Wittmaxi
Copy link
Author

Wittmaxi commented Jul 8, 2024

@HeikoKlare the Bug we need to work around is the one we already encountered when implementing FindReplaceLogicTest#onlySelectAndReplacesIfFindSuccessfulOnCustomTarget.

	/**
	 * The TextViewer implementation of IFindReplaceLogic is misleading and not adhering to the
	 * Interface: IFindReplaceTargetExtension3#replaceSelection will NOT replace the selection if
	 * nothing was previously found. This does not generally have to be the case and thus we mock a
	 * target that is setup like this:
	 *
	 * The text contained is {@code ~SELECTEDTEXT~abcd} with ~ marking the boundaries of the
	 * selection. We perform a search for "NOTFOUND" first - the selection stays put since the
	 * string was not found. At this point, we do not want to perform
	 * {@code replaceSelection("NOTFOUND")} since an implementation adhering to the specification of
	 * the function would just overwrite the current selection.
	 */

In short: the editor will only replace a selection if it "searched" for it before, even though we would expect it to "blindly replace" the selection.

As for fixing the implementation, I am not sure if we want to get into that; we would need to write tests for the Implementation of FindReplaceTargetExtension3 of the Editor, learn and debug the code and hope that no user depends on this behavior. What do you think?

@HeikoKlare
Copy link
Contributor

I see, still I find it confusing to have a commit message stating that there is a bug that we work around without stating explicitly what and where the bug is and that it is accepted to (currently) not address it.
So something like: "The TextViewer implementation of IFindReplaceTargetExtension3.replaceSelection() does not perform a replace operation if not preceeding find operation was called. This address this accepted deviation from the method's specification, this change ...".

Taking a look at that bug led me to a related bug in the current implementation of the overlay: when having the regex option enabled, the string selected in the editor is not properly transformed into a regex when inserting it into the overlay (like done in the existing dialog). This PR will make the situation worse, as a find operation is executed based on that string, which can change the selection in the editor:
find_replace_regex_init

@Wittmaxi
Copy link
Author

Wittmaxi commented Jul 8, 2024

@HeikoKlare we can fix that bug first and then rebase this PR on that PR - what do you think?

@HeikoKlare
Copy link
Contributor

we can fix that bug first and then rebase this PR on that PR - what do you think?

Yes, makes sense 👍

@Wittmaxi
Copy link
Author

Wittmaxi commented Jul 8, 2024

@HeikoKlare I rebased this PR on #2056 as discussed.

@Wittmaxi
Copy link
Author

I have fixed the merging conflicts.
Since this change mimics the behavior in the Dialog and the faulty behavior with the RegEx is fixed in merged, I believe we are in a good state.
I have changed the commit message to better reflect our thought process in regards to the faulty behavior of the TextViewer's implementation of IFindReplaceTargetExtension3

…latform#2011

The TextViewer implementation of IFindReplaceTargetExtension3.replaceSelection() does not perform
a replace operation if no preceeding find operation was called. To address this accepted
deviation from the interface's specification, this change forces the overlay to search for an initializing
word again so that the Editor can then later replace it if required.

fixes eclipse-platform#2011
Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected, thank you!
I've rebased on master and resolved newly introduced conflicts. If checks succeed, I consider this ready to be merged.

@HeikoKlare
Copy link
Contributor

Failing test is unrelated: #1935

@HeikoKlare HeikoKlare merged commit be68f2f into eclipse-platform:master Jul 15, 2024
14 of 16 checks passed
@HannesWell
Copy link
Member

Thank you for this fix!
Works like a charm now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Find/Replace overlay: Immediate Replace after searching selected text not working
3 participants