diff --git a/packages/fleather/lib/src/widgets/autoformats.dart b/packages/fleather/lib/src/widgets/autoformats.dart index 5c06ac50..f4ced9c6 100644 --- a/packages/fleather/lib/src/widgets/autoformats.dart +++ b/packages/fleather/lib/src/widgets/autoformats.dart @@ -13,14 +13,6 @@ import 'package:quill_delta/quill_delta.dart'; abstract class AutoFormat { const AutoFormat(); - /// Indicates whether the character triggering the auto format is kept in - /// document - /// - /// E.g: for link detections, [space] is kept whereas for Markdown block - /// shortcuts, the [space] is not added to document, it only serves to - /// trigger the block formatting - bool get keepTriggerCharacter; - /// Upon insertion of a trigger character, run format detection and apply /// formatting to document /// @@ -53,11 +45,6 @@ class AutoFormats { /// The position at which the active suggestion can be deactivated int get undoPosition => _activeSuggestion!.undoPositionCandidate; - /// `true` if the active suggestion [AutoFormat] keeps trigger character in - /// document; `false` otherwise - bool get activeSuggestionKeepTriggerCharacter => - _activeSuggestion!.keepTriggerCharacter; - /// `true` if there is an active suggestion; `false` otherwise bool get hasActiveSuggestion => _activeSuggestion != null; @@ -104,7 +91,6 @@ class AutoFormatResult { this.undoSelection, required this.undo, required this.undoPositionCandidate, - required this.keepTriggerCharacter, }); /// *Optional* [TextSelection] after applying the auto format. @@ -125,9 +111,6 @@ class AutoFormatResult { /// The position at which an auto format can be canceled final int undoPositionCandidate; - - /// Whether the trigger character will be removed from the document after undoing the auto format - final bool keepTriggerCharacter; } class _AutoFormatLinks extends AutoFormat { @@ -136,9 +119,6 @@ class _AutoFormatLinks extends AutoFormat { const _AutoFormatLinks(); - @override - final bool keepTriggerCharacter = false; - @override AutoFormatResult? apply( ParchmentDocument document, int position, String data) { @@ -175,10 +155,7 @@ class _AutoFormatLinks extends AutoFormat { final undo = change.invert(documentDelta); document.compose(change, ChangeSource.local); return AutoFormatResult( - change: change, - undo: undo, - keepTriggerCharacter: keepTriggerCharacter, - undoPositionCandidate: position); + change: change, undo: undo, undoPositionCandidate: position); } } @@ -199,9 +176,6 @@ class _MarkdownShortCuts extends AutoFormat { const _MarkdownShortCuts(); - @override - final bool keepTriggerCharacter = false; - String? _getLinePrefix(DeltaIterator iter, int index) { final prefixOps = skipToLineAt(iter, index); if (prefixOps.any((element) => element.data is! String)) return null; @@ -314,7 +288,6 @@ class _MarkdownShortCuts extends AutoFormat { undoSelection: TextSelection.collapsed(offset: position + data.length), undo: undo, - keepTriggerCharacter: keepTriggerCharacter, undoPositionCandidate: position - prefix.length - 1); } } @@ -342,7 +315,6 @@ class _MarkdownShortCuts extends AutoFormat { // current position is after prefix, so need to add 1 for space undoSelection: TextSelection.collapsed(offset: position + 1), undo: undo, - keepTriggerCharacter: keepTriggerCharacter, undoPositionCandidate: position - prefix.length - 1); } } @@ -354,9 +326,6 @@ class _AutoTextDirection extends AutoFormat { final _isRTL = intl.Bidi.startsWithRtl; - @override - final bool keepTriggerCharacter = true; - bool _isAfterEmptyLine(Operation? previous) { final data = previous?.data; return data == null || (data is String ? data.endsWith('\n') : false); @@ -400,9 +369,6 @@ class _AutoTextDirection extends AutoFormat { final undo = change.invert(documentDelta); document.compose(change, ChangeSource.local); return AutoFormatResult( - change: change, - undo: undo, - keepTriggerCharacter: keepTriggerCharacter, - undoPositionCandidate: position); + change: change, undo: undo, undoPositionCandidate: position); } } diff --git a/packages/fleather/lib/src/widgets/controller.dart b/packages/fleather/lib/src/widgets/controller.dart index 7b2a2770..d3f998d0 100644 --- a/packages/fleather/lib/src/widgets/controller.dart +++ b/packages/fleather/lib/src/widgets/controller.dart @@ -173,8 +173,6 @@ class FleatherController extends ChangeNotifier { ParchmentDocument document, int position, int length, Object data) { if (!_autoFormats.hasActiveSuggestion) return true; - final keepTriggerCharacter = - _autoFormats.activeSuggestionKeepTriggerCharacter; final isDeletionOfOneChar = data is String && data.isEmpty && length == 1; if (isDeletionOfOneChar) { // Undo if deleting 1 character after retain of auto-format @@ -183,7 +181,7 @@ class FleatherController extends ChangeNotifier { if (undoSelection != null) { _updateSelectionSilent(undoSelection, source: ChangeSource.local); } - return keepTriggerCharacter; + return false; } } // Cancel active nevertheless