fix: use token offset and length to determine where to highlight in example messages
This commit is contained in:
parent
c454dc152c
commit
0ebf3d6346
1 changed files with 5 additions and 11 deletions
|
|
@ -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,
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue