-
Notifications
You must be signed in to change notification settings - Fork 167
"Replace next" incorrect behavior #355
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
Comments
@danipen will PR with "fast and dirty" fix will be accepted ? public void ReplaceNext()
{
if (!IsReplaceMode) return;
FindNext();
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
}
(...)
public void FindNext()
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
_currentSearchResultIndex = GetSearchResultIndex(_renderer.CurrentResults, result);
SelectResult(result);
UpdateSearchLabel();
}
} we can fix this issue with allowing to add additional offset (negative) in FindNext like this: public void FindNext(int additionallOffset = 0)
{
var result = _renderer.CurrentResults.FindFirstSegmentWithStartAfter(_textArea.Caret.Offset + 1 + additionallOffset) ??
_renderer.CurrentResults.FirstSegment;
if (result != null)
{
_currentSearchResultIndex = GetSearchResultIndex(_renderer.CurrentResults, result);
SelectResult(result);
UpdateSearchLabel();
}
} and ReplaceNext : public void ReplaceNext()
{
if (!IsReplaceMode) return;
FindNext(-1);
if (!_textArea.Selection.IsEmpty)
{
_textArea.Selection.ReplaceSelectionWithText(ReplacePattern ?? string.Empty);
}
UpdateSearch();
} |
Haha It's a quite dirty hack... A better solution would be desired... |
or insead off |
IMO first step is taking a look to the upstream repo to see if the bug is there. If not we should review the port. If the bug is there too we can think a fix for it. |
i maked PR for this issue |
@gusmanb please could you elaborate a little bit more on this, showing a video or an example?
|
Started PR #393. |
Here is an example of what I meant. As you can see the first occurence of the word is skipped and it selects the next one. search2.online-video-cutter.com.mp4 |
@gusmanb got it. Other editors place the caret at the end of the search result, so they then |
@danipen Search works as expected, selects the first occurence of the word, but replace next still skips one occurence each time (should it also be fixed in that pr?) Desktop.2024.01.09.-.17.52.08.02.online-video-cutter.com.mp4 |
Yes, it should work in this PR. Taking a look again... |
@gusmanb ok, it was broken with latest changes, it should work as expected now. Please can you give it a try? Thanks! |
@danipen Excellent! Now everything works as expected, find next and replace next 👍 |
The "replace next" function of the search panel implements an incorrect behavior when used more than once.
AvaloniaEdit 11.0.0
If you have a text that contains multiple matches and replace one by one using the "Replace next" button it skips one of the matches each time.
Internally the "Replace next" function calls "FindNext", which searches one char ahead of the caret position, this behavior makes sense for the "FindNext" functionality but not for the replace as once you replace a match it moves the caret to the next one so the next time you press the "Replace next" button that match is skipped and the next one is replaced.
"Replace next" should use its own search criteria that searches from the caret position, not from the next position.
"FindNext" also may present an erratic behavior because of the search-ahead, for example, if an user places the caret at the beginning of a file and the searched text is present starting at the first char the function will skip it and go to the next. The search-ahead behavior should be used only after the first "FindNext" is issued and if the user has not moved manually the caret.
The text was updated successfully, but these errors were encountered: