@@ -584,6 +584,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
584
584
_searchBox->Open ([weakThis = get_weak ()]() {
585
585
if (const auto self = weakThis.get (); self && !self->_IsClosing ())
586
586
{
587
+ self->_searchScrollOffset = self->_calculateSearchScrollOffset ();
587
588
self->_searchBox ->SetFocusOnTextbox ();
588
589
self->_refreshSearch ();
589
590
}
@@ -605,7 +606,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
605
606
}
606
607
else
607
608
{
608
- _handleSearchResults (_core.Search (_searchBox->Text (), goForward, _searchBox->CaseSensitive (), _searchBox->RegularExpression (), false ));
609
+ const auto request = SearchRequest{ _searchBox->Text (), goForward, _searchBox->CaseSensitive (), _searchBox->RegularExpression (), false , _searchScrollOffset };
610
+ _handleSearchResults (_core.Search (request));
609
611
}
610
612
}
611
613
@@ -639,7 +641,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
639
641
{
640
642
if (_searchBox && _searchBox->IsOpen ())
641
643
{
642
- _handleSearchResults (_core.Search (text, goForward, caseSensitive, regularExpression, false ));
644
+ const auto request = SearchRequest{ text, goForward, caseSensitive, regularExpression, false , _searchScrollOffset };
645
+ _handleSearchResults (_core.Search (request));
643
646
}
644
647
}
645
648
@@ -660,7 +663,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
660
663
{
661
664
// We only want to update the search results based on the new text. Set
662
665
// `resetOnly` to true so we don't accidentally update the current match index.
663
- const auto result = _core.Search (text, goForward, caseSensitive, regularExpression, true );
666
+ const auto request = SearchRequest{ text, goForward, caseSensitive, regularExpression, true , _searchScrollOffset };
667
+ const auto result = _core.Search (request);
664
668
_handleSearchResults (result);
665
669
}
666
670
}
@@ -3572,6 +3576,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3572
3576
QuickFixIcon ().FontSize (static_cast <double >(args.Width () / dpiScale));
3573
3577
RefreshQuickFixMenu ();
3574
3578
}
3579
+
3580
+ _searchScrollOffset = _calculateSearchScrollOffset ();
3575
3581
}
3576
3582
3577
3583
void TermControl::_coreRaisedNotice (const IInspectable& /* sender*/ ,
@@ -3702,7 +3708,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3702
3708
const auto goForward = _searchBox->GoForward ();
3703
3709
const auto caseSensitive = _searchBox->CaseSensitive ();
3704
3710
const auto regularExpression = _searchBox->RegularExpression ();
3705
- _handleSearchResults (_core.Search (text, goForward, caseSensitive, regularExpression, true ));
3711
+ const auto request = SearchRequest{ text, goForward, caseSensitive, regularExpression, true , _calculateSearchScrollOffset () };
3712
+ _handleSearchResults (_core.Search (request));
3706
3713
}
3707
3714
3708
3715
void TermControl::_handleSearchResults (SearchResults results)
@@ -3982,6 +3989,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3982
3989
SearchMissingCommand.raise (*this , args);
3983
3990
}
3984
3991
3992
+ til::CoordType TermControl::_calculateSearchScrollOffset () const
3993
+ {
3994
+ auto result = 0 ;
3995
+ if (_searchBox)
3996
+ {
3997
+ const auto displayInfo = DisplayInformation::GetForCurrentView ();
3998
+ const auto scaleFactor = _core.FontSize ().Height / displayInfo.RawPixelsPerViewPixel ();
3999
+ const auto searchBoxRows = _searchBox->ActualHeight () / scaleFactor;
4000
+ result = static_cast <int32_t >(std::ceil (searchBoxRows));
4001
+ }
4002
+ return result;
4003
+ }
4004
+
3985
4005
void TermControl::ClearQuickFix ()
3986
4006
{
3987
4007
_core.ClearQuickFix ();
0 commit comments