ChurchTao / clipboard-rs

Cross-platform clipboard API (text | image | rich text | html | files | monitoring changes) | 跨平台剪贴板 API(文本|图片|富文本|html|文件|监听变化) Windows,MacOS,Linux
https://docs.rs/clipboard-rs
MIT License
29 stars 5 forks source link

如何触发富文本的复制 #29

Open ayangweb opened 2 weeks ago

ayangweb commented 2 weeks ago

The feature request | 需求描述

大佬,怎么正确的触发富文本的复制啊,我这里一直都是 has_html 为 true,has_rich_text 为 false!

#[command]
async fn has_html(manager: State<'_, ClipboardManager>) -> Result<bool> {
    Ok(manager.has(ContentFormat::Html))
}

#[command]
async fn has_rich_text(manager: State<'_, ClipboardManager>) -> Result<bool> {
    Ok(manager.has(ContentFormat::Rtf))
}

Proposed solution | 解决方案

求解惑,谢谢大佬😁

ChurchTao commented 2 weeks ago

你去 word 里面复制东西,就是富文本

ayangweb commented 2 weeks ago

你去 word 里面复制东西,就是富文本

您说的是 Microsoft Word 吗?我去 windows 虚拟机下载一个试试!

ayangweb commented 2 weeks ago

你去 word 里面复制东西,就是富文本

大佬,确实是识别到了,不过获取到的富文本内容是空字符串!

EcoCopy_80

image

我复制的做笔记这三字,html 正常识别到了内容,富文本为空!

#[command]
async fn read_rich_text(manager: State<'_, ClipboardManager>) -> Result<String> {
    Ok(manager.context.get_rich_text().unwrap())
}
export const readRichText = async (): Promise<ClipboardPayload> => {
    const richText = await invoke<string>(CLIPBOARD_PLUGIN.READ_RICH_TEXT);

    return {
        value: richText,
        search: richText,
        size: richText.length,
    };
};
ayangweb commented 2 weeks ago

你去 word 里面复制东西,就是富文本

大佬,确实是识别到了,不过获取到的富文本内容是空字符串!

EcoCopy_80

image

我复制的做笔记这三字,html 正常识别到了内容,富文本为空!

#[command]
async fn read_rich_text(manager: State<'_, ClipboardManager>) -> Result<String> {
    Ok(manager.context.get_rich_text().unwrap())
}
export const readRichText = async (): Promise<ClipboardPayload> => {
  const richText = await invoke<string>(CLIPBOARD_PLUGIN.READ_RICH_TEXT);

  return {
      value: richText,
      search: richText,
      size: richText.length,
  };
};

@ChurchTao 大佬,空了帮忙看看这个问题,谢谢😁

ChurchTao commented 2 weeks ago

@ayangweb 在windows上跑的时候,当剪贴板上有富文本时,打印一下 context.available_formats() 的结果,贴上来我看下

ayangweb commented 2 weeks ago

@ayangweb 在windows上跑的时候,当剪贴板上有富文本时,打印一下 context.available_formats() 的结果,贴上来我看下

我现在这个是 macos 上下了 word,可以打印给你看不,必须 windows 吗,虚拟机操作起来不是很流畅🤣

ChurchTao commented 2 weeks ago

都行,但是 macos 上应该是能复制到值的吧

ayangweb commented 2 weeks ago

都行,但是 macos 上应该是能复制到值的吧

我上面给您发的截图就是 MacOS 的操作,获取到了空的富文本内容

ChurchTao commented 2 weeks ago

嗯嗯 那一样 打印一下

ayangweb commented 2 weeks ago

context.available_formats()

image
#[command]
async fn has_rich_text(manager: State<'_, ClipboardManager>) -> Result<bool> {
    let has_rtf = manager.has(ContentFormat::Rtf);

    println!("\n\nhas_rtf: {has_rtf}\n\n");

    if has_rtf {
        let types = manager.context.available_formats().unwrap();

        println!("{types:?}\n\n");

        let rtf = manager.context.get_rich_text().unwrap();

        println!("rtf: {rtf:?}\n\n");
    }

    Ok(has_rtf)
}
ChurchTao commented 2 weeks ago

确实无法读取到,我回头查下什么毛病,估计是word的格式不是很通用。

ayangweb commented 2 weeks ago

确实无法读取到,我回头查下什么毛病,估计是word的格式不是很通用。

👌🏻