diff --git a/lib/settings.dart b/lib/settings.dart index 621018c2..8bfaa3f9 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -321,5 +321,3 @@ class Settings extends ChangeNotifier { }; } } - - diff --git a/lib/third_party/linkify/flutter_linkify.dart b/lib/third_party/linkify/flutter_linkify.dart index 0db37816..4e702841 100644 --- a/lib/third_party/linkify/flutter_linkify.dart +++ b/lib/third_party/linkify/flutter_linkify.dart @@ -1,6 +1,7 @@ +// Code Originally taken from https://github.com/Cretezy/flutter_linkify/ +// +// Now uses local `linkify` // -// Code Originally taken from https://github.com/Cretezy/flutter_linkify/ and -// subsequently modified... // Original License for this code: // MIT License // Copyright (c) 2020 Charles-William Crete @@ -23,14 +24,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. - import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'linkify.dart'; - +export 'linkify.dart' show LinkifyElement, LinkifyOptions, LinkableElement, TextElement, Linkifier; /// Callback clicked link typedef LinkCallback = void Function(LinkableElement link); @@ -131,9 +131,9 @@ class Linkify extends StatelessWidget { .bodyText2 ?.merge(style) .copyWith( - color: Colors.blueAccent, - decoration: TextDecoration.underline, - ) + color: Colors.blueAccent, + decoration: TextDecoration.underline, + ) .merge(linkStyle), ), textAlign: textAlign, @@ -295,9 +295,9 @@ class SelectableLinkify extends StatelessWidget { .bodyText2 ?.merge(style) .copyWith( - color: Colors.blueAccent, - decoration: TextDecoration.underline, - ) + color: Colors.blueAccent, + decoration: TextDecoration.underline, + ) .merge(linkStyle), ), textAlign: textAlign, @@ -331,26 +331,26 @@ class LinkableSpan extends WidgetSpan { required MouseCursor mouseCursor, required InlineSpan inlineSpan, }) : super( - child: MouseRegion( - cursor: mouseCursor, - child: Text.rich( - inlineSpan, - ), - ), - ); + child: MouseRegion( + cursor: mouseCursor, + child: Text.rich( + inlineSpan, + ), + ), + ); } /// Raw TextSpan builder for more control on the RichText TextSpan buildTextSpan( - List elements, { - TextStyle? style, - TextStyle? linkStyle, - LinkCallback? onOpen, - bool useMouseRegion = false, - }) { + List elements, { + TextStyle? style, + TextStyle? linkStyle, + LinkCallback? onOpen, + bool useMouseRegion = false, +}) { return TextSpan( children: elements.map( - (element) { + (element) { if (element is LinkableElement) { if (useMouseRegion) { return LinkableSpan( diff --git a/lib/third_party/linkify/linkify.dart b/lib/third_party/linkify/linkify.dart index ea6f027a..381babb6 100644 --- a/lib/third_party/linkify/linkify.dart +++ b/lib/third_party/linkify/linkify.dart @@ -1,4 +1,6 @@ -// Originally from linkify +// Originally from linkify https://github.com/Cretezy/linkify/blob/master/lib/linkify.dart +// Removed options `removeWWW` and `humanize` +// // MIT License // // Copyright (c) 2019 Charles-William Crete @@ -43,8 +45,7 @@ class LinkableElement extends LinkifyElement { bool operator ==(other) => equals(other); @override - bool equals(other) => - other is LinkableElement && super.equals(other) && other.url == url; + bool equals(other) => other is LinkableElement && super.equals(other) && other.url == url; } /// Represents an element containing text @@ -66,17 +67,10 @@ class TextElement extends LinkifyElement { abstract class Linkifier { const Linkifier(); - List parse( - List elements, LinkifyOptions options); + List parse(List elements, LinkifyOptions options); } class LinkifyOptions { - /// Removes http/https from shown URLs. - final bool humanize; - - /// Removes www. from shown URLs. - final bool removeWww; - /// Enables loose URL parsing (any string with "." is a URL). final bool looseUrl; @@ -87,8 +81,6 @@ class LinkifyOptions { final bool excludeLastPeriod; const LinkifyOptions({ - this.humanize = true, - this.removeWww = false, this.looseUrl = false, this.defaultToHttps = false, this.excludeLastPeriod = true, @@ -106,10 +98,10 @@ const defaultLinkifiers = [_urlLinkifier]; /// Uses [linkTypes] to enable some types of links (URL, email). /// Will default to all (if `null`). List linkify( - String text, { - LinkifyOptions options = const LinkifyOptions(), - List linkifiers = defaultLinkifiers, - }) { + String text, { + LinkifyOptions options = const LinkifyOptions(), + List linkifiers = defaultLinkifiers, +}) { var list = [TextElement(text)]; if (text.isEmpty) { diff --git a/lib/third_party/linkify/uri.dart b/lib/third_party/linkify/uri.dart index 4c432f09..7cca8072 100644 --- a/lib/third_party/linkify/uri.dart +++ b/lib/third_party/linkify/uri.dart @@ -1,4 +1,8 @@ -// Originally from linkify +// Originally from linkify: https://github.com/Cretezy/linkify/blob/master/lib/src/url.dart +// +// Removed handling of `removeWWW` and `humanize`. +// Removed auto-appending of `http(s)://` to the readable url +// // MIT License // // Copyright (c) 2019 Charles-William Crete @@ -49,9 +53,7 @@ class UrlLinkifier extends Linkifier { elements.forEach((element) { if (element is TextElement) { - var match = options.looseUrl - ? _looseUrlRegex.firstMatch(element.text) - : _urlRegex.firstMatch(element.text); + var match = options.looseUrl ? _looseUrlRegex.firstMatch(element.text) : _urlRegex.firstMatch(element.text); if (match == null) { list.add(element); @@ -66,32 +68,15 @@ class UrlLinkifier extends Linkifier { var originalUrl = match.group(2)!; String? end; - if ((options.excludeLastPeriod) && - originalUrl[originalUrl.length - 1] == ".") { + if ((options.excludeLastPeriod) && originalUrl[originalUrl.length - 1] == ".") { end = "."; originalUrl = originalUrl.substring(0, originalUrl.length - 1); } var url = originalUrl; - // We do not, ever, change the original text of a message. - if (options.defaultToHttps) { - url = url.replaceFirst('http://', 'https://'); - } - - // These options are intended for the human-readable portion of - // the URI - if (options.humanize) { - originalUrl = originalUrl.replaceFirst(RegExp(r'https?://'), ''); - } - - if (options.removeWww) { - originalUrl = originalUrl.replaceFirst(RegExp(r'www\.'), ''); - } - list.add(UrlElement(originalUrl, url)); - if (end != null) { list.add(TextElement(end)); } diff --git a/lib/widgets/messagebubble.dart b/lib/widgets/messagebubble.dart index f1a26eee..948351cd 100644 --- a/lib/widgets/messagebubble.dart +++ b/lib/widgets/messagebubble.dart @@ -2,8 +2,6 @@ import 'dart:io'; import 'package:cwtch/models/message.dart'; import 'package:cwtch/third_party/linkify/flutter_linkify.dart'; -import 'package:cwtch/third_party/linkify/linkify.dart'; -import 'package:cwtch/third_party/linkify/uri.dart'; import 'package:cwtch/widgets/malformedbubble.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -69,7 +67,7 @@ class MessageBubbleState extends State { wdgMessage = SelectableLinkify( text: widget.content + '\u202F', // TODO: onOpen breaks the "selectable" functionality. Maybe something to do with gesture handler? - options: LinkifyOptions(humanize: false, removeWww: false, looseUrl: true, defaultToHttps: true), + options: LinkifyOptions(looseUrl: true, defaultToHttps: true), linkifiers: [UrlLinkifier()], onOpen: (link) { _modalOpenLink(context, link);