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 * [X] Start to end of document
* [ ] Confine to line unless CTRL is pressed * [ ] Confine to line unless CTRL is pressed
- [ ] Mouse input - [ ] Mouse input
- [ ] [[./src/main.rs::ConfigurableInput][Make keyboard input configurable instead of hardcoded]]
* Editing [2/7] * Editing [2/7]
- [X] Type text - [X] Type text

@ -16,6 +16,8 @@ mod keybinds {
Redo, Redo,
NewLines, NewLines,
DeleteLines, DeleteLines,
TabForward,
TabBackward,
} }
pub(super) enum Movement { 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) { pub fn backspace(buffer: &mut String, cursor_position: &mut usize, modifiers: &ModifierKeys) {
if modifiers.ctrl { if modifiers.ctrl {
// Word backspace // Word backspace
@ -73,7 +86,6 @@ pub fn backspace(buffer: &mut String, cursor_position: &mut usize, modifiers: &M
*cursor_position -= 1; *cursor_position -= 1;
buffer.remove(*cursor_position); buffer.remove(*cursor_position);
} }
// i shouldn't have to do this
*cursor_position -= 1; *cursor_position -= 1;
buffer.remove(*cursor_position); buffer.remove(*cursor_position);
} else { } else {

@ -64,7 +64,7 @@ pub fn main() -> Result<(), String> {
draw!(); draw!();
'mainloop: loop { 'mainloop: loop {
// TODO: Make this completely user-configurable instead of hardcoded // TODO: <<ConfigurableInput>>
for event in sdl_context.event_pump()?.poll_iter() { for event in sdl_context.event_pump()?.poll_iter() {
match event { match event {
Event::Window { win_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