mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-24 02:56:58 +08:00
copy/cut rich text
Closes #1047 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -19,6 +19,7 @@ import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/models/common/image_type.dart';
|
||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
@@ -1019,4 +1020,37 @@ class RichTextEditingController extends TextEditingController {
|
||||
}
|
||||
return newSelection;
|
||||
}
|
||||
|
||||
String? getSelectionText(TextSelection selection) {
|
||||
try {
|
||||
String text = '';
|
||||
final start = selection.start;
|
||||
final end = selection.end;
|
||||
for (var e in items) {
|
||||
final range = e.range;
|
||||
if (start >= range.end) {
|
||||
continue;
|
||||
}
|
||||
if (end <= range.start) {
|
||||
break;
|
||||
}
|
||||
if (e.isRich) {
|
||||
if (e.emote != null) {
|
||||
text += e.rawText;
|
||||
} else {
|
||||
text += e.text;
|
||||
}
|
||||
} else {
|
||||
text += e.text.substring(
|
||||
max(start, range.start) - range.start,
|
||||
min(end, range.end) - range.start,
|
||||
);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
} catch (e) {
|
||||
if (kDebugMode) debugPrint('err getSelectionText: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user