Skip to content

Commit

Permalink
Link pattern bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Dec 7, 2023
1 parent 3be21fb commit 6066f2f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## 9.0.0-dev-7
* Fix a bug in chaning the background/font color of ol/ul list
* Flutter Quill Extensions:
* Fix link bug in the video url
* Fix patterns

## 9.0.0-dev-6
* Move the `child` from `QuillToolbarConfigurations` into `QuillToolbar` directly
* Bug fixes
Expand Down
16 changes: 8 additions & 8 deletions example/lib/presentation/quill/quill_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ class _QuillScreenState extends State<QuillScreen> {
codeBlock: QuillEditorCodeBlockElementOptions(
enableLineNumbers: true,
),
// orderedList: QuillEditorOrderedListElementOptions(
// backgroundColor: Colors.amber,
// fontColor: Colors.black,
// ),
// unorderedList: QuillEditorUnOrderedListElementOptions(
// backgroundColor: Colors.green,
// fontColor: Colors.red,
// ),
orderedList: QuillEditorOrderedListElementOptions(
backgroundColor: Colors.amber,
fontColor: Colors.black,
),
unorderedList: QuillEditorUnOrderedListElementOptions(
backgroundColor: Colors.green,
fontColor: Colors.red,
),
),
),
scrollController: _editorScrollController,
Expand Down
36 changes: 25 additions & 11 deletions flutter_quill_extensions/lib/embeds/others/image_video_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart' show QuillDialogTheme;
import 'package:flutter_quill/translations.dart';

import '../../utils/patterns.dart';

enum LinkType {
video,
image,
Expand All @@ -28,23 +30,15 @@ class TypeLinkDialog extends StatefulWidget {
class TypeLinkDialogState extends State<TypeLinkDialog> {
late String _link;
late TextEditingController _controller;
late RegExp _linkRegExp;
RegExp? _linkRegExp;

@override
void initState() {
super.initState();
_link = widget.link ?? '';
_controller = TextEditingController(text: _link);

final defaultLinkNonSecureRegExp = RegExp(
r'https?://.*?\.(?:png|jpe?g|gif|bmp|webp|tiff?)',
caseSensitive: false,
); // Not secure
// final defaultLinkRegExp = RegExp(
// r'https://.*?\.(?:png|jpe?g|gif|bmp|webp|tiff?)',
// caseSensitive: false,
// ); // Secure
_linkRegExp = widget.linkRegExp ?? defaultLinkNonSecureRegExp;
_linkRegExp = widget.linkRegExp;
}

@override
Expand Down Expand Up @@ -102,8 +96,28 @@ class TypeLinkDialogState extends State<TypeLinkDialog> {
Navigator.pop(context, _link.trim());
}

RegExp get linkRegExp {
final customRegExp = _linkRegExp;
if (customRegExp != null) {
return customRegExp;
}
switch (widget.linkType) {
case LinkType.video:
if (youtubeRegExp.hasMatch(_link)) {
return youtubeRegExp;
}
return videoRegExp;
case LinkType.image:
return imageRegExp;
}
}

bool _canPress() {
return _link.isNotEmpty && _linkRegExp.hasMatch(_link);
if (_link.isEmpty) {
return false;
}
if (widget.linkType == LinkType.image) {}
return _link.isNotEmpty && linkRegExp.hasMatch(_link);
}
}

Expand Down
17 changes: 17 additions & 0 deletions flutter_quill_extensions/lib/utils/patterns.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
RegExp base64RegExp = RegExp(
r'^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$',
);

final imageRegExp = RegExp(
r'https?://.*?\.(?:png|jpe?g|gif|bmp|webp|tiff?)',
caseSensitive: false,
);

final videoRegExp = RegExp(
r'\bhttps?://\S+\.(mp4|mov|avi|mkv|flv|wmv|webm)\b',
caseSensitive: false,
);
final youtubeRegExp = RegExp(
r'^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|live\/|v\/)?)([\w\-]+)(\S+)?$',
caseSensitive: false,
);
7 changes: 2 additions & 5 deletions flutter_quill_extensions/lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import 'package:http/http.dart' as http;

import '../embeds/widgets/image.dart';
import '../services/image_saver/s_image_saver.dart';

RegExp _base64 = RegExp(
r'^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$',
);
import 'patterns.dart';

bool isBase64(String str) {
return _base64.hasMatch(str);
return base64RegExp.hasMatch(str);
}

bool isHttpBasedUrl(String url) {
Expand Down
8 changes: 7 additions & 1 deletion lib/src/widgets/style_widgets/number_point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ class QuillEditorNumberPoint extends StatelessWidget {
alignment: AlignmentDirectional.topEnd,
width: width,
padding: EdgeInsetsDirectional.only(end: padding),
child: Text(withDot ? '$s.' : s, style: style),
color: context.quillEditorElementOptions?.orderedList.backgroundColor,
child: Text(
withDot ? '$s.' : s,
style: style.copyWith(
color: context.quillEditorElementOptions?.orderedList.fontColor,
),
),
);
}
if (attrs.containsKey(Attribute.indent.key)) {
Expand Down
2 changes: 1 addition & 1 deletion version.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const version = '9.0.0-dev-6';
const version = '9.0.0-dev-7';

0 comments on commit 6066f2f

Please sign in to comment.