fix: 修复没有关键词时无法匹配时间、修复不显示关键词时不替换超链接、时间添加中文冒号匹配并提升分支判定严格程度
This commit is contained in:
@ -595,10 +595,21 @@ InlineSpan buildContent(
|
|||||||
e.replaceAll('?', '\\?').replaceAll('+', '\\+').replaceAll('*', '\\*')),
|
e.replaceAll('?', '\\?').replaceAll('+', '\\+').replaceAll('*', '\\*')),
|
||||||
];
|
];
|
||||||
|
|
||||||
final String patternStr =
|
String patternStr =
|
||||||
specialTokens.map(RegExp.escape).join('|') + r'|\b[0-9]{1,2}:[0-9]{2}\b';
|
specialTokens.map(RegExp.escape).join('|');
|
||||||
|
if (patternStr.isNotEmpty) {
|
||||||
|
patternStr += "|";
|
||||||
|
}
|
||||||
|
patternStr += r'(\b\d{1,2}[::]\d{2}\b)';
|
||||||
final RegExp pattern = RegExp(patternStr);
|
final RegExp pattern = RegExp(patternStr);
|
||||||
List<String> matchedStrs = [];
|
List<String> matchedStrs = [];
|
||||||
|
void addPlainTextSpan(str){
|
||||||
|
spanChilds.add(TextSpan(
|
||||||
|
text: str,
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () =>
|
||||||
|
replyReply(replyItem.root == 0 ? replyItem : fReplyItem)));
|
||||||
|
}
|
||||||
// 分割文本并处理每个部分
|
// 分割文本并处理每个部分
|
||||||
content.message.splitMapJoin(
|
content.message.splitMapJoin(
|
||||||
pattern,
|
pattern,
|
||||||
@ -636,7 +647,7 @@ InlineSpan buildContent(
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else if (matchStr.contains(':')) {
|
} else if (RegExp(r'^\b[0-9]{1,2}[::][0-9]{2}\b$').hasMatch(matchStr)) {
|
||||||
spanChilds.add(
|
spanChilds.add(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: ' $matchStr ',
|
text: ' $matchStr ',
|
||||||
@ -647,6 +658,7 @@ InlineSpan buildContent(
|
|||||||
..onTap = () {
|
..onTap = () {
|
||||||
// 跳转到指定位置
|
// 跳转到指定位置
|
||||||
try {
|
try {
|
||||||
|
matchStr = matchStr.replaceAll(':', ':');
|
||||||
SmartDialog.showToast('跳转至:$matchStr');
|
SmartDialog.showToast('跳转至:$matchStr');
|
||||||
Get.find<VideoDetailController>(tag: Get.arguments['heroTag'])
|
Get.find<VideoDetailController>(tag: Get.arguments['heroTag'])
|
||||||
.plPlayerController
|
.plPlayerController
|
||||||
@ -664,10 +676,13 @@ InlineSpan buildContent(
|
|||||||
String appUrlSchema = '';
|
String appUrlSchema = '';
|
||||||
final bool enableWordRe = setting.get(SettingBoxKey.enableWordRe,
|
final bool enableWordRe = setting.get(SettingBoxKey.enableWordRe,
|
||||||
defaultValue: false) as bool;
|
defaultValue: false) as bool;
|
||||||
if (enableWordRe &&
|
if (content.jumpUrl[matchStr] != null &&
|
||||||
content.jumpUrl[matchStr] != null &&
|
|
||||||
!matchedStrs.contains(matchStr)) {
|
!matchedStrs.contains(matchStr)) {
|
||||||
appUrlSchema = content.jumpUrl[matchStr]['app_url_schema'];
|
appUrlSchema = content.jumpUrl[matchStr]['app_url_schema'];
|
||||||
|
if (appUrlSchema.startsWith('bilibili://search') && !enableWordRe) {
|
||||||
|
addPlainTextSpan(matchStr);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
spanChilds.add(
|
spanChilds.add(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: content.jumpUrl[matchStr]['title'],
|
text: content.jumpUrl[matchStr]['title'],
|
||||||
@ -707,7 +722,7 @@ InlineSpan buildContent(
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (appUrlSchema.startsWith('bilibili://search') && enableWordRe) {
|
if (appUrlSchema.startsWith('bilibili://search')) {
|
||||||
spanChilds.add(
|
spanChilds.add(
|
||||||
WidgetSpan(
|
WidgetSpan(
|
||||||
child: Icon(
|
child: Icon(
|
||||||
@ -722,21 +737,13 @@ InlineSpan buildContent(
|
|||||||
// 只显示一次
|
// 只显示一次
|
||||||
matchedStrs.add(matchStr);
|
matchedStrs.add(matchStr);
|
||||||
} else {
|
} else {
|
||||||
spanChilds.add(TextSpan(
|
addPlainTextSpan(matchStr);
|
||||||
text: matchStr,
|
|
||||||
recognizer: TapGestureRecognizer()
|
|
||||||
..onTap = () =>
|
|
||||||
replyReply(replyItem.root == 0 ? replyItem : fReplyItem)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
onNonMatch: (String nonMatchStr) {
|
onNonMatch: (String nonMatchStr) {
|
||||||
spanChilds.add(TextSpan(
|
addPlainTextSpan(nonMatchStr);
|
||||||
text: nonMatchStr,
|
|
||||||
recognizer: TapGestureRecognizer()
|
|
||||||
..onTap = () =>
|
|
||||||
replyReply(replyItem.root == 0 ? replyItem : fReplyItem)));
|
|
||||||
return nonMatchStr;
|
return nonMatchStr;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user