moveWordLeft function
Implementation
NavigationResult moveWordLeft(Root root, CaretStop current, {
List<CaretStop>? stops,
List<LogicalLine>? cachedLines,
}) {
final stops_ = stops ?? buildAllStops(root);
int idx = findStopIndex(stops_, current.fragmentId, current.offset);
if (idx < 0 || idx <= 0) return NavigationResult.none;
_ensureWordCaches(root, stops_, cachedLines: cachedLines);
final cache = _wordFragCache!;
final lineIdx = _wordLineIdx!;
String? ch(int i) => _charLeft(stops_, i, cache, lineIdx);
final startChar = ch(idx);
if (startChar == null) return NavigationResult.none;
if (_isSpaceChar(startChar)) {
while (idx > 0 && _isSpaceChar(ch(idx) ?? '')) {
idx--;
}
while (idx > 0) {
final c = ch(idx);
if (c == null || !_isWordChar(c)) break;
idx--;
}
} else if (_isWordChar(startChar)) {
while (idx > 0) {
final c = ch(idx);
if (c == null || !_isWordChar(c)) break;
idx--;
}
} else {
while (idx > 0) {
final c = ch(idx);
if (c == null || _isWordChar(c) || _isSpaceChar(c)) break;
idx--;
}
}
return NavigationResult(position: stops_[idx], preferredX: 0.0);
}