Merge pull request #5381 from pangeachat/5363-vocab-practice-taking-only-part-of-english-word

fix: use token offset and length to determine where to highlight in e…
This commit is contained in:
ggurdin 2026-01-23 10:49:31 -05:00 committed by GitHub
commit 99af3e4f42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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,
),