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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#[cfg(not(feature = "std"))]
use alloc::string::String;
#[cfg(feature = "swash")]
use crate::Color;
use crate::{AttrsList, BorrowedWithFontSystem, Buffer, Cursor, FontSystem};
pub use self::editor::*;
mod editor;
#[cfg(feature = "syntect")]
pub use self::syntect::*;
#[cfg(feature = "syntect")]
mod syntect;
#[cfg(feature = "vi")]
pub use self::vi::*;
#[cfg(feature = "vi")]
mod vi;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Action {
Previous,
Next,
Left,
Right,
Up,
Down,
Home,
End,
ParagraphStart,
ParagraphEnd,
PageUp,
PageDown,
Vertical(i32),
Escape,
Insert(char),
Enter,
Backspace,
Delete,
Click { x: i32, y: i32 },
Drag { x: i32, y: i32 },
Scroll { lines: i32 },
PreviousWord,
NextWord,
LeftWord,
RightWord,
BufferStart,
BufferEnd,
}
pub trait Edit {
fn borrow_with<'a>(
&'a mut self,
font_system: &'a mut FontSystem,
) -> BorrowedWithFontSystem<'a, Self>
where
Self: Sized,
{
BorrowedWithFontSystem {
inner: self,
font_system,
}
}
fn buffer(&self) -> &Buffer;
fn buffer_mut(&mut self) -> &mut Buffer;
fn cursor(&self) -> Cursor;
fn select_opt(&self) -> Option<Cursor>;
fn set_select_opt(&mut self, select_opt: Option<Cursor>);
fn shape_as_needed(&mut self, font_system: &mut FontSystem);
fn copy_selection(&mut self) -> Option<String>;
fn delete_selection(&mut self) -> bool;
fn insert_string(&mut self, data: &str, attrs_list: Option<AttrsList>);
fn action(&mut self, font_system: &mut FontSystem, action: Action);
#[cfg(feature = "swash")]
fn draw<F>(
&self,
font_system: &mut FontSystem,
cache: &mut crate::SwashCache,
color: Color,
f: F,
) where
F: FnMut(i32, i32, u32, u32, Color);
}
impl<'a, T: Edit> BorrowedWithFontSystem<'a, T> {
pub fn buffer_mut(&mut self) -> BorrowedWithFontSystem<Buffer> {
BorrowedWithFontSystem {
inner: self.inner.buffer_mut(),
font_system: self.font_system,
}
}
pub fn shape_as_needed(&mut self) {
self.inner.shape_as_needed(self.font_system);
}
pub fn action(&mut self, action: Action) {
self.inner.action(self.font_system, action);
}
#[cfg(feature = "swash")]
pub fn draw<F>(&mut self, cache: &mut crate::SwashCache, color: Color, f: F)
where
F: FnMut(i32, i32, u32, u32, Color),
{
self.inner.draw(self.font_system, cache, color, f);
}
}