feat: Implement paste shortcut and remove popup menu option

taken from https://github.com/krille-chan/fluffychat/pull/2775
This commit is contained in:
Alexey 2026-04-23 12:13:10 +03:00
commit bf21b7f42c
4 changed files with 15 additions and 31 deletions

View file

@ -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"
}
}

View file

@ -1452,11 +1452,6 @@
"type": "String",
"placeholders": {}
},
"pasteImage": "Изображение из буфера обмена",
"@pasteImage": {
"type": "String",
"placeholders": {}
},
"sendMessages": "Отправить сообщения",
"@sendMessages": {
"type": "String",

View file

@ -344,6 +344,12 @@ class ChatController extends State<ChatPageWithRoom>
}
}
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<ChatPageWithRoom>
Future<void> 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<ChatPageWithRoom>
case AddPopupMenuActions.location:
sendLocationAction();
return;
case AddPopupMenuActions.pasteImage:
sendImageFromClipBoardAction();
return;
}
}
@ -1458,5 +1468,4 @@ enum AddPopupMenuActions {
photoCamera,
videoCamera,
location,
pasteImage,
}

View file

@ -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(