diff options
Diffstat (limited to 'src/command.rs')
-rw-r--r-- | src/command.rs | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/command.rs b/src/command.rs index 064d767..d80f1f2 100644 --- a/src/command.rs +++ b/src/command.rs | |||
@@ -22,11 +22,11 @@ impl CommandBox { | |||
22 | } | 22 | } |
23 | } | 23 | } |
24 | 24 | ||
25 | fn cursor_end(&mut self) { | 25 | pub fn cursor_end(&mut self) { |
26 | self.cursor = self.text.len(); | 26 | self.cursor = self.text.len(); |
27 | } | 27 | } |
28 | 28 | ||
29 | fn cursor_start(&mut self) { | 29 | pub fn cursor_start(&mut self) { |
30 | self.cursor = 0; | 30 | self.cursor = 0; |
31 | } | 31 | } |
32 | 32 | ||
@@ -47,8 +47,17 @@ impl CommandBox { | |||
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | pub fn delete_to_end(&mut self) { | ||
51 | self.text.truncate(self.cursor); | ||
52 | } | ||
53 | |||
54 | pub fn delete_to_start(&mut self) { | ||
55 | self.text = self.text.chars().skip(self.cursor).collect(); | ||
56 | self.cursor = 0; | ||
57 | } | ||
58 | |||
50 | pub fn push_str(&mut self, v: &str) { | 59 | pub fn push_str(&mut self, v: &str) { |
51 | self.text.push_str(v); | 60 | self.text.insert_str(self.cursor, v); |
52 | self.cursor += v.len(); | 61 | self.cursor += v.len(); |
53 | } | 62 | } |
54 | 63 | ||
@@ -143,6 +152,36 @@ mod command_tests { | |||
143 | } | 152 | } |
144 | 153 | ||
145 | #[test] | 154 | #[test] |
155 | fn entering_text_between() { | ||
156 | let mut cmd = setup_with("save as file.png"); | ||
157 | cmd.backward(); | ||
158 | cmd.backward(); | ||
159 | cmd.backward(); | ||
160 | cmd.push_str("ext"); | ||
161 | assert_eq!(&cmd.text, "save as file.extpng"); | ||
162 | } | ||
163 | |||
164 | #[test] | ||
165 | fn delete_to_end() { | ||
166 | let mut cmd = setup_with("save as file.png"); | ||
167 | cmd.backward(); | ||
168 | cmd.backward(); | ||
169 | cmd.backward(); | ||
170 | cmd.delete_to_end(); | ||
171 | assert_eq!(&cmd.text, "save as file."); | ||
172 | } | ||
173 | |||
174 | #[test] | ||
175 | fn delete_to_start() { | ||
176 | let mut cmd = setup_with("save as file.png"); | ||
177 | cmd.backward(); | ||
178 | cmd.backward(); | ||
179 | cmd.backward(); | ||
180 | cmd.delete_to_start(); | ||
181 | assert_eq!(&cmd.text, "png"); | ||
182 | } | ||
183 | |||
184 | #[test] | ||
146 | fn backspacing_from_end() { | 185 | fn backspacing_from_end() { |
147 | let mut cmd = setup_with("save"); | 186 | let mut cmd = setup_with("save"); |
148 | cmd.backspace(); | 187 | cmd.backspace(); |