๐Ÿ“ฆ amake / orgro

๐Ÿ“„ editing.dart ยท 19 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19import 'package:flutter/services.dart';

TextEditingValue testValue(String text) {
  final cleaned = text.replaceAll('|', '');
  final baseOffset = text.indexOf('|');
  final cursorCount = text.length - cleaned.length;
  assert(cursorCount == 1 || cursorCount == 2);
  final extentOffset = cursorCount == 2
      ? text.lastIndexOf('|') - 1
      : baseOffset;
  return TextEditingValue(
    text: cleaned,
    selection: TextSelection(
      baseOffset: baseOffset,
      extentOffset: extentOffset,
    ),
  );
}