diff --git a/app/lib/pages/home_page.dart b/app/lib/pages/home_page.dart index 60383e94..2c945bcc 100644 --- a/app/lib/pages/home_page.dart +++ b/app/lib/pages/home_page.dart @@ -6,6 +6,7 @@ import 'package:flutter_quill/models/documents/document.dart'; import 'package:flutter_quill/widgets/controller.dart'; import 'package:flutter_quill/widgets/editor.dart'; import 'package:flutter_quill/widgets/toolbar.dart'; +import 'package:url_launcher/url_launcher.dart'; class HomePage extends StatefulWidget { @override @@ -78,10 +79,17 @@ class _HomePageState extends State { enableInteractiveSelection: true, expands: false, padding: EdgeInsets.zero, + onLaunchUrl: _launchUrl, ), ), ), ], ); } + + void _launchUrl(String url) async { + if (await canLaunch(url)) { + await launch(url); + } + } } diff --git a/app/pubspec.lock b/app/pubspec.lock index 86094d48..4c85745c 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -74,6 +74,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" matcher: dependency: transitive description: @@ -95,6 +100,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0-nullsafety.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" quill_delta: dependency: transitive description: @@ -177,6 +189,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0-nullsafety.3" + url_launcher: + dependency: "direct main" + description: + name: url_launcher + url: "https://pub.dartlang.org" + source: hosted + version: "5.7.10" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+4" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+9" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.9" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5+1" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+3" vector_math: dependency: transitive description: @@ -186,4 +240,4 @@ packages: version: "2.1.0-nullsafety.3" sdks: dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.17.0 <2.0.0" + flutter: ">=1.22.0 <2.0.0" diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 3a6814e0..ed06341d 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -23,6 +23,7 @@ environment: dependencies: flutter: sdk: flutter + url_launcher: ^5.7.10 # The following adds the Cupertino Icons font to your application. diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index f37360d0..746d207c 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -22,6 +22,9 @@ import 'cursor.dart'; import 'default_styles.dart'; import 'delegate.dart'; +const urlPattern = + r"^((https?|http)://)?([-A-Z0-9.]+)(/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#/%=~_|!:‌​,.;]*)?$"; + abstract class EditorState extends State { TextEditingValue getTextEditingValue(); @@ -252,6 +255,8 @@ class _QuillEditorState extends State class _QuillEditorSelectionGestureDetectorBuilder extends EditorTextSelectionGestureDetectorBuilder { + static final urlRegExp = new RegExp(urlPattern, caseSensitive: false); + final _QuillEditorState _state; _QuillEditorSelectionGestureDetectorBuilder(this._state) : super(_state); @@ -313,10 +318,11 @@ class _QuillEditorSelectionGestureDetectorBuilder Leaf segment = segmentResult.node as Leaf; if (segment.style.containsKey(Attribute.link.key) && getEditor().widget.onLaunchUrl != null) { - if (getEditor().widget.readOnly) { - getEditor() - .widget - .onLaunchUrl(segment.style.attributes[Attribute.link.key].value); + String link = segment.style.attributes[Attribute.link.key].value; + if (getEditor().widget.readOnly && + link != null && + urlRegExp.firstMatch(link) != null) { + getEditor().widget.onLaunchUrl(link); } } } diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index 32507f6a..21301579 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -596,7 +596,7 @@ class _NumberPoint extends StatelessWidget { } if (this.indentLevelCounts.containsKey(level + 1)) { // last visited level is done, going up - this.indentLevelCounts[level + 1] = 0; + this.indentLevelCounts.remove(level + 1); } int count = (this.indentLevelCounts[level] ?? 0) + 1; this.indentLevelCounts[level] = count;