opt dyn/reply text menu

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-07-16 20:25:21 +08:00
parent f7cd1aa502
commit 177493fe38
31 changed files with 550 additions and 268 deletions

View File

@@ -0,0 +1,114 @@
part of 'package:PiliPlus/pages/dynamics/widgets/content_panel.dart';
Widget dynTextMenuBuilder(
EditableTextState state,
String text,
ModuleDynamicModel? moduleDynamic,
) {
final buttonItems = state.contextMenuButtonItems
..insertOrAdd(
3,
ContextMenuButtonItem(
label: '文本',
onPressed: () {
state.hideToolbar();
_showTextDialog(text);
},
),
)
..insertOrAdd(
4,
ContextMenuButtonItem(
label: '表情',
onPressed: () {
state
..hideToolbar()
..clearSelectionIfNeeded();
_showEmoteDialog(moduleDynamic);
},
),
);
return AdaptiveTextSelectionToolbar.buttonItems(
buttonItems: buttonItems,
anchors: state.contextMenuAnchors,
);
}
void _showEmoteDialog(ModuleDynamicModel? moduleDynamic) {
if (moduleDynamic == null) return;
final richTextNodes =
moduleDynamic.desc?.richTextNodes ??
moduleDynamic.major?.opus?.summary?.richTextNodes;
if (richTextNodes == null || richTextNodes.isEmpty) return;
Map<String, Emoji>? emotes;
for (final e in richTextNodes) {
if (e.type == 'RICH_TEXT_NODE_TYPE_EMOJI') {
emotes ??= <String, Emoji>{};
if (!emotes.containsKey(e.origText)) {
emotes[e.origText!] = e.emoji!;
}
}
}
if (emotes == null || emotes.isEmpty) return;
showDialog(
context: Get.context!,
builder: (context) => Dialog(
child: Padding(
padding: const .symmetric(horizontal: 20, vertical: 16),
child: SelectableText.rich(
TextSpan(
children: emotes!.entries.mapIndexed(
(i, e) {
final emoji = e.value;
final size = emoji.size * 25.0;
return TextSpan(
children: [
if (i != 0) const TextSpan(text: '\n\n'),
WidgetSpan(
child: NetworkImgLayer(
src: emoji.url,
type: .emote,
width: size,
height: size,
),
),
TextSpan(text: '\n${e.key}\n${emoji.url}'),
],
);
},
).toList(),
),
contextMenuBuilder: openUrlMenuBuilder,
style: const TextStyle(fontSize: 15, height: 1.7),
scrollPhysics: const ClampingScrollPhysicsExt(),
),
),
),
);
}
void _showTextDialog(String text) {
showDialog(
context: Get.context!,
builder: (context) => Dialog(
child: Padding(
padding: const .symmetric(horizontal: 20, vertical: 16),
child: SelectableText(
text,
contextMenuBuilder: openUrlMenuBuilder,
style: const TextStyle(fontSize: 15, height: 1.7),
scrollPhysics: const ClampingScrollPhysicsExt(),
),
),
),
);
}
Widget openUrlMenuBuilder(_, EditableTextState state) {
final buttonItems = state.contextMenuButtonItems;
state.addLaunchMenuIfNeeded(buttonItems, index: 3);
return AdaptiveTextSelectionToolbar.buttonItems(
buttonItems: buttonItems,
anchors: state.contextMenuAnchors,
);
}

View File

