A simple CPU rendered GUI IDE experience.
Diffstat (limited to 'src/edi/input_handlers.rs')
-rw-r--r--src/edi/input_handlers.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/edi/input_handlers.rs b/src/edi/input_handlers.rs
new file mode 100644
index 0000000..ac4ca4c
--- /dev/null
+++ b/src/edi/input_handlers.rs
@@ -0,0 +1,59 @@
+use std::path::Path;
+
+use winit::keyboard::Key;
+mod click;
+mod cursor;
+mod keyboard;
+use crate::edi::*;
+pub fn handle2<'a>(
+ key: &'a Key,
+ text: &mut TextArea,
+ l: Option<(&Client, &Path)>,
+) -> Option<&'a str> {
+ use Key::*;
+
+ match key {
+ Character(" ") => text.insert(" "),
+ Named(Backspace) if ctrl() => text.backspace_word(),
+ Named(Backspace) => text.backspace(),
+ Named(Home) if ctrl() => {
+ text.cursor.just(0, &text.rope);
+ text.vo = 0;
+ }
+ Named(End) if ctrl() => {
+ text.cursor.just(text.rope.len_chars(), &text.rope);
+ text.vo = text.l().saturating_sub(text.r);
+ }
+ Character("e") if alt() => text.end(),
+ Character("q") if alt() => text.home(),
+ Named(Home) => text.home(),
+ Named(End) => text.end(),
+ Named(Tab) => text.tab(),
+ Named(Delete) => {
+ text.right();
+ text.backspace()
+ }
+ Character("a") if alt() && ctrl() => text.word_left(),
+ Character("d") if alt() && ctrl() => text.word_right(),
+ Character("a") if alt() => text.left(),
+ Character("w") if alt() => text.up(),
+ Character("s") if alt() => text.down(),
+ Character("d") if alt() => text.right(),
+ Named(ArrowLeft) if ctrl() => text.word_left(),
+ Named(ArrowRight) if ctrl() => text.word_right(),
+ Named(ArrowLeft) => text.left(),
+ Named(ArrowRight) => text.right(),
+ Named(ArrowUp) => text.up(),
+ Named(ArrowDown) => text.down(),
+ Named(PageDown) => text.page_down(),
+ Named(PageUp) => text.page_up(),
+ Named(Enter) if let Some((l, p)) = l => l.enter(p, text).unwrap(),
+ Named(Enter) => text.enter(),
+ Character(x) => {
+ text.insert(&x);
+ return Some(x);
+ }
+ _ => {}
+ };
+ None
+}