type-render
korin 3 years ago
parent a27ec9d267
commit d01e06fbc0
  1. 1
      TODO.org
  2. 14
      src/input.rs
  3. 9
      src/main.rs

@ -10,6 +10,7 @@
* [X] Start to end of document
* [ ] Confine to line unless CTRL is pressed
- [ ] Mouse input
- [ ] [[./src/main.rs::ConfigurableInput][Make keyboard input configurable instead of hardcoded]]
* Editing [2/7]
- [X] Type text

@ -16,6 +16,8 @@ mod keybinds {
Redo,
NewLines,
DeleteLines,
TabForward,
TabBackward,
}
pub(super) enum Movement {
@ -61,6 +63,17 @@ impl ModifierKeys {
}
}
pub fn tab(buffer: &mut String, cursor_position: &mut usize, modifiers: &ModifierKeys) {
if modifiers.shift {
println!("unimplemented back-tab");
} else {
// for _ in 0..4 {
buffer.insert_str(*cursor_position, " ");
*cursor_position += 4;
// }
}
}
pub fn backspace(buffer: &mut String, cursor_position: &mut usize, modifiers: &ModifierKeys) {
if modifiers.ctrl {
// Word backspace
@ -73,7 +86,6 @@ pub fn backspace(buffer: &mut String, cursor_position: &mut usize, modifiers: &M
*cursor_position -= 1;
buffer.remove(*cursor_position);
}
// i shouldn't have to do this
*cursor_position -= 1;
buffer.remove(*cursor_position);
} else {

@ -64,7 +64,7 @@ pub fn main() -> Result<(), String> {
draw!();
'mainloop: loop {
// TODO: Make this completely user-configurable instead of hardcoded
// TODO: <<ConfigurableInput>>
for event in sdl_context.event_pump()?.poll_iter() {
match event {
Event::Window { win_event, .. } => {
@ -113,6 +113,13 @@ pub fn main() -> Result<(), String> {
}
}
Some(Keycode::Tab) => {
undo_timer = 0;
input::tab(&mut buffer, &mut cursor_position, &modifier_keys);
draw!();
}
_ => (),
};

Loading…
Cancel
Save