From bf21b7f42c672d75be8953f8f2e5a7602a8acb4a Mon Sep 17 00:00:00 2001 From: 2ndbeam <2ndbeam@disroot.org> Date: Thu, 23 Apr 2026 12:13:10 +0300 Subject: [PATCH] feat: Implement paste shortcut and remove popup menu option taken from https://github.com/krille-chan/fluffychat/pull/2775 --- lib/l10n/intl_en.arb | 7 +------ lib/l10n/intl_ru.arb | 5 ----- lib/pages/chat/chat.dart | 19 ++++++++++++++----- lib/pages/chat/chat_input_row.dart | 15 --------------- 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index f8ad303c..b71dd81f 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -1618,11 +1618,6 @@ "type": "String", "placeholders": {} }, - "pasteImage": "Image from clipboard", - "@pasteImage": { - "type": "String", - "placeholders": {} - }, "sendImages": "Send {count} image", "@sendImages": { "type": "String", @@ -2808,4 +2803,4 @@ "removeTag": "Remove tag", "tagName": "Tag name", "createNewTag": "Create new tag" -} \ No newline at end of file +} diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index 307a2618..c0e5490d 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -1452,11 +1452,6 @@ "type": "String", "placeholders": {} }, - "pasteImage": "Изображение из буфера обмена", - "@pasteImage": { - "type": "String", - "placeholders": {} - }, "sendMessages": "Отправить сообщения", "@sendMessages": { "type": "String", diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 44766d96..0a5ab9fc 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -344,6 +344,12 @@ class ChatController extends State } } + return KeyEventResult.ignored; + } else if (evt is KeyDownEvent && + evt.logicalKey == LogicalKeyboardKey.keyV && + (HardwareKeyboard.instance.isControlPressed || + HardwareKeyboard.instance.isMetaPressed)) { + sendImageFromClipBoardAction(); return KeyEventResult.ignored; } else { return KeyEventResult.ignored; @@ -659,10 +665,17 @@ class ChatController extends State Future sendImageFromClipBoard(Uint8List? image) async { if (image == null) return; + if (!mounted) return; + + final mimeType = lookupMimeType('', headerBytes: image); + final fileType = mimeType == null ? null : extensionFromMime(mimeType); + final extension = fileType == null ? '' : '.$fileType'; + final fileName = 'clipboard-image$extension'; + await showAdaptiveDialog( context: context, builder: (c) => SendFileDialog( - files: [XFile.fromData(image)], + files: [XFile.fromData(image, name: fileName, mimeType: mimeType)], room: room, outerContext: context, threadRootEventId: activeThreadId, @@ -1248,9 +1261,6 @@ class ChatController extends State case AddPopupMenuActions.location: sendLocationAction(); return; - case AddPopupMenuActions.pasteImage: - sendImageFromClipBoardAction(); - return; } } @@ -1458,5 +1468,4 @@ enum AddPopupMenuActions { photoCamera, videoCamera, location, - pasteImage, } diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index 2cf0159e..c0a664f6 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -171,21 +171,6 @@ class ChatInputRow extends StatelessWidget { contentPadding: const EdgeInsets.all(0), ), ), - if (!PlatformInfos.isMobile) - PopupMenuItem( - value: AddPopupMenuActions.pasteImage, - child: ListTile( - leading: CircleAvatar( - backgroundColor: - theme.colorScheme.onPrimaryContainer, - foregroundColor: - theme.colorScheme.primaryContainer, - child: const Icon(Icons.content_paste), - ), - title: Text(L10n.of(context).pasteImage), - contentPadding: const EdgeInsets.all(0), - ), - ), PopupMenuItem( value: AddPopupMenuActions.image, child: ListTile(