fix: use token offset and length to determine where to highlight in example messages

This commit is contained in:
ggurdin 2026-01-23 10:49:01 -05:00
parent c454dc152c
commit 0ebf3d6346
No known key found for this signature in database
GPG key ID: A01CB41737CBB478

View file

@ -71,22 +71,16 @@ class ExampleMessageUtil {
}
if (token == null) return null;
final tokenText = token.text.content;
int tokenIndex = text.indexOf(tokenText);
if (tokenIndex == -1) return null;
final beforeSubstring = text.substring(0, tokenIndex);
if (beforeSubstring.length != beforeSubstring.characters.length) {
tokenIndex = beforeSubstring.characters.length;
}
final before = text.characters.take(token.text.offset).toString();
final after = text.characters
.skip(token.text.offset + token.text.content.characters.length)
.toString();
final int tokenLength = tokenText.characters.length;
final before = text.characters.take(tokenIndex).toString();
final after = text.characters.skip(tokenIndex + tokenLength).toString();
return [
TextSpan(text: before),
TextSpan(
text: tokenText,
text: token.text.content,
style: const TextStyle(
fontWeight: FontWeight.bold,
),