A simple CPU rendered GUI IDE experience.
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
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
}