From 8aee953596c537f605bd981c136f5bed7a56a04e Mon Sep 17 00:00:00 2001 From: Ahmed Hnewa <73608287+freshtechtips@users.noreply.github.com> Date: Thu, 19 Oct 2023 16:55:25 +0300 Subject: [PATCH] Add the uncomplete option to ovveride the verify link regex pattern --- flutter_quill_extensions/pubspec.yaml | 2 +- lib/src/models/rules/delete.dart | 40 ++++++--------------------- lib/src/models/rules/format.dart | 4 --- lib/src/models/rules/insert.dart | 33 ++++++++++++++-------- lib/src/models/rules/rule.dart | 1 - 5 files changed, 30 insertions(+), 50 deletions(-) diff --git a/flutter_quill_extensions/pubspec.yaml b/flutter_quill_extensions/pubspec.yaml index 7fe0fc23..59995c59 100644 --- a/flutter_quill_extensions/pubspec.yaml +++ b/flutter_quill_extensions/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: flutter_quill: ^7.4.14 # In case you are working on changes for both libraries, # flutter_quill: - # path: /Users/ahmedhnewa/development/playground/framework_based/flutter/flutter-quill + # path: ~/development/playground/framework_based/flutter/flutter-quill http: ^1.1.0 image_picker: ">=1.0.4" diff --git a/lib/src/models/rules/delete.dart b/lib/src/models/rules/delete.dart index 6381636a..fd547825 100644 --- a/lib/src/models/rules/delete.dart +++ b/lib/src/models/rules/delete.dart @@ -22,14 +22,8 @@ class EnsureLastLineBreakDeleteRule extends DeleteRule { const EnsureLastLineBreakDeleteRule(); @override - Delta? applyRule( - Delta document, - int index, { - int? len, - Object? data, - Attribute? attribute, - Map extraData = const {}, - }) { + Delta? applyRule(Delta document, int index, + {int? len, Object? data, Attribute? attribute}) { final itr = DeltaIterator(document)..skip(index + len!); return Delta() @@ -44,14 +38,8 @@ class CatchAllDeleteRule extends DeleteRule { const CatchAllDeleteRule(); @override - Delta applyRule( - Delta document, - int index, { - int? len, - Object? data, - Attribute? attribute, - Map extraData = const {}, - }) { + Delta applyRule(Delta document, int index, + {int? len, Object? data, Attribute? attribute}) { final itr = DeltaIterator(document)..skip(index + len!); return Delta() @@ -70,14 +58,8 @@ class PreserveLineStyleOnMergeRule extends DeleteRule { const PreserveLineStyleOnMergeRule(); @override - Delta? applyRule( - Delta document, - int index, { - int? len, - Object? data, - Attribute? attribute, - Map extraData = const {}, - }) { + Delta? applyRule(Delta document, int index, + {int? len, Object? data, Attribute? attribute}) { final itr = DeltaIterator(document)..skip(index); var op = itr.next(1); if (op.data != '\n') { @@ -134,14 +116,8 @@ class EnsureEmbedLineRule extends DeleteRule { const EnsureEmbedLineRule(); @override - Delta? applyRule( - Delta document, - int index, { - int? len, - Object? data, - Attribute? attribute, - Map extraData = const {}, - }) { + Delta? applyRule(Delta document, int index, + {int? len, Object? data, Attribute? attribute}) { final itr = DeltaIterator(document); var op = itr.skip(index); diff --git a/lib/src/models/rules/format.dart b/lib/src/models/rules/format.dart index 45a40f11..a57bac7a 100644 --- a/lib/src/models/rules/format.dart +++ b/lib/src/models/rules/format.dart @@ -29,7 +29,6 @@ class ResolveLineFormatRule extends FormatRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { if (attribute!.scope != AttributeScope.BLOCK) { return null; @@ -120,7 +119,6 @@ class FormatLinkAtCaretPositionRule extends FormatRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { if (attribute!.key != Attribute.link.key || len! > 0) { return null; @@ -160,7 +158,6 @@ class ResolveInlineFormatRule extends FormatRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { if (attribute!.scope != AttributeScope.INLINE) { return null; @@ -206,7 +203,6 @@ class ResolveImageFormatRule extends FormatRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { if (attribute == null || attribute.key != Attribute.style.key) { return null; diff --git a/lib/src/models/rules/insert.dart b/lib/src/models/rules/insert.dart index 41be0fa0..ed75442e 100644 --- a/lib/src/models/rules/insert.dart +++ b/lib/src/models/rules/insert.dart @@ -33,9 +33,6 @@ class PreserveLineStyleOnSplitRule extends InsertRule { int? len, Object? data, Attribute? attribute, - // TODO: If the maintainer are not okay with this change then tell me - // so I can change it back - Map extraData = const {}, }) { if (data is! String || data != '\n') { return null; @@ -86,7 +83,6 @@ class PreserveBlockStyleOnInsertRule extends InsertRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { if (data is! String || !data.contains('\n')) { // Only interested in text containing at least one newline character. @@ -173,7 +169,6 @@ class AutoExitBlockRule extends InsertRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { if (data is! String || data != '\n') { return null; @@ -243,7 +238,6 @@ class ResetLineFormatOnNewLineRule extends InsertRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { if (data is! String || data != '\n') { return null; @@ -280,7 +274,6 @@ class InsertEmbedsRule extends InsertRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { if (data is String) { return null; @@ -393,7 +386,7 @@ class AutoFormatMultipleLinksRule extends InsertRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, + Object? extraData, }) { // Only format when inserting text. if (data is! String) return null; @@ -428,8 +421,27 @@ class AutoFormatMultipleLinksRule extends InsertRule { // Build the segment of affected words. final affectedWords = '$leftWordPart$data$rightWordPart'; + var usedRegExp = detectLinkRegExp; + final alternativeLinkRegExp = extraData; + if (alternativeLinkRegExp != null) { + try { + if (alternativeLinkRegExp is! String) { + throw ArgumentError.value( + alternativeLinkRegExp, + 'alternativeLinkRegExp', + '`alternativeLinkRegExp` should be of type String', + ); + } + final regPattern = alternativeLinkRegExp; + usedRegExp = RegExp( + regPattern, + caseSensitive: false, + ); + } catch (_) {} + } + // Check for URL pattern. - final matches = detectLinkRegExp.allMatches(affectedWords); + final matches = usedRegExp.allMatches(affectedWords); // If there are no matches, do not apply any format. if (matches.isEmpty) return null; @@ -489,7 +501,6 @@ class AutoFormatLinksRule extends InsertRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { if (data is! String || data != ' ') { return null; @@ -535,7 +546,6 @@ class PreserveInlineStylesRule extends InsertRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { if (data is! String || data.contains('\n')) { return null; @@ -587,7 +597,6 @@ class CatchAllInsertRule extends InsertRule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }) { return Delta() ..retain(index + (len ?? 0)) diff --git a/lib/src/models/rules/rule.dart b/lib/src/models/rules/rule.dart index ac4c015c..45b8bdf8 100644 --- a/lib/src/models/rules/rule.dart +++ b/lib/src/models/rules/rule.dart @@ -37,7 +37,6 @@ abstract class Rule { int? len, Object? data, Attribute? attribute, - Map extraData = const {}, }); RuleType get type;