Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore non text update in autoformats detection #409

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading