CrossCopy / tauri-plugin-clipboard

A Tauri clipboard plugin with text, files, html, RTF, and image support. Clipboard content update monitoring is also supported.
https://crosscopy.github.io/tauri-plugin-clipboard/
MIT License
122 stars 6 forks source link

Can I writeText and writeHtml at the same time without triggering the event twice? #28

Closed Tester-957 closed 2 months ago

Tester-957 commented 2 months ago

I found that when using writeHtml, the html will be written to the clipboard, but the text will not be written. I can understand this. But when the text is copied and writeHtml is used again, the onTextUpdate event will be triggered.

Here are my steps:

  1. Control+C to copy arbitrary text to the clipboard
  2. Use the example writeHtml() to write HTML
  3. At this time the onClipboardUpdate event contains the text in step 1

Expected results: Step 3 should only listen for hasHTML, not the text from Step 1.🕷️ image

I think you can add a writeHtmlAndText(html,text) api😉

HuakunShen commented 2 months ago

I believe this is because the text from step one is not removed from the UI. So it's not a problem with the API. Maybe I can make the example clearer by refreshing all content displayed rather than appending the new clipboard content. If you take a screenshot after step 3 you will see the text, the html and a screenshot.

git pull the main branch to get the latest commit. https://github.com/CrossCopy/tauri-plugin-clipboard/commit/960e6d90a438bb3606549ccede92027e14bb7042

Not sure if this is what you want.

HuakunShen commented 2 months ago

And in your screenshot has hasHtml and hasText both equal to true. Are you on Mac? For me, after writing sample html, I only got hasHtml == true

image
Tester-957 commented 2 months ago

And in your screenshot has hasHtml and hasText both equal to true. Are you on Mac?在您的屏幕截图中, hasHtmlhasText 都等于 true。你在Mac上吗? For me, after writing sample html, I only got hasHtml == true 对我来说,编写示例 html 后,我只得到 hasHtml == true image

On Windows 11, confirm that it is the content left by the last text

Tester-957 commented 2 months ago

I believe this is because the text from step one is not removed from the UI. So it's not a problem with the API. Maybe I can make the example clearer by refreshing all content displayed rather than appending the new clipboard content. If you take a screenshot after step 3 you will see the text, the html and a screenshot.

git pull the main branch to get the latest commit. 960e6d9

Not sure if this is what you want.

When I copy HTML content on Windows, HTML and text will be triggered at the same time, such as copying code in VSCode. I want to be able to write both HTML and text to the clipboard in the same way. This may be a Windows mechanism that allows multiple types of text to exist in the clipboard.

HuakunShen commented 2 months ago

@Tester-957 I see what you mean. This needs to be added in clipboard-rs. @ChurchTao

Here is my experiment with cilpboard-rs, writing html doesn't update text.

let ctx = ClipboardContext::new().unwrap();

ctx.set_html("<h1>hello</h1>".to_string()).unwrap();
let txt = ctx.get_text().unwrap();
println!("txt: {:?}", txt);
let html = ctx.get_html().unwrap();
println!("html: {:?}", html);

Output:

txt: ""
html: "<h1>hello</h1>"
HuakunShen commented 2 months ago

A writeHtmlAndText() is added.

Tester-957 commented 2 months ago

A writeHtmlAndText() is added. 添加了 writeHtmlAndText()

Thank you

Tester-957 commented 2 months ago

V: 0.6.7 Tested on Windows 11, the problem still exists @HuakunShen image

text is the content I copied last time

HuakunShen commented 2 months ago

Oh looks like the new api only worked on Mac, but not windows.

HuakunShen commented 2 months ago

Text has to go before Html, otherwise it won't work on Windows.

image Fixed in https://github.com/CrossCopy/tauri-plugin-clipboard/releases/tag/v0.6.8

Tested on Mac, Win11, and Ubuntu 22.