mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-23 12:00:13 +08:00
replace SelectableText with SelectionArea
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
lib/utils/extension/selectable_region_ext.dart
Normal file
32
lib/utils/extension/selectable_region_ext.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension SelectableRegionStateExt on SelectableRegionState {
|
||||
void addLaunchMenuIfNeeded(
|
||||
List<ContextMenuButtonItem> buttonItems, {
|
||||
required int index,
|
||||
}) {
|
||||
try {
|
||||
if (selectionEndpoints.first != selectionEndpoints[1]) {
|
||||
buttonItems.insertOrAdd(
|
||||
index,
|
||||
ContextMenuButtonItem(
|
||||
label: '打开',
|
||||
onPressed: () {
|
||||
final text = (this as dynamic).selectable
|
||||
?.getSelectedContent()
|
||||
?.plainText
|
||||
.trim();
|
||||
hideToolbar();
|
||||
clearSelection();
|
||||
if (text != null && text.isNotEmpty) {
|
||||
PageUtils.launchURL(text);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user