Add clipboard support for Windows (#8978)

Release Notes:

- Added Read / Write clipboard support to Windows via copypasta

---------

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
EricApostal 2024-03-07 23:16:38 -05:00 committed by GitHub
parent 866d791760
commit aa7be4b5d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 7 deletions

2
.gitignore vendored
View file

@ -22,4 +22,4 @@ DerivedData/
**/*.db
.pytest_cache
.venv
.blob_store
.blob_store

View file

@ -103,6 +103,7 @@ blade-macros.workspace = true
blade-rwh.workspace = true
bytemuck = "1"
cosmic-text = "0.10.0"
copypasta = "0.10.1"
[target.'cfg(target_os = "linux")'.dependencies]
open = "5.0.1"
@ -116,7 +117,6 @@ xkbcommon = { version = "0.7", features = ["wayland", "x11"] }
as-raw-xcb-connection = "1"
calloop = "0.12.4"
calloop-wayland-source = "0.2.0"
copypasta = "0.10.1"
oo7 = "0.3.0"
[target.'cfg(windows)'.dependencies]
@ -128,4 +128,4 @@ path = "examples/hello_world.rs"
[[example]]
name = "image"
path = "examples/image/image.rs"
path = "examples/image/image.rs"

View file

@ -13,6 +13,7 @@ use std::{
use anyhow::{anyhow, Result};
use async_task::Runnable;
use copypasta::{ClipboardContext, ClipboardProvider};
use futures::channel::oneshot::Receiver;
use parking_lot::Mutex;
use time::UtcOffset;
@ -493,14 +494,18 @@ impl Platform for WindowsPlatform {
false
}
// todo(windows)
fn write_to_clipboard(&self, item: ClipboardItem) {
unimplemented!()
let mut ctx = ClipboardContext::new().unwrap();
ctx.set_contents(item.text().to_owned()).unwrap();
}
// todo(windows)
fn read_from_clipboard(&self) -> Option<ClipboardItem> {
unimplemented!()
let mut ctx = ClipboardContext::new().unwrap();
let content = ctx.get_contents().unwrap();
Some(ClipboardItem {
text: content,
metadata: None,
})
}
// todo(windows)