@@ -0,0 +1,119 @@
part of 'package:PiliPlus/pages/video/reply/widgets/reply_item_grpc.dart';
void showReplyCopyDialog(
BuildContext context,
String message,
Map<String, Emote> emotes,
) {
bool showEmote = false;
showDialog(
context: context,
builder: (context) => Dialog(
constraints: const BoxConstraints.tightFor(width: 380),
child: Padding(
padding: const .symmetric(horizontal: 20, vertical: 16),
child: SelectableText.rich(
scrollPhysics: const ClampingScrollPhysicsExt(),
showEmote
? TextSpan(
children: emotes.entries.mapIndexed(
(i, e) {
final emote = e.value;
final size = emote.size.toInt() * 25.0;
return TextSpan(
children: [
if (i != 0) const TextSpan(text: '\n\n'),
WidgetSpan(
child: NetworkImgLayer(
src: emote.url,
type: .emote,
width: size,
height: size,
),
),
TextSpan(text: '\n${e.key}\n${emote.url}'),
],
);
},
).toList(),
)
: TextSpan(text: message),
contextMenuBuilder: (_, state) {
final buttonItems = state.contextMenuButtonItems;
final selection = state.textEditingValue.selection;
if (emotes.isNotEmpty) {
buttonItems.insertOrAdd(
3,
ContextMenuButtonItem(
label: showEmote ? '文本' : '表情',
onPressed: () {
state
..widget.focusNode.unfocus()
..hideToolbar();
showEmote = !showEmote;
(context as Element).markNeedsBuild();
},
),
);
if (showEmote) {
state.addLaunchMenuIfNeeded(buttonItems, index: 4);
}
}
if (!selection.isCollapsed) {
buttonItems.add(
ContextMenuButtonItem(
onPressed: () {
Navigator.of(context).pop();
final value = state.textEditingValue;
String text = RegExp.escape(
selection.textInside(value.text),
);
if (ReplyGrpc.enableFilter) text = '|$text';
showConfirmDialog(
context: context,
title: const Text('是否确认评论过滤的变更:'),
content: Text.rich(
TextSpan(
text: ReplyGrpc.replyRegExp.pattern,
children: [
TextSpan(
text: text,
style: const TextStyle(
color: Colors.green,
fontWeight: .bold,
),
),
],
),
),
onConfirm: () {
final filter = ReplyGrpc.replyRegExp.pattern + text;
ReplyGrpc.replyRegExp = RegExp(
filter,
caseSensitive: true,
);
ReplyGrpc.enableFilter = true;
GStorage.setting.put(
SettingBoxKey.banWordForReply,
filter,
);
SmartDialog.showToast('已保存');
},
);
},
label: '加入过滤',
),
);
}
return AdaptiveTextSelectionToolbar.buttonItems(
buttonItems: buttonItems,
anchors: state.contextMenuAnchors,
);
},
style: const TextStyle(fontSize: 15, height: 1.7),
),
),
),
);
}

View File

@@ -5111,9 +5111,11 @@ class EditableTextState extends State<EditableText>
) {
// Compare the current TextEditingValue with the pre-format new
// TextEditingValue value, in case the formatter would reject the change.
final shouldShowCaret = widget.readOnly
? _value.selection != value.selection
: _value != value;
final shouldShowCaret =
cause != .drag &&
(widget.readOnly
? _value.selection != value.selection
: _value != value);
if (shouldShowCaret) {
scheduleShowCaretOnScreen(withAnimation: true);
}

View File

@@ -1,6 +1,8 @@
import 'package:PiliPlus/common/style.dart';
import 'package:PiliPlus/common/widgets/button/icon_button.dart';
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
import 'package:PiliPlus/common/widgets/scroll_physics.dart'
show NeverSelectableScrollPhysics;
import 'package:PiliPlus/http/user.dart';
import 'package:PiliPlus/utils/image_utils.dart';
import 'package:PiliPlus/utils/platform_utils.dart';
@@ -73,6 +75,7 @@ void imageSaveDialog({
child: SelectableText(
title,
style: theme.textTheme.titleSmall,
scrollPhysics: const NeverSelectableScrollPhysics(),
),
)
else

View File

@@ -1,4 +1,6 @@
import 'package:PiliPlus/common/assets.dart';
import 'package:PiliPlus/common/widgets/scroll_physics.dart'
show NeverSelectableScrollPhysics;
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
@@ -35,7 +37,7 @@ class HttpError extends StatelessWidget {
errMsg ?? '没有数据',
textAlign: TextAlign.center,
style: theme.textTheme.titleSmall,
scrollPhysics: const NeverScrollableScrollPhysics(),
scrollPhysics: const NeverSelectableScrollPhysics(),
),
),
if (onReload != null)

View File

@@ -13,6 +13,8 @@ Widget tabBarView({
children: children,
);
final _springDescription = _customSpringDescription();
SpringDescription _customSpringDescription() {
final List<double> springDescription = Pref.springDescription;
return SpringDescription(
@@ -34,8 +36,6 @@ class CustomTabBarViewScrollPhysics extends ScrollPhysics {
return CustomTabBarViewScrollPhysics(parent: buildParent(ancestor));
}
static final _springDescription = _customSpringDescription();
@override
SpringDescription get spring => _springDescription;
}

View File

@@ -1,40 +0,0 @@
import 'package:PiliPlus/utils/platform_utils.dart';
import 'package:flutter/material.dart';
Widget selectableText(
String text, {
TextStyle? style,
}) {
if (PlatformUtils.isDesktop) {
return SelectionArea(
child: Text(
style: style,
text,
),
);
}
return SelectableText(
style: style,
text,
scrollPhysics: const NeverScrollableScrollPhysics(),
);
}
Widget selectableRichText(
TextSpan textSpan, {
TextStyle? style,
}) {
if (PlatformUtils.isDesktop) {
return SelectionArea(
child: Text.rich(
style: style,
textSpan,
),
);
}
return SelectableText.rich(
style: style,
textSpan,
scrollPhysics: const NeverScrollableScrollPhysics(),
);
}