Skip to content
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

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

Closed
Tester-957 opened this issue Apr 23, 2024 · 10 comments

Comments

@Tester-957
Copy link

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
Copy link
Collaborator

HuakunShen commented Apr 24, 2024

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.

@HuakunShen
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Author

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
Copy link
Collaborator

@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
Copy link
Collaborator

A writeHtmlAndText() is added.

@Tester-957
Copy link
Author

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

Thank you

@Tester-957
Copy link
Author

Tester-957 commented Apr 25, 2024

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

text is the content I copied last time

@HuakunShen
Copy link
Collaborator

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

HuakunShen added a commit that referenced this issue Apr 25, 2024
@HuakunShen
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants