fix: Enabled link regex to be overridden (#1931)

* fix: Enabled link regex to be overridden

* chore: Updated formatting
pull/1934/head v9.4.4
Joep Heijnen 10 months ago committed by GitHub
parent 57302fdc6e
commit 01cf92a73e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      lib/src/models/rules/insert.dart
  2. 4
      lib/src/widgets/toolbar/buttons/link_style2_button.dart
  3. 3
      lib/src/widgets/toolbar/buttons/link_style_button.dart

@ -371,18 +371,18 @@ class AutoFormatMultipleLinksRule extends InsertRule {
r'https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?(\/[^\s]*)?';
/// It requires a valid link in one link
static final oneLineLinkRegExp = RegExp(
_oneLineLinkPattern,
caseSensitive: false,
);
RegExp get oneLineLinkRegExp => RegExp(
_oneLineLinkPattern,
caseSensitive: false,
);
/// It detect if there is a link in the text whatever if it in the middle etc
// Used to solve bug https://github.com/singerdmx/flutter-quill/issues/1432
static final detectLinkRegExp = RegExp(
_detectLinkPattern,
caseSensitive: false,
);
static final linkRegExp = oneLineLinkRegExp;
RegExp get detectLinkRegExp => RegExp(
_detectLinkPattern,
caseSensitive: false,
);
RegExp get linkRegExp => oneLineLinkRegExp;
@override
Delta? applyRule(

@ -413,7 +413,9 @@ class _LinkStyleDialogState extends State<LinkStyleDialog> {
String? _validateLink(String? value) {
if ((value?.isEmpty ?? false) ||
!AutoFormatMultipleLinksRule.oneLineLinkRegExp.hasMatch(value!)) {
!const AutoFormatMultipleLinksRule()
.oneLineLinkRegExp
.hasMatch(value!)) {
return widget.validationMessage ?? 'That is not a valid URL';
}

@ -196,7 +196,8 @@ class _LinkDialogState extends State<_LinkDialog> {
late String _text;
RegExp get linkRegExp {
return widget.linkRegExp ?? AutoFormatMultipleLinksRule.oneLineLinkRegExp;
return widget.linkRegExp ??
const AutoFormatMultipleLinksRule().oneLineLinkRegExp;
}
late TextEditingController _linkController;

Loading…
Cancel
Save