Skip to content

Commit

Permalink
Ignore non text update in autoformats detection
Browse files Browse the repository at this point in the history
  • Loading branch information
amantoux committed Aug 19, 2024
1 parent 7f965d0 commit a642dc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/fleather/lib/src/widgets/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ class FleatherController extends ChangeNotifier {
// document; `false` otherwise
bool _captureAutoFormatCancellationOrUndo(
ParchmentDocument document, int position, int length, Object data) {
// Platform (iOS for example) may send TextEditingDeltaNonTextUpdate
// before the TextEditingDeltaDeletion that may cancel all active autoformats
// We ignore these changes
if (length == 0 && data == '') return true;
if (!_autoFormats.hasActiveSuggestion) return true;

if (_autoFormats.canUndo) {
Expand Down
13 changes: 13 additions & 0 deletions packages/fleather/test/widgets/controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,19 @@ void main() {
expect(controller.selection, selection);
});

test('No de-activation when receiving non text update', () {
const text = 'Some link https://fleather-editor.github.io';
const selection = TextSelection.collapsed(offset: text.length);
controller.replaceText(0, 0, text);
controller.replaceText(text.length, 0, ' ', selection: selection);
controller.replaceText(0, 0, '', selection: selection);
controller.replaceText(text.length, 1, '',
selection: const TextSelection.collapsed(offset: text.length));
final expDelta = Delta()..insert('$text \n');
expect(controller.document.toDelta(), expDelta);
expect(controller.selection, selection);
});

test('Markdown shortcuts', () {
const text = 'Some line\n*';
const selection = TextSelection.collapsed(offset: text.length);
Expand Down

0 comments on commit a642dc7

Please sign in to comment.