Skip to content

Commit

Permalink
TW-731: rebuild copy/paste text
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn committed Oct 11, 2023
1 parent 5181519 commit 0de1d68
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
6 changes: 5 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2760,5 +2760,9 @@
"thisMessageHasBeenEncrypted": "This message has been encrypted",
"roomCreationFailed": "Room creation failed",
"errorGettingPdf": "Error getting PDF",
"errorPreviewingFile": "Error previewing file"
"errorPreviewingFile": "Error previewing file",
"paste": "Paste",
"cut": "Cut",
"pasteImageFailed": "Paste image failed",
"copyImageFailed": "Copy image failed"
}
5 changes: 5 additions & 0 deletions lib/presentation/enum/chat/popup_menu_item_web_enum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum InputBarContextMenu {
copy,
cut,
paste,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:fluffychat/utils/clipboard.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' as flutter;

extension TextEdittingControllerExtension on TextEditingController {
Future<void> pasteText() async {
final start = selection.start;
final end = selection.end;
final pastedText = await Clipboard.instance.pasteText();
if (pastedText != null) {
if (start == -1 || end == -1) {
text = pastedText + text;
return;
}
if (start == end) {
final startText = text.substring(0, start);
final trailingText = text.substring(end, text.length);
text = startText + pastedText + trailingText;
} else {
text = text.replaceRange(start, end, pastedText);
}
}
}

Future<void> copyText() async {
final start = selection.start;
final end = selection.end;
if (start < end) {
await flutter.Clipboard.setData(
flutter.ClipboardData(
text: text.substring(start, end),
),
);
}
}

Future<void> cutText() async {
//TO-DO:
}
}

0 comments on commit 0de1d68

Please sign in to comment.