Skip to content

Avoid covering current search highlight with search box #17516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

if (const auto idx = _searcher.CurrentMatch(); idx >= 0)
{
_terminal->SetSearchHighlightFocused(gsl::narrow<size_t>(idx));
_terminal->SetSearchHighlightFocused(gsl::narrow<size_t>(idx), _searchScrollOffset);
}
_renderer->TriggerSearchHighlight(oldResults);
}
Expand Down Expand Up @@ -1751,7 +1751,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
const auto lock = _terminal->LockForWriting();
_terminal->SetSearchHighlights({});
_terminal->SetSearchHighlightFocused({});
_terminal->SetSearchHighlightFocused({}, _searchScrollOffset);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you can just pass 0 instead of _searchScrollOffset here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

_renderer->TriggerSearchHighlight(_searcher.Results());
_searcher = {};
}
Expand Down Expand Up @@ -2934,4 +2934,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_terminal->PreviewText(input);
}

void ControlCore::SetSearchScrollOffset(til::CoordType offset)
{
_searchScrollOffset = offset;
}
}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bool ShouldShowSelectOutput();

void PreviewInput(std::wstring_view input);
void SetSearchScrollOffset(til::CoordType offset);

RUNTIME_SETTING(float, Opacity, _settings->Opacity());
RUNTIME_SETTING(float, FocusedOpacity, FocusedAppearance().Opacity());
Expand Down Expand Up @@ -337,6 +338,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bool _colorGlyphs = true;
CSSLengthPercentage _cellWidth;
CSSLengthPercentage _cellHeight;
til::CoordType _searchScrollOffset = 0;

// storage location for the leading surrogate of a utf-16 surrogate pair
std::optional<wchar_t> _leadingSurrogate{ std::nullopt };
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ namespace Microsoft.Terminal.Control
Boolean ShouldShowSelectOutput();

void ClearQuickFix();
void SetSearchScrollOffset(Int32 offset);

// These events are called from some background thread
event Windows.Foundation.TypedEventHandler<Object, TitleChangedEventArgs> TitleChanged;
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_searchBox->Open([weakThis = get_weak()]() {
if (const auto self = weakThis.get(); self && !self->_IsClosing())
{
const auto displayInfo = DisplayInformation::GetForCurrentView();
const auto scaleFactor = self->_core.FontSize().Height / displayInfo.RawPixelsPerViewPixel();
const auto searchBoxRows = self->_searchBox->ActualHeight() / scaleFactor;
self->_core.SetSearchScrollOffset(static_cast<int32_t>(std::ceil(searchBoxRows)));
self->_searchBox->SetFocusOnTextbox();
self->_refreshSearch();
}
Expand Down
6 changes: 4 additions & 2 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ void Terminal::SetSearchHighlights(const std::vector<til::point_span>& highlight
// Method Description:
// - Stores the focused search highlighted region in the terminal
// - If the region isn't empty, it will be brought into view
void Terminal::SetSearchHighlightFocused(const size_t focusedIdx)
void Terminal::SetSearchHighlightFocused(const size_t focusedIdx, til::CoordType searchScrollOffset)
{
_assertLocked();
_searchHighlightFocused = focusedIdx;
Expand All @@ -1268,7 +1268,9 @@ void Terminal::SetSearchHighlightFocused(const size_t focusedIdx)
if (focusedIdx < _searchHighlights.size())
{
const auto focused = til::at(_searchHighlights, focusedIdx);
_ScrollToPoints(focused.start, focused.end);
const auto adjustedStart = til::point{ focused.start.x, std::max(0, focused.start.y - searchScrollOffset) };
const auto adjustedEnd = til::point{ focused.end.x, std::max(0, focused.end.y - searchScrollOffset) };
_ScrollToPoints(adjustedStart, adjustedEnd);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class Microsoft::Terminal::Core::Terminal final :
void SetSearchMissingCommandCallback(std::function<void(std::wstring_view)> pfn) noexcept;
void SetClearQuickFixCallback(std::function<void()> pfn) noexcept;
void SetSearchHighlights(const std::vector<til::point_span>& highlights) noexcept;
void SetSearchHighlightFocused(const size_t focusedIdx);
void SetSearchHighlightFocused(const size_t focusedIdx, til::CoordType searchScrollOffset);

void BlinkCursor() noexcept;
void SetCursorOn(const bool isOn) noexcept;
Expand Down
Loading