@@ -465,7 +465,6 @@ namespace MWGui
465
465
466
466
void Console::findOccurrence (const SearchDirection direction)
467
467
{
468
-
469
468
if (mCurrentSearchTerm .empty ())
470
469
{
471
470
return ;
@@ -478,17 +477,16 @@ namespace MWGui
478
477
size_t firstIndex{ 0 };
479
478
size_t lastIndex{ historyText.length () };
480
479
481
- // If search is not the first adjust the range based on the direction and previous occurrence.
480
+ // If this isn't the first search, adjust the range based on the previous occurrence.
482
481
if (mCurrentOccurrenceIndex != std::string::npos)
483
482
{
484
- if (direction == SearchDirection::Forward && mCurrentOccurrenceIndex > 1 )
483
+ if (direction == SearchDirection::Forward)
485
484
{
486
485
firstIndex = mCurrentOccurrenceIndex + mCurrentOccurrenceLength ;
487
486
}
488
- else if (direction == SearchDirection::Reverse
489
- && (historyText.length () - mCurrentOccurrenceIndex ) > mCurrentOccurrenceLength )
487
+ else if (direction == SearchDirection::Reverse)
490
488
{
491
- lastIndex = mCurrentOccurrenceIndex - 1 ;
489
+ lastIndex = mCurrentOccurrenceIndex ;
492
490
}
493
491
}
494
492
@@ -523,6 +521,13 @@ namespace MWGui
523
521
void Console::findInHistoryText (const std::string& historyText, const SearchDirection direction,
524
522
const size_t firstIndex, const size_t lastIndex)
525
523
{
524
+ if (lastIndex <= firstIndex)
525
+ {
526
+ mCurrentOccurrenceIndex = std::string::npos;
527
+ mCurrentOccurrenceLength = 0 ;
528
+ return ;
529
+ }
530
+
526
531
if (mRegExSearch )
527
532
{
528
533
findWithRegex (historyText, direction, firstIndex, lastIndex);
@@ -570,7 +575,7 @@ namespace MWGui
570
575
const size_t firstIndex, const size_t lastIndex)
571
576
{
572
577
// Search in given text interval for search term
573
- const size_t substringLength{ ( lastIndex - firstIndex) + 1 } ;
578
+ const size_t substringLength = lastIndex - firstIndex;
574
579
const std::string_view historyTextView ((historyText.c_str () + firstIndex), substringLength);
575
580
if (direction == SearchDirection::Forward)
576
581
{
0 commit comments