opt context menu

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-07-21 20:44:14 +08:00
parent 8f48ddb42a
commit 0164e32b70
6 changed files with 140 additions and 81 deletions

View File

@@ -11,7 +11,7 @@ Widget dynTextMenuBuilder(
ContextMenuButtonItem(
label: '文本',
onPressed: () {
state.hideToolbar();
state.hideAndClear();
_showTextDialog(text);
},
),
@@ -21,9 +21,7 @@ Widget dynTextMenuBuilder(
ContextMenuButtonItem(
label: '表情',
onPressed: () {
state
..hideToolbar()
..clearSelection();
state.hideAndClear();
_showEmoteDialog(moduleDynamic);
},
),

View File

@@ -0,0 +1,40 @@
part of 'package:PiliPlus/pages/live_room/superchat/superchat_card.dart';
Widget scMenuBuilder(
BuildContext context,
SelectableRegionState state,
) {
final buttonItems = state.contextMenuButtonItems;
if (state.isUncollapsed) {
buttonItems
..insertOrAdd(
3,
ContextMenuButtonItem(
label: '视频',
onPressed: () {
state.onMenuPressed(
(text) => PiliScheme.videoPush(null, text),
);
},
),
)
..insertOrAdd(
4,
ContextMenuButtonItem(
label: '搜索',
onPressed: () {
state.onMenuPressed(
(text) => Get.toNamed(
'/searchResult',
parameters: {'keyword': text},
),
);
},
),
);
}
return AdaptiveTextSelectionToolbar.buttonItems(
buttonItems: buttonItems,
anchors: state.contextMenuAnchors,
);
}

View File

@@ -46,9 +46,7 @@ void showReplyCopyDialog(
ContextMenuButtonItem(
label: showEmote ? '文本' : '表情',
onPressed: () {
state
..hideToolbar()
..clearSelection();
state.hideAndClear();
showEmote = !showEmote;
(context as Element).markNeedsBuild();
},
@@ -58,55 +56,49 @@ void showReplyCopyDialog(
state.addLaunchMenuIfNeeded(buttonItems, index: 4);
}
}
try {
if (state.selectionEndpoints.first !=
state.selectionEndpoints[1]) {
buttonItems.add(
ContextMenuButtonItem(
onPressed: () {
final selectedText = (state as dynamic).selectable
?.getSelectedContent()
?.plainText;
String text = RegExp.escape(selectedText);
if (ReplyGrpc.enableFilter) text = '|$text';
if (state.isUncollapsed) {
buttonItems.add(
ContextMenuButtonItem(
onPressed: () {
String text = RegExp.escape(state.selectedText!);
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,
),
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: '加入过滤',
),
);
}
} catch (_) {}
),
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,