From d01e06fbc0addd0510aaf5fa5fed5c804b37b2f7 Mon Sep 17 00:00:00 2001 From: korin Date: Sun, 21 May 2023 08:56:28 -0400 Subject: [PATCH] idk --- TODO.org | 1 + src/input.rs | 14 +++++++++++++- src/main.rs | 9 ++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/TODO.org b/TODO.org index 4b1a245..b93ccdf 100644 --- a/TODO.org +++ b/TODO.org @@ -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 diff --git a/src/input.rs b/src/input.rs index 4149b05..ce48777 100644 --- a/src/input.rs +++ b/src/input.rs @@ -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 { diff --git a/src/main.rs b/src/main.rs index 3aa6a69..8b5ad0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,7 +64,7 @@ pub fn main() -> Result<(), String> { draw!(); 'mainloop: loop { - // TODO: Make this completely user-configurable instead of hardcoded + // TODO: <> 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!(); + } + _ => (), };