1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//! The clipboard an application's widgets copy text through.
//!
//! An [`App`](crate::App) holds one clipboard, installed with
//! [`App::set_clipboard`](crate::App::set_clipboard). The windowing layer
//! installs one that reaches the system clipboard; a test installs a
//! [`MemoryClipboard`], which keeps its text in memory and shares it through
//! [`MemoryClipboard::clone`]. Widget code reaches whichever one is installed
//! with [`with`], which finds the clipboard of the app the running code
//! belongs to, the same way timers find their clock.
//!
//! ```
//! use smudge_core::clipboard::{Clipboard, MemoryClipboard};
//!
//! let mut clipboard = MemoryClipboard::default();
//! clipboard.set(String::from("copied"));
//! assert_eq!(clipboard.get().as_deref(), Some("copied"));
//! ```
use RefCell;
use ;
use crateruntime;
/// The clipboard text is copied and pasted through.
///
/// A clipboard holds at most one piece of text. Putting text on it replaces
/// what it held; reading it leaves the text there.
/// A clipboard that keeps its text in memory.
///
/// A test installs one through
/// [`App::set_clipboard`](crate::App::set_clipboard) and keeps a clone, which
/// shares the same text, so the test can seed the clipboard before a paste or
/// read it back after a copy. This is also the clipboard of a platform with
/// no system clipboard to reach.
///
/// # Examples
///
/// ```
/// use smudge_core::clipboard::{Clipboard, MemoryClipboard};
///
/// let mut clipboard = MemoryClipboard::default();
/// let mut clone = clipboard.clone();
///
/// clipboard.set(String::from("text"));
/// assert_eq!(clone.get().as_deref(), Some("text"));
/// ```
/// Runs `f` with the clipboard of the app that owns the code running now.
///
/// Handlers run inside the owner of their node, so an input's copy and paste
/// keys reach the app's clipboard this way. Returns `None` when the running
/// code belongs to no app, when the app has no clipboard installed, or when
/// an outer `with` call holds the clipboard already. The caller should then
/// do nothing.
/// The shared slot one app's clipboard lives in, held strongly by the app and
/// weakly by every owner of its tree.
pub type Slot = ;
/// A weak view of a clipboard slot, as an owner holds it.
pub type WeakSlot = ;
/// Returns the clipboard of the app `owner` belongs to, walking up the owner
/// chain to the root that holds it.
/// Stores `clipboard` as the clipboard of the app whose root owner is
/// `root`, replacing any clipboard it had.
///
/// The app keeps the strong reference, so the clipboard lives as long as the
/// app does; owners hold only weak references.
pub