1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-27 18:11:34 +00:00

Merge branch 'consolesearch' into 'master'

Uncursify forward/reverse console search (#8532)

Closes #8532

See merge request OpenMW/openmw!4697
This commit is contained in:
psi29a 2025-05-30 07:21:26 +00:00
commit ed03babb08

View file

@ -465,7 +465,6 @@ namespace MWGui
void Console::findOccurrence(const SearchDirection direction) void Console::findOccurrence(const SearchDirection direction)
{ {
if (mCurrentSearchTerm.empty()) if (mCurrentSearchTerm.empty())
{ {
return; return;
@ -478,17 +477,16 @@ namespace MWGui
size_t firstIndex{ 0 }; size_t firstIndex{ 0 };
size_t lastIndex{ historyText.length() }; size_t lastIndex{ historyText.length() };
// If search is not the first adjust the range based on the direction and previous occurrence. // If this isn't the first search, adjust the range based on the previous occurrence.
if (mCurrentOccurrenceIndex != std::string::npos) if (mCurrentOccurrenceIndex != std::string::npos)
{ {
if (direction == SearchDirection::Forward && mCurrentOccurrenceIndex > 1) if (direction == SearchDirection::Forward)
{ {
firstIndex = mCurrentOccurrenceIndex + mCurrentOccurrenceLength; firstIndex = mCurrentOccurrenceIndex + mCurrentOccurrenceLength;
} }
else if (direction == SearchDirection::Reverse else if (direction == SearchDirection::Reverse)
&& (historyText.length() - mCurrentOccurrenceIndex) > mCurrentOccurrenceLength)
{ {
lastIndex = mCurrentOccurrenceIndex - 1; lastIndex = mCurrentOccurrenceIndex;
} }
} }
@ -523,6 +521,13 @@ namespace MWGui
void Console::findInHistoryText(const std::string& historyText, const SearchDirection direction, void Console::findInHistoryText(const std::string& historyText, const SearchDirection direction,
const size_t firstIndex, const size_t lastIndex) const size_t firstIndex, const size_t lastIndex)
{ {
if (lastIndex <= firstIndex)
{
mCurrentOccurrenceIndex = std::string::npos;
mCurrentOccurrenceLength = 0;
return;
}
if (mRegExSearch) if (mRegExSearch)
{ {
findWithRegex(historyText, direction, firstIndex, lastIndex); findWithRegex(historyText, direction, firstIndex, lastIndex);
@ -570,7 +575,7 @@ namespace MWGui
const size_t firstIndex, const size_t lastIndex) const size_t firstIndex, const size_t lastIndex)
{ {
// Search in given text interval for search term // Search in given text interval for search term
const size_t substringLength{ (lastIndex - firstIndex) + 1 }; const size_t substringLength = lastIndex - firstIndex;
const std::string_view historyTextView((historyText.c_str() + firstIndex), substringLength); const std::string_view historyTextView((historyText.c_str() + firstIndex), substringLength);
if (direction == SearchDirection::Forward) if (direction == SearchDirection::Forward)
{ {