@@ -522,7 +522,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
522
522
}
523
523
}
524
524
525
- if (_searchBox && _searchBox->Visibility () == Visibility::Visible )
525
+ if (_searchBox && _searchBox->IsOpen () )
526
526
{
527
527
const auto core = winrt::get_self<ControlCore>(_core);
528
528
const auto & searchMatches = core->SearchResultRows ();
@@ -567,6 +567,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
567
567
// but since code paths differ, extra work is required to ensure correctness.
568
568
if (!_core.HasMultiLineSelection ())
569
569
{
570
+ _core.SnapSearchResultToSelection (true );
570
571
const auto selectedLine{ _core.SelectedText (true ) };
571
572
_searchBox->PopulateTextbox (selectedLine);
572
573
}
@@ -583,13 +584,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
583
584
}
584
585
}
585
586
587
+ // This is called when a Find Next/Previous Match action is triggered.
586
588
void TermControl::SearchMatch (const bool goForward)
587
589
{
588
590
if (_IsClosing ())
589
591
{
590
592
return ;
591
593
}
592
- if (!_searchBox || _searchBox->Visibility () != Visibility::Visible )
594
+ if (!_searchBox || ! _searchBox->IsOpen () )
593
595
{
594
596
CreateSearchBoxControl ();
595
597
}
@@ -631,7 +633,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
631
633
}
632
634
633
635
// Method Description:
634
- // - The handler for the "search criteria changed" event. Clears selection and initiates a new search.
636
+ // - The handler for the "search criteria changed" event. Initiates a new search.
635
637
// Arguments:
636
638
// - text: the text to search
637
639
// - goForward: indicates whether the search should be performed forward (if set to true) or backward
@@ -645,7 +647,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
645
647
{
646
648
if (_searchBox && _searchBox->Visibility () == Visibility::Visible)
647
649
{
648
- _handleSearchResults (_core.Search (text, goForward, caseSensitive, regularExpression, false ));
650
+ // We only want to update the search results based on the new text. Set
651
+ // `resetOnly` to true so we don't accidentally update the current match index.
652
+ const auto result = _core.Search (text, goForward, caseSensitive, regularExpression, true );
653
+ _handleSearchResults (result);
649
654
}
650
655
}
651
656
@@ -663,6 +668,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
663
668
_searchBox->Close ();
664
669
_core.ClearSearch ();
665
670
671
+ // Clear search highlights scroll marks (by triggering an update after closing the search box)
672
+ if (_showMarksInScrollbar)
673
+ {
674
+ const auto scrollBar = ScrollBar ();
675
+ ScrollBarUpdate update{
676
+ .newValue = scrollBar.Value (),
677
+ .newMaximum = scrollBar.Maximum (),
678
+ .newMinimum = scrollBar.Minimum (),
679
+ .newViewportSize = scrollBar.ViewportSize (),
680
+ };
681
+ _updateScrollBar->Run (update);
682
+ }
683
+
666
684
// Set focus back to terminal control
667
685
this ->Focus (FocusState::Programmatic);
668
686
}
@@ -3646,7 +3664,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3646
3664
3647
3665
void TermControl::_refreshSearch ()
3648
3666
{
3649
- if (!_searchBox || _searchBox->Visibility () != Visibility::Visible )
3667
+ if (!_searchBox || ! _searchBox->IsOpen () )
3650
3668
{
3651
3669
return ;
3652
3670
}
@@ -3670,7 +3688,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3670
3688
return ;
3671
3689
}
3672
3690
3673
- _searchBox->SetStatus (results.TotalMatches , results.CurrentMatch , results.SearchRegexInvalid );
3691
+ // Only show status when we have a search term
3692
+ if (_searchBox->Text ().empty ())
3693
+ {
3694
+ _searchBox->ClearStatus ();
3695
+ }
3696
+ else
3697
+ {
3698
+ _searchBox->SetStatus (results.TotalMatches , results.CurrentMatch , results.SearchRegexInvalid );
3699
+ }
3674
3700
3675
3701
if (results.SearchInvalidated )
3676
3702
{
0 commit comments