wordAround method
Word boundaries around offset (start inclusive, end exclusive).
Implementation
(int, int)? wordAround(int offset) {
if (text.isEmpty) return null;
final int safe = offset.clamp(0, text.length - 1);
bool isBreak(int code) => code == 0x20 || code == 0x0A || code == 0x09 || code == 0x0D || code == 0x200C;
int start = safe;
int end = safe;
while (start > 0 && !isBreak(text.codeUnitAt(start - 1))) {
start--;
}
while (end < text.length && !isBreak(text.codeUnitAt(end))) {
end++;
}
if (end <= start) return null;
return (start, end);
}