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,38 @@
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
import 'package:PiliPlus/utils/page_utils.dart';
import 'package:flutter/material.dart';
extension EditableTextExt on EditableTextState {
void addLaunchMenuIfNeeded(
List<ContextMenuButtonItem> buttonItems, {
required int index,
}) {
final selection = textEditingValue.selection;
if (!selection.isCollapsed) {
buttonItems.insertOrAdd(
index,
ContextMenuButtonItem(
label: '打开',
onPressed: () {
hideToolbar();
clearSelection(selection);
PageUtils.launchURL(
selection.textInside(textEditingValue.text).trim(),
);
},
),
);
}
}
void clearSelection(TextSelection currSelection) {
widget.controller.selection = .collapsed(offset: currSelection.end);
}
void clearSelectionIfNeeded() {
final selection = textEditingValue.selection;
if (!selection.isCollapsed) {
clearSelection(selection);
}
}
}