fix(tui): prevent crash when searching with digits in model selector

highlightMatch() was replacing tokens inside ANSI escape codes,
corrupting sequences like [38;2;123;127;135m when searching for '2'.
Fix: apply highlighting to plain text before theme styling.
This commit is contained in:
Mario Zechner
2026-02-01 09:50:57 +01:00
parent ba4a55f6d9
commit c621c80afc

View File

@@ -228,9 +228,9 @@ export class SearchableSelectList implements Component {
const remainingWidth = width - descriptionStart - 2;
if (remainingWidth > 10) {
const truncatedDesc = truncateToWidth(item.description, remainingWidth, "");
const descText = isSelected
? this.highlightMatch(truncatedDesc, query)
: this.highlightMatch(this.theme.description(truncatedDesc), query);
// Highlight plain text first, then apply theme styling to avoid corrupting ANSI codes
const highlightedDesc = this.highlightMatch(truncatedDesc, query);
const descText = isSelected ? highlightedDesc : this.theme.description(highlightedDesc);
const line = `${prefix}${valueText}${spacing}${descText}`;
return isSelected ? this.theme.selectedText(line) : line;
}