Responding to @errorinn PR Comments
continuous-integration/drone/pr Build is pending
Details
continuous-integration/drone/pr Build is pending
Details
This commit is contained in:
parent
b3f06d6765
commit
cd1bf07fba
|
@ -321,5 +321,3 @@ class Settings extends ChangeNotifier {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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:
|
// Original License for this code:
|
||||||
// MIT License
|
// MIT License
|
||||||
// Copyright (c) 2020 Charles-William Crete
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
import 'linkify.dart';
|
import 'linkify.dart';
|
||||||
|
|
||||||
|
export 'linkify.dart' show LinkifyElement, LinkifyOptions, LinkableElement, TextElement, Linkifier;
|
||||||
|
|
||||||
/// Callback clicked link
|
/// Callback clicked link
|
||||||
typedef LinkCallback = void Function(LinkableElement link);
|
typedef LinkCallback = void Function(LinkableElement link);
|
||||||
|
@ -347,7 +347,7 @@ TextSpan buildTextSpan(
|
||||||
TextStyle? linkStyle,
|
TextStyle? linkStyle,
|
||||||
LinkCallback? onOpen,
|
LinkCallback? onOpen,
|
||||||
bool useMouseRegion = false,
|
bool useMouseRegion = false,
|
||||||
}) {
|
}) {
|
||||||
return TextSpan(
|
return TextSpan(
|
||||||
children: elements.map<InlineSpan>(
|
children: elements.map<InlineSpan>(
|
||||||
(element) {
|
(element) {
|
||||||
|
|
|
@ -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
|
// MIT License
|
||||||
//
|
//
|
||||||
// Copyright (c) 2019 Charles-William Crete
|
// Copyright (c) 2019 Charles-William Crete
|
||||||
|
@ -43,8 +45,7 @@ class LinkableElement extends LinkifyElement {
|
||||||
bool operator ==(other) => equals(other);
|
bool operator ==(other) => equals(other);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool equals(other) =>
|
bool equals(other) => other is LinkableElement && super.equals(other) && other.url == url;
|
||||||
other is LinkableElement && super.equals(other) && other.url == url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents an element containing text
|
/// Represents an element containing text
|
||||||
|
@ -66,17 +67,10 @@ class TextElement extends LinkifyElement {
|
||||||
abstract class Linkifier {
|
abstract class Linkifier {
|
||||||
const Linkifier();
|
const Linkifier();
|
||||||
|
|
||||||
List<LinkifyElement> parse(
|
List<LinkifyElement> parse(List<LinkifyElement> elements, LinkifyOptions options);
|
||||||
List<LinkifyElement> elements, LinkifyOptions options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class LinkifyOptions {
|
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).
|
/// Enables loose URL parsing (any string with "." is a URL).
|
||||||
final bool looseUrl;
|
final bool looseUrl;
|
||||||
|
|
||||||
|
@ -87,8 +81,6 @@ class LinkifyOptions {
|
||||||
final bool excludeLastPeriod;
|
final bool excludeLastPeriod;
|
||||||
|
|
||||||
const LinkifyOptions({
|
const LinkifyOptions({
|
||||||
this.humanize = true,
|
|
||||||
this.removeWww = false,
|
|
||||||
this.looseUrl = false,
|
this.looseUrl = false,
|
||||||
this.defaultToHttps = false,
|
this.defaultToHttps = false,
|
||||||
this.excludeLastPeriod = true,
|
this.excludeLastPeriod = true,
|
||||||
|
@ -109,7 +101,7 @@ List<LinkifyElement> linkify(
|
||||||
String text, {
|
String text, {
|
||||||
LinkifyOptions options = const LinkifyOptions(),
|
LinkifyOptions options = const LinkifyOptions(),
|
||||||
List<Linkifier> linkifiers = defaultLinkifiers,
|
List<Linkifier> linkifiers = defaultLinkifiers,
|
||||||
}) {
|
}) {
|
||||||
var list = <LinkifyElement>[TextElement(text)];
|
var list = <LinkifyElement>[TextElement(text)];
|
||||||
|
|
||||||
if (text.isEmpty) {
|
if (text.isEmpty) {
|
||||||
|
|
|
@ -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
|
// MIT License
|
||||||
//
|
//
|
||||||
// Copyright (c) 2019 Charles-William Crete
|
// Copyright (c) 2019 Charles-William Crete
|
||||||
|
@ -49,9 +53,7 @@ class UrlLinkifier extends Linkifier {
|
||||||
|
|
||||||
elements.forEach((element) {
|
elements.forEach((element) {
|
||||||
if (element is TextElement) {
|
if (element is TextElement) {
|
||||||
var match = options.looseUrl
|
var match = options.looseUrl ? _looseUrlRegex.firstMatch(element.text) : _urlRegex.firstMatch(element.text);
|
||||||
? _looseUrlRegex.firstMatch(element.text)
|
|
||||||
: _urlRegex.firstMatch(element.text);
|
|
||||||
|
|
||||||
if (match == null) {
|
if (match == null) {
|
||||||
list.add(element);
|
list.add(element);
|
||||||
|
@ -66,32 +68,15 @@ class UrlLinkifier extends Linkifier {
|
||||||
var originalUrl = match.group(2)!;
|
var originalUrl = match.group(2)!;
|
||||||
String? end;
|
String? end;
|
||||||
|
|
||||||
if ((options.excludeLastPeriod) &&
|
if ((options.excludeLastPeriod) && originalUrl[originalUrl.length - 1] == ".") {
|
||||||
originalUrl[originalUrl.length - 1] == ".") {
|
|
||||||
end = ".";
|
end = ".";
|
||||||
originalUrl = originalUrl.substring(0, originalUrl.length - 1);
|
originalUrl = originalUrl.substring(0, originalUrl.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = originalUrl;
|
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));
|
list.add(UrlElement(originalUrl, url));
|
||||||
|
|
||||||
|
|
||||||
if (end != null) {
|
if (end != null) {
|
||||||
list.add(TextElement(end));
|
list.add(TextElement(end));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@ import 'dart:io';
|
||||||
|
|
||||||
import 'package:cwtch/models/message.dart';
|
import 'package:cwtch/models/message.dart';
|
||||||
import 'package:cwtch/third_party/linkify/flutter_linkify.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:cwtch/widgets/malformedbubble.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
@ -69,7 +67,7 @@ class MessageBubbleState extends State<MessageBubble> {
|
||||||
wdgMessage = SelectableLinkify(
|
wdgMessage = SelectableLinkify(
|
||||||
text: widget.content + '\u202F',
|
text: widget.content + '\u202F',
|
||||||
// TODO: onOpen breaks the "selectable" functionality. Maybe something to do with gesture handler?
|
// 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()],
|
linkifiers: [UrlLinkifier()],
|
||||||
onOpen: (link) {
|
onOpen: (link) {
|
||||||
_modalOpenLink(context, link);
|
_modalOpenLink(context, link);
|
||||||
|
|
Loading…
Reference in New Issue