♻️ Refactor post

This commit is contained in:
2025-10-06 11:55:53 +08:00
parent a8a59ee30c
commit f871cd3b62
7 changed files with 1109 additions and 643 deletions

View File

@@ -77,16 +77,32 @@ class ChatInput extends HookConsumerWidget {
}
Future<void> handlePaste() async {
final clipboard = await Pasteboard.image;
if (clipboard == null) return;
final image = await Pasteboard.image;
if (image != null) {
onAttachmentsChanged([
...attachments,
UniversalFile(
data: XFile.fromData(image, mimeType: "image/jpeg"),
type: UniversalFileType.image,
),
]);
return;
}
onAttachmentsChanged([
...attachments,
UniversalFile(
data: XFile.fromData(clipboard, mimeType: "image/jpeg"),
type: UniversalFileType.image,
),
]);
final textData = await Clipboard.getData(Clipboard.kTextPlain);
if (textData != null && textData.text != null) {
final text = messageController.text;
final selection = messageController.selection;
final start = selection.start >= 0 ? selection.start : text.length;
final end = selection.end >= 0 ? selection.end : text.length;
final newText = text.replaceRange(start, end, textData.text!);
messageController.value = TextEditingValue(
text: newText,
selection: TextSelection.collapsed(
offset: start + textData.text!.length,
),
);
}
}
inputFocusNode.onKeyEvent = (node, event) {