diff --git a/yazi-plugin/src/utils/text.rs b/yazi-plugin/src/utils/text.rs index 92044180..0c1c4cdf 100644 --- a/yazi-plugin/src/utils/text.rs +++ b/yazi-plugin/src/utils/text.rs @@ -4,6 +4,7 @@ use mlua::{Lua, Table}; use unicode_width::UnicodeWidthChar; use super::Utils; +use crate::CLIPBOARD; impl Utils { pub(super) fn text(lua: &Lua, ya: &Table) -> mlua::Result<()> { @@ -31,6 +32,21 @@ impl Utils { })?, )?; + ya.raw_set( + "clipboard", + lua.create_async_function(|lua, text: mlua::String| async move { + let text = text.to_string_lossy().into_owned(); + + if text.is_empty() { + let clipboard_data = CLIPBOARD.get().await; + Some(lua.create_string(clipboard_data.as_encoded_bytes())).transpose() + } else { + CLIPBOARD.set(text).await; + Ok(None) + } + })?, + )?; + Ok(()) }