Add the uncomplete option to ovveride the verify link regex pattern

pull/1437/head
Ahmed Hnewa 2 years ago
parent 7d3731aaa0
commit 8aee953596
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 2
      flutter_quill_extensions/pubspec.yaml
  2. 40
      lib/src/models/rules/delete.dart
  3. 4
      lib/src/models/rules/format.dart
  4. 33
      lib/src/models/rules/insert.dart
  5. 1
      lib/src/models/rules/rule.dart

@ -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"

@ -22,14 +22,8 @@ class EnsureLastLineBreakDeleteRule extends DeleteRule {
const EnsureLastLineBreakDeleteRule();
@override
Delta? applyRule(
Delta document,
int index, {
int? len,
Object? data,
Attribute? attribute,
Map<String, Object?> 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<String, Object?> 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<String, Object?> 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<String, Object?> extraData = const {},
}) {
Delta? applyRule(Delta document, int index,
{int? len, Object? data, Attribute? attribute}) {
final itr = DeltaIterator(document);
var op = itr.skip(index);

@ -29,7 +29,6 @@ class ResolveLineFormatRule extends FormatRule {
int? len,
Object? data,
Attribute? attribute,
Map<String, Object?> extraData = const {},
}) {
if (attribute!.scope != AttributeScope.BLOCK) {
return null;
@ -120,7 +119,6 @@ class FormatLinkAtCaretPositionRule extends FormatRule {
int? len,
Object? data,
Attribute? attribute,
Map<String, Object?> 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<String, Object?> extraData = const {},
}) {
if (attribute!.scope != AttributeScope.INLINE) {
return null;
@ -206,7 +203,6 @@ class ResolveImageFormatRule extends FormatRule {
int? len,
Object? data,
Attribute? attribute,
Map<String, Object?> extraData = const {},
}) {
if (attribute == null || attribute.key != Attribute.style.key) {
return null;

@ -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<String, Object?> 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<String, Object?> 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<String, Object?> 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<String, Object?> 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<String, Object?> extraData = const {},
}) {
if (data is String) {
return null;
@ -393,7 +386,7 @@ class AutoFormatMultipleLinksRule extends InsertRule {
int? len,
Object? data,
Attribute? attribute,
Map<String, Object?> 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<String, Object?> extraData = const {},
}) {
if (data is! String || data != ' ') {
return null;
@ -535,7 +546,6 @@ class PreserveInlineStylesRule extends InsertRule {
int? len,
Object? data,
Attribute? attribute,
Map<String, Object?> 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<String, Object?> extraData = const {},
}) {
return Delta()
..retain(index + (len ?? 0))

@ -37,7 +37,6 @@ abstract class Rule {
int? len,
Object? data,
Attribute? attribute,
Map<String, Object?> extraData = const {},
});
RuleType get type;

Loading…
Cancel
Save