Skip to content

Commit f2a90eb

Browse files
authored
use NSDataDetector to extract URI on macOS (#1638)
1 parent c81d25b commit f2a90eb

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

lib/utils/reg_exp_utils.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
final mentionRegExp = RegExp(r'@(\S*)$');
22
final mentionNumberRegExp = RegExp(r'@(\d{4,})');
3-
// ignore: avoid-non-ascii-symbols
43
final uriRegExp = RegExp(
54
r'\b[a-zA-z+]+:(?://)?[\w-]+(?:\.[\w-]+)*(?:[\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?\b/?');
65
final botNumberRegExp = RegExp(r'(?<!\d)7000\d{6}(?!\d)');

lib/widgets/high_light_text.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:math';
22
import 'dart:ui' as ui;
33

4+
import 'package:data_detector/data_detector.dart';
45
import 'package:emojis/emoji.dart';
56
import 'package:equatable/equatable.dart';
67
import 'package:flutter/foundation.dart';
@@ -507,8 +508,16 @@ class _MatchedSpans {
507508

508509
class UrlTextMatcher extends TextMatcher implements EquatableMixin {
509510
UrlTextMatcher(BuildContext context)
510-
: super.regExp(
511-
regExp: uriRegExp,
511+
: super.textRangesFromText(
512+
textRangesFromText: (text) {
513+
if (kPlatformIsDarwin) {
514+
final dataDetector =
515+
DataDetector(NSTextCheckingType.NSTextCheckingTypeLink);
516+
return dataDetector.matchesInString(text).map((e) => e.range);
517+
} else {
518+
return TextMatcher._textRangesFromText(text, uriRegExp);
519+
}
520+
},
512521
matchBuilder: (
513522
span,
514523
displayString,

macos/Podfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ PODS:
2727
- FlutterMacOS
2828
- network_info_plus (0.0.1):
2929
- FlutterMacOS
30+
- objective_c (0.0.1):
31+
- FlutterMacOS
3032
- ogg_opus_player (0.0.1):
3133
- FlutterMacOS
3234
- package_info_plus (0.0.1):
@@ -90,6 +92,7 @@ DEPENDENCIES:
9092
- local_auth_darwin (from `Flutter/ephemeral/.symlinks/plugins/local_auth_darwin/darwin`)
9193
- mixin_logger (from `Flutter/ephemeral/.symlinks/plugins/mixin_logger/macos`)
9294
- network_info_plus (from `Flutter/ephemeral/.symlinks/plugins/network_info_plus/macos`)
95+
- objective_c (from `Flutter/ephemeral/.symlinks/plugins/objective_c/macos`)
9396
- ogg_opus_player (from `Flutter/ephemeral/.symlinks/plugins/ogg_opus_player/macos`)
9497
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
9598
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
@@ -140,6 +143,8 @@ EXTERNAL SOURCES:
140143
:path: Flutter/ephemeral/.symlinks/plugins/mixin_logger/macos
141144
network_info_plus:
142145
:path: Flutter/ephemeral/.symlinks/plugins/network_info_plus/macos
146+
objective_c:
147+
:path: Flutter/ephemeral/.symlinks/plugins/objective_c/macos
143148
ogg_opus_player:
144149
:path: Flutter/ephemeral/.symlinks/plugins/ogg_opus_player/macos
145150
package_info_plus:
@@ -184,6 +189,7 @@ SPEC CHECKSUMS:
184189
local_auth_darwin: 66e40372f1c29f383a314c738c7446e2f7fdadc3
185190
mixin_logger: 5e5bd35ba38da1ff4939ee5ec83260d7fc5258fc
186191
network_info_plus: aeb9c4ed699cae128bc94b9d0f04f2389a414cbb
192+
objective_c: c13d3306e0fbf006bad001fd523e4bf8ebda8953
187193
ogg_opus_player: 67fc56771b16586b9b2478f848e632f751400604
188194
package_info_plus: fa739dd842b393193c5ca93c26798dff6e3d0e0c
189195
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46

macos/Runner.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@
343343
"${BUILT_PRODUCTS_DIR}/local_auth_darwin/local_auth_darwin.framework",
344344
"${BUILT_PRODUCTS_DIR}/mixin_logger/mixin_logger.framework",
345345
"${BUILT_PRODUCTS_DIR}/network_info_plus/network_info_plus.framework",
346+
"${BUILT_PRODUCTS_DIR}/objective_c/objective_c.framework",
346347
"${BUILT_PRODUCTS_DIR}/ogg_opus_player/ogg_opus_player.framework",
347348
"${BUILT_PRODUCTS_DIR}/package_info_plus/package_info_plus.framework",
348349
"${BUILT_PRODUCTS_DIR}/path_provider_foundation/path_provider_foundation.framework",
@@ -374,6 +375,7 @@
374375
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/local_auth_darwin.framework",
375376
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/mixin_logger.framework",
376377
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/network_info_plus.framework",
378+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/objective_c.framework",
377379
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ogg_opus_player.framework",
378380
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/package_info_plus.framework",
379381
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider_foundation.framework",

pubspec.lock

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ packages:
360360
url: "https://pub.dev"
361361
source: hosted
362362
version: "2.3.6"
363+
data_detector:
364+
dependency: "direct main"
365+
description:
366+
path: "packages/data_detector"
367+
ref: "66a8ed5f955fa35c9aaac76842b9dab83c51db92"
368+
resolved-ref: "66a8ed5f955fa35c9aaac76842b9dab83c51db92"
369+
url: "https://github.com/MixinNetwork/flutter-plugins.git"
370+
source: git
371+
version: "0.0.1"
363372
dbus:
364373
dependency: "direct main"
365374
description:
@@ -1344,6 +1353,14 @@ packages:
13441353
url: "https://pub.dev"
13451354
source: hosted
13461355
version: "0.5.0"
1356+
objective_c:
1357+
dependency: transitive
1358+
description:
1359+
name: objective_c
1360+
sha256: "77c341fce45bb3865a7bc3ddee4201605799e3de2f7af200e8dae26369d210ea"
1361+
url: "https://pub.dev"
1362+
source: hosted
1363+
version: "1.1.0"
13471364
octo_image:
13481365
dependency: "direct main"
13491366
description:
@@ -1873,8 +1890,8 @@ packages:
18731890
dependency: "direct main"
18741891
description:
18751892
path: "packages/string_tokenizer"
1876-
ref: "0334bbaa7293c72398eaf4571ba7ba2b5df2302d"
1877-
resolved-ref: "0334bbaa7293c72398eaf4571ba7ba2b5df2302d"
1893+
ref: "66a8ed5f955fa35c9aaac76842b9dab83c51db92"
1894+
resolved-ref: "66a8ed5f955fa35c9aaac76842b9dab83c51db92"
18781895
url: "https://github.com/MixinNetwork/flutter-plugins.git"
18791896
source: git
18801897
version: "0.0.1"
@@ -2313,5 +2330,5 @@ packages:
23132330
source: hosted
23142331
version: "3.1.2"
23152332
sdks:
2316-
dart: ">=3.5.0-259.0.dev <4.0.0"
2333+
dart: ">=3.5.0 <4.0.0"
23172334
flutter: ">=3.22.0"

pubspec.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ publish_to: none
1515
version: 1.10.1+285
1616

1717
environment:
18-
sdk: '^3.2.0'
18+
sdk: '^3.5.0'
1919

2020
dependencies:
2121
android_id: ^0.4.0
@@ -121,7 +121,7 @@ dependencies:
121121
git:
122122
url: https://github.com/MixinNetwork/flutter-plugins.git
123123
path: packages/string_tokenizer
124-
ref: 0334bbaa7293c72398eaf4571ba7ba2b5df2302d
124+
ref: 66a8ed5f955fa35c9aaac76842b9dab83c51db92
125125
super_clipboard: ^0.8.19
126126
super_context_menu: ^0.8.19
127127
super_native_extensions: ^0.8.19
@@ -158,6 +158,12 @@ dependencies:
158158
ref: 210839e1e9311bcddeb733297a565721692033ee
159159
hexagon: ^0.2.0
160160
breakpad_client: ^0.0.2
161+
data_detector:
162+
git:
163+
url: https://github.com/MixinNetwork/flutter-plugins.git
164+
ref: 66a8ed5f955fa35c9aaac76842b9dab83c51db92
165+
path: packages/data_detector
166+
161167
dev_dependencies:
162168
build_runner: ^2.4.8
163169
debug_info_collector:

0 commit comments

Comments
 (0)