Skip to content

Commit 0af2c13

Browse files
committed
Add support for Home and End key
1 parent 9280fae commit 0af2c13

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/cmd.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,17 @@ impl CommandLine {
602602
}
603603
}
604604

605+
pub fn cursor_back(&mut self) {
606+
if self.cursor > 1 {
607+
self.cursor = 1;
608+
self.autocomplete.invalidate();
609+
}
610+
}
611+
612+
pub fn cursor_front(&mut self) {
613+
self.cursor = self.input.len();
614+
}
615+
605616
pub fn putc(&mut self, c: char) {
606617
if self.input.len() + c.len_utf8() > self.input.capacity() {
607618
return;
@@ -1334,6 +1345,19 @@ mod test {
13341345

13351346
cli.delc();
13361347
assert_eq!(cli.input(), ":e");
1348+
1349+
cli.clear();
1350+
cli.puts(":echo");
1351+
1352+
assert_eq!(cli.peek(), None);
1353+
cli.cursor_back();
1354+
1355+
assert_eq!(cli.peek(), Some('e'));
1356+
assert_eq!(cli.peek_back(), Some(':'));
1357+
1358+
cli.cursor_front();
1359+
assert_eq!(cli.peek(), None);
1360+
assert_eq!(cli.peek_back(), Some('o'));
13371361
}
13381362

13391363
#[test]

src/session.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,12 @@ impl Session {
22862286
platform::Key::Escape => {
22872287
self.cmdline_hide();
22882288
}
2289+
platform::Key::Home => {
2290+
self.cmdline.cursor_back();
2291+
}
2292+
platform::Key::End => {
2293+
self.cmdline.cursor_front();
2294+
}
22892295
_ => {}
22902296
}
22912297
}

0 commit comments

Comments
 (0)