-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Desktop: Add write() method to Plugin Clipboard API #13348
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
Conversation
|
recheck |
| * }); | ||
| * ``` | ||
| */ | ||
| public async writeMultiple(content: ClipboardContent): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good, thank you! Since this is the generic method to write to clipboard, could it be called just write()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense, I committed a change to update the method name from writeMultiple() to write()
during my earlier testing I was seeing issues when I tried to use write() and I thought it might be some kind of conflict due to electron clipboard API also having a method called write(), but it seems that it was actually a caching issue with my copy as html plugin build that I was using to test the API (after deleting node_modules and dist in my plugin directory and rebuilding, I was able to use await joplin.clipboard.write without issue)
| clipboardData.image = this.electronNativeImage_.createFromDataURL(content.image); | ||
| } | ||
|
|
||
| this.electronClipboard_.write(clipboardData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If nothing was written, maybe skip this call? Unless we want to support clearing the clipboard, but I'm not sure we want this as that might be unexpected (we just merge two PR to avoid clearing the clipboard when copying nothing from the editor)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I committed a change to only write to clipboard if there's actually data to write
To test the change, I modified my plugin to attempt clipboard write even when no text is selected and verified that it does not overwrite existing clipboard content, and also tested to make sure that it still copies all formats to clipboard when there's valid content selected
|
That looks good, thank you! |
Summary
Adds a new
write()method to the plugin clipboard API that allows writing multiple formats (text/plain, text/html, and image) to the clipboard simultaneously.Background: see forum thread: https://discourse.joplinapp.org/t/is-it-possible-to-populate-both-text-html-and-text-plain-at-the-same-time-with-joplin-clipboard/46968
Overview
Currently, the plugin API provides writeText() and writeHtml() methods, but each call overwrites the previous clipboard content. This limitation prevents plugins from setting both plain text and HTML formats at the same time.
Changes
1. New ClipboardContent Interface (types.ts)
2. New write() Method (JoplinClipboard.ts)
<span class="platform-desktop">desktop</span>(Electron-only)Usage Example
Testing
Backward Compatibility
This change is fully backward compatible: