Skip to content

FilteringTextInputFormatter's output text is selection dependent #80842

@LongCatIsLooong

Description

@LongCatIsLooong

The following test fails:

  test('FilteringTextInputFormatter should filter independent of selection', () {
    final TextInputFormatter formatter = FilteringTextInputFormatter.deny('abc', replacementString: '*');

    const TextEditingValue oldValue = TextEditingValue();
    const TextEditingValue newValue = TextEditingValue(text: 'abcabcabc');

    final String filteredText = formatter.formatEditUpdate(oldValue, newValue).text;

    for (int i = 0; i < newValue.text.length; i += 1) {
      final String text = formatter.formatEditUpdate(
        oldValue,
        newValue.copyWith(selection: TextSelection.collapsed(offset: i)),
      ).text;
      expect(filteredText, text);
    }
  });

because currently the text is not formatted as a single string:

final String beforeSelection = substringManipulation(
value.text.substring(0, selectionStartIndex),
);
final String inSelection = substringManipulation(
value.text.substring(selectionStartIndex, selectionEndIndex),
);
final String afterSelection = substringManipulation(
value.text.substring(selectionEndIndex),
);
manipulatedText = beforeSelection + inSelection + afterSelection;

Metadata

Metadata

Labels

a: text inputEntering text in a text field or keyboard related problemsfound in release: 2.2Found to occur in 2.2frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions