Skip to content

Commit

Permalink
Fix FindReplaceDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Snoozeds committed Sep 22, 2024
1 parent cad64f2 commit 7862897
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/UnrealLocresEditor/FindReplaceDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ public async void FindText(string searchTerm, bool forward = true)
bool isMatchCellChecked = uiMatchCellCheckBox.IsChecked ?? false;

int increment = forward ? 1 : -1;

// Reset match index for a new search term
if (searchTerm != _lastSearchTerm)
{
_currentRowIndex = -1;
_currentMatchIndex = -1;
_lastSearchTerm = searchTerm;
_totalMatches = 0;
}

int startRowIndex = (_currentRowIndex + increment + items.Count) % items.Count;
StringComparison comparison = isMatchCaseChecked ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

Expand All @@ -94,25 +104,18 @@ public async void FindText(string searchTerm, bool forward = true)
var cellContent = row.Values[colIndex] as string;
if (cellContent == null) continue;

bool matchFound = isMatchCellChecked ? string.Equals(cellContent, searchTerm, comparison)
: (isMatchWholeWordChecked ? IsWholeWordMatch(cellContent, searchTerm, comparison)
: cellContent.IndexOf(searchTerm, comparison) >= 0);
bool matchFound = isMatchCellChecked
? string.Equals(cellContent, searchTerm, comparison)
: (isMatchWholeWordChecked
? IsWholeWordMatch(cellContent, searchTerm, comparison)
: cellContent.IndexOf(searchTerm, comparison) >= 0);

if (matchFound)
{
_currentMatchIndex = colIndex;
_currentRowIndex = rowIndex;

if (searchTerm != _lastSearchTerm)
{
_totalMatches = 1;
_lastSearchTerm = searchTerm;
}
else
{
_totalMatches++;
}

_totalMatches++;
foundMatch = true;

await Dispatcher.UIThread.InvokeAsync(() =>
Expand All @@ -134,7 +137,6 @@ await Dispatcher.UIThread.InvokeAsync(() =>
_currentMatchIndex = -1;
_currentRowIndex = -1;
_totalMatches = 0;
_lastSearchTerm = searchTerm;
}
}

Expand Down

0 comments on commit 7862897

Please sign in to comment.