-
Notifications
You must be signed in to change notification settings - Fork 78
Feature/paste image and text from clipboard #129 #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feature/paste image and text from clipboard #129 #173
Conversation
|
Still working on a way to bypass the toolbar paste and right-click paste on web |
|
@gspencergoog can you help us out here? |
|
To run the workflows? Sure. |
|
@gspencergoog cam upi help us figure out how to cover all of the basis for UI gestures, keyboard shortcuts and mouse gestures to enable image pasting across desktop, web and mobile as detailed here? |
|
Sorry, I'd like to, but I'm a bit busy at the moment. Maybe ask the framework team to help? |
|
Thanks, @gspencergoog . @Piinks -- any thoughts here? what's the right way to be able to paste an image in across platforms in Flutter and hit all of the UI gestures, e.g. Ctrl/Cmd+V, right-click Paste, menu Paste, etc.? thanks! |
|
Hey @csells! I am not sure I understand the question, what are you looking for help with? |
|
Hey Kate! The PR adds support for pasting images and text from the clipboard across platforms (desktop, mobile, web) in Flutter. @DeTuksa lists the places that image-pasting works, but he's still working on covering all paste methods — particularly toolbar-paste and right-click paste on web. So basically: how do we override right-click / toolbar Paste on the web so we can do an image paste? |
Good question! I do not know this. I will see if I can find out! |
|
@csells Have you tried using the package super_clipboard? https://pub.dev/packages/super_clipboard |
|
thanks, @loic-sharma . that looks pretty great! @DeTuksa do you want to take a look? |
|
Sure, thanks @csells. I'll check it out |
|
@csells the super_clipboard package came in really handy. Pasting now works across all platforms. On MacOS, pasting from Edit on toolbar still doesn't work, but the problem isn't limited to just pasting as it includes copying, cutting and select all. |
|
oh jeez. good catch on the copy/paste issues on editing. is that something you can track down, too? |
|
Totally. I'll dig into the issue as well and see what I can do. |
|
for this to work properly, what we need is a macos plugin that can iterate over what a normal macos app gets in the menu bar (it changes with every release of the OS in my experience) and allows you to override the functionality as you choose. Does that code exist inside the Flutter framework that we can hijack and repurpose? |
|
Okay that sounds good. Let me take a look and see if such code exist for us to use. |
|
@csells after going through the flutter repo, there's no existing Flutter code that we could hijack and repurpose for this particular use case. Like you mentioned earlier, we would need a macos plugin for this. |
|
I don't know if this is true, but Opus 4.5 says that you can handle the macOS menu items in one of several ways. Do you want to see if any of this works, @DeTuksa ? How to Override macOS Menu Item Handlers in FlutterYou can customize or replace macOS menu item handlers using the 1. Basic Custom Menu with HandlersUse Dart 2. Using Platform-Provided Menu ItemsFor standard macOS menu items (About, Quit, Hide, etc.), use Dart Available platform-provided menu types on macOS:
3. Complete Example with State ManagementHere's a [full working example](https://github.com/flutter/flutter/blob/ef3dbceed24a4cf545d6b538916cbc8b44ce29d6/examples/api/lib/material/platform_menu_bar/platform_menu_bar.0.dart#L8-L142) from the Flutter repo: Dart 4. Augmenting Existing HandlersTo augment rather than replace behavior, you can call custom code in your Dart Key Points:
The Note: Search results are limited. [View more examples on GitHub](https://github.com/flutter/flutter/search?q=PlatformMenuBar+onSelected&type=code). You said: I don't want to replace the menubarI don't want to replace the menubar in my app -- I want to provide augmented functionality for whatever menubar behavior is already there. specifically, I'd like to handle the Paste menu item to support image paste (which is not handled by default in Flutter). Copilot said: Ah, that's a different scenario! You wantAh, that's a different scenario! You want to intercept existing menu items (like Paste) rather than replace the entire menu bar. Unfortunately, Flutter's For augmenting the existing Edit > Paste functionality specifically, you'll want to use platform channels to listen for paste events at a lower level. Here are your options: Option 1: Listen for Paste Intent/Shortcut (Recommended)Flutter has a Dart However, this won't help with the Edit menu itself - it only intercepts the keyboard shortcut. Option 2: Platform Channel for Clipboard Images (Better Solution)Flutter's Solution: Create a Custom macOS Plugin to Handle Image PasteSince you want to augment (not replace) the existing Paste behavior, you'll need to create a platform channel that intercepts clipboard access at the native macOS level. Here's how: 1. Create a Method Channel for Custom Paste HandlingIn your Flutter app: Dart 2. Create the Native macOS Plugin CodeCreate a file Swift 3. Register the PluginIn Swift 4. Override Paste Behavior in Your TextFieldNow use it in your widgets: Dart Alternative: Intercept at the Responder Level (More Complex)If you need to truly intercept the Edit > Paste menu item (not just Cmd+V), you'd need to override the responder chain at the native level: Create Swift Then use this custom view controller in your MainFlutterWindow. swift. SummaryThe key insight: You cannot easily augment menu handlers without native code because:
The approach above:
|
@csells, solutions 1-3 are great. Replacing the macOS menu items works fine like I previously mentioned. However, when we take that approach we lose the original menu items. I have attached a screenshot of what it looks like. The code used is also attached below For the Copilot solution of using Native code would serve as the best bet, but since this is a package, there’s no room for that. Should we proceed with the PlatformMenuBar as it is? |
|
can we build a separate package to allow us to override the existing implementations? |
|
Yeah that's the best option right now. Already started working on one |
|
Nice!! |
This PR addresses pasting images into the textfield and preserving pasting of text. #129
Mobile Check:
Desktop Check:
Web Check:
Pre-launch Checklist
///).