Refine terminal search highlighting and placement

eterm:
  - render the active match with palette yellow and black text
  - use translucent palette yellow for inactive matches
  - share search color handling across all terminal rendering paths
  - collect the complete visible range of wrapped active matches
  - move the find bar below matches in either of the first two rows
  - remove unreliable horizontal overlap checks from find bar placement
This commit is contained in:
Martín Lucas Golini
2026-09-16 11:12:00 -03:00
parent 25a492094e
commit 9956f38c2a
2 changed files with 22 additions and 23 deletions

View File

@@ -655,14 +655,16 @@ Int32 TerminalDisplay::getCurrentSearchMatch() const {
bool TerminalDisplay::getVisibleCurrentSearchMatch( Vector2i& start, Vector2i& end ) const {
if ( !mSnapshot )
return false;
bool found = false;
for ( const auto& match : mSnapshot->visibleSearchMatches ) {
if ( match.active ) {
start = match.start;
if ( !found )
start = match.start;
end = match.end;
return true;
found = true;
}
}
return false;
return found;
}
Uint64 TerminalDisplay::getSearchRequestId() const {
@@ -1265,6 +1267,18 @@ static inline Color termColor( unsigned int terminalColor, const std::vector<Col
terminalColor & 0xFF, ( ~( ( terminalColor >> 25 ) & 0xFF ) ) & 0xFF );
}
static inline void applySearchHighlight( Int32 mode, const std::vector<Color>& colors, Color& fg,
Color& bg ) {
if ( mode & ATTR_SEARCH_ACTIVE ) {
fg = termColor( 0, colors );
bg = termColor( 3, colors );
} else if ( mode & ATTR_SEARCH_MATCH ) {
Color highlight = termColor( 3, colors );
highlight.a = 90;
bg = Color::blend( highlight, bg );
}
}
void TerminalDisplay::drawrect( const Color& col, const float& x, const float& y, const float& w,
const float& h ) {
if ( mVBStyles.empty() ) {
@@ -1484,11 +1498,7 @@ void TerminalDisplay::drawGrid( const Vector2f& pos ) {
if ( glyph.mode & ATTR_REVERSE )
bg = fg;
if ( glyph.mode & ( ATTR_SEARCH_MATCH | ATTR_SEARCH_ACTIVE ) ) {
Color highlight = mColorScheme.getCursor();
highlight.a = glyph.mode & ATTR_SEARCH_ACTIVE ? 190 : 90;
bg = Color::blend( highlight, bg );
}
applySearchHighlight( glyph.mode, mColors, fg, bg );
bool isWide = glyph.mode & ATTR_WIDE;
@@ -1543,11 +1553,7 @@ void TerminalDisplay::drawGrid( const Vector2f& pos ) {
}
if ( glyph.mode & ATTR_REVERSE )
background = foreground;
if ( glyph.mode & ( ATTR_SEARCH_MATCH | ATTR_SEARCH_ACTIVE ) ) {
Color highlight = mColorScheme.getCursor();
highlight.a = glyph.mode & ATTR_SEARCH_ACTIVE ? 190 : 90;
background = Color::blend( highlight, background );
}
applySearchHighlight( glyph.mode, mColors, foreground, background );
const bool wide = glyph.mode & ATTR_WIDE;
const Float advance = spaceCharAdvanceX * ( wide ? 2.0f : 1.0f );
if ( background != defaultBg ) {
@@ -1605,11 +1611,7 @@ void TerminalDisplay::drawGrid( const Vector2f& pos ) {
fg = bg;
bg = temp;
}
if ( glyph.mode & ( ATTR_SEARCH_MATCH | ATTR_SEARCH_ACTIVE ) ) {
Color highlight = mColorScheme.getCursor();
highlight.a = glyph.mode & ATTR_SEARCH_ACTIVE ? 190 : 90;
bg = Color::blend( highlight, bg );
}
applySearchHighlight( glyph.mode, mColors, fg, bg );
if ( glyph.mode & ATTR_BLINK && ( mMode & MODE_BLINK ) )
fg = bg;

View File

@@ -198,13 +198,10 @@ void UITerminalFind::updatePosition() {
Vector2i start;
Vector2i end;
auto term = mTerminal->getTerm();
if ( term->getVisibleCurrentSearchMatch( start, end ) && start.y == 0 ) {
if ( term->getVisibleCurrentSearchMatch( start, end ) && start.y <= 1 ) {
const Sizei cellSize = term->getCellPixelSize();
const Rectf& padding = term->getPadding();
const Float matchLeft = padding.Left + start.x * cellSize.getWidth();
const Float matchRight = padding.Left + ( end.x + 1 ) * cellSize.getWidth();
if ( matchRight > x && matchLeft < x + getSize().getWidth() )
y = padding.Top + cellSize.getHeight();
y = padding.Top + ( end.y + 1 ) * cellSize.getHeight();
}
const Vector2f position( x, y );
if ( getPosition() != position )