Skip to content

Commit 5b799dc

Browse files
authored
Fix bug in clipboard text (#137)
* Fix bug when copying clipboard text. * Add test for clipboard text manipulation.
1 parent cf82535 commit 5b799dc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/sdl3/clipboard.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl ClipboardUtil {
3636
let text = CString::new(text).unwrap();
3737
let result = sys::clipboard::SDL_SetClipboardText(text.as_ptr() as *const c_char);
3838

39-
if result {
39+
if !result {
4040
Err(get_error())
4141
} else {
4242
Ok(())

tests/clipboard.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
extern crate sdl3;
2+
3+
#[test]
4+
fn test_clipboard() {
5+
let sdl_context = sdl3::init().unwrap();
6+
let video_subsystem = sdl_context.video().unwrap();
7+
let clipboard = video_subsystem.clipboard();
8+
let text = "Hello World!";
9+
10+
// set some text
11+
assert!(clipboard.set_clipboard_text(text).is_ok());
12+
assert!(clipboard.has_clipboard_text());
13+
// get it back
14+
assert_eq!(clipboard.clipboard_text(), Ok(text.to_string()));
15+
}

0 commit comments

Comments
 (0)