@@ -547,6 +547,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
547
547
_searchBox->Open ([weakThis = get_weak ()]() {
548
548
if (const auto self = weakThis.get (); self && !self->_IsClosing ())
549
549
{
550
+ self->_searchScrollOffset = self->_calculateSearchScrollOffset ();
550
551
self->_searchBox ->SetFocusOnTextbox ();
551
552
self->_refreshSearch ();
552
553
}
@@ -568,7 +569,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
568
569
}
569
570
else
570
571
{
571
- _handleSearchResults (_core.Search (_searchBox->Text (), goForward, _searchBox->CaseSensitive (), _searchBox->RegularExpression (), false ));
572
+ const auto request = SearchRequest{ _searchBox->Text (), goForward, _searchBox->CaseSensitive (), _searchBox->RegularExpression (), false , _searchScrollOffset };
573
+ _handleSearchResults (_core.Search (request));
572
574
}
573
575
}
574
576
@@ -602,7 +604,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
602
604
{
603
605
if (_searchBox && _searchBox->IsOpen ())
604
606
{
605
- _handleSearchResults (_core.Search (text, goForward, caseSensitive, regularExpression, false ));
607
+ const auto request = SearchRequest{ text, goForward, caseSensitive, regularExpression, false , _searchScrollOffset };
608
+ _handleSearchResults (_core.Search (request));
606
609
}
607
610
}
608
611
@@ -623,7 +626,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
623
626
{
624
627
// We only want to update the search results based on the new text. Set
625
628
// `resetOnly` to true so we don't accidentally update the current match index.
626
- const auto result = _core.Search (text, goForward, caseSensitive, regularExpression, true );
629
+ const auto request = SearchRequest{ text, goForward, caseSensitive, regularExpression, true , _searchScrollOffset };
630
+ const auto result = _core.Search (request);
627
631
_handleSearchResults (result);
628
632
}
629
633
}
@@ -3629,6 +3633,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3629
3633
};
3630
3634
scaleMarker (SelectionStartMarker ());
3631
3635
scaleMarker (SelectionEndMarker ());
3636
+
3637
+ _searchScrollOffset = _calculateSearchScrollOffset ();
3632
3638
}
3633
3639
3634
3640
void TermControl::_coreRaisedNotice (const IInspectable& /* sender*/ ,
@@ -3750,7 +3756,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3750
3756
const auto goForward = _searchBox->GoForward ();
3751
3757
const auto caseSensitive = _searchBox->CaseSensitive ();
3752
3758
const auto regularExpression = _searchBox->RegularExpression ();
3753
- _handleSearchResults (_core.Search (text, goForward, caseSensitive, regularExpression, true ));
3759
+ const auto request = SearchRequest{ text, goForward, caseSensitive, regularExpression, true , _calculateSearchScrollOffset () };
3760
+ _handleSearchResults (_core.Search (request));
3754
3761
}
3755
3762
3756
3763
void TermControl::_handleSearchResults (SearchResults results)
@@ -3919,6 +3926,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3919
3926
_showContextMenuAt (_toControlOrigin (cursorPos));
3920
3927
}
3921
3928
3929
+ til::CoordType TermControl::_calculateSearchScrollOffset () const
3930
+ {
3931
+ auto result = 0 ;
3932
+ if (_searchBox)
3933
+ {
3934
+ const auto displayInfo = DisplayInformation::GetForCurrentView ();
3935
+ const auto scaleFactor = _core.FontSize ().Height / displayInfo.RawPixelsPerViewPixel ();
3936
+ const auto searchBoxRows = _searchBox->ActualHeight () / scaleFactor;
3937
+ result = static_cast <int32_t >(std::ceil (searchBoxRows));
3938
+ }
3939
+ return result;
3940
+ }
3941
+
3922
3942
void TermControl::_PasteCommandHandler (const IInspectable& /* sender*/ ,
3923
3943
const IInspectable& /* args*/ )
3924
3944
{
0 commit comments