|
|
|
|
@ -16,6 +16,8 @@ mod keybinds { |
|
|
|
|
Redo, |
|
|
|
|
NewLines, |
|
|
|
|
DeleteLines, |
|
|
|
|
TabForward, |
|
|
|
|
TabBackward, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub(super) enum Movement { |
|
|
|
|
@ -53,22 +55,57 @@ pub struct ModifierKeys { |
|
|
|
|
|
|
|
|
|
impl ModifierKeys { |
|
|
|
|
pub fn new() -> ModifierKeys { |
|
|
|
|
ModifierKeys { alt: false, ctrl: false, shift: false } |
|
|
|
|
ModifierKeys { |
|
|
|
|
alt: false, |
|
|
|
|
ctrl: false, |
|
|
|
|
shift: false, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
// TODO: Clean up this messy expression
|
|
|
|
|
let buffer_chars: Vec<char> = buffer.chars().collect(); |
|
|
|
|
while !(buffer_chars[*cursor_position - 1] == ' ' |
|
|
|
|
|| buffer_chars[*cursor_position - 1] == '\n') |
|
|
|
|
&& *cursor_position > 1 |
|
|
|
|
{ |
|
|
|
|
*cursor_position -= 1; |
|
|
|
|
buffer.remove(*cursor_position); |
|
|
|
|
} |
|
|
|
|
*cursor_position -= 1; |
|
|
|
|
buffer.remove(*cursor_position); |
|
|
|
|
} else { |
|
|
|
|
// Character backspace
|
|
|
|
|
buffer.remove(*cursor_position - 1); |
|
|
|
|
*cursor_position -= 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn delete(buffer: &mut String, cursor_position: usize, modifiers: &ModifierKeys) { |
|
|
|
|
if modifiers.ctrl { |
|
|
|
|
loop { |
|
|
|
|
let buffer_chars: Vec<char> = buffer.chars() |
|
|
|
|
.collect(); |
|
|
|
|
let buffer_chars: Vec<char> = buffer.chars().collect(); |
|
|
|
|
if cursor_position == buffer.len() { |
|
|
|
|
break
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if !buffer_chars[cursor_position].is_whitespace() { |
|
|
|
|
buffer.remove(cursor_position); |
|
|
|
|
} else { |
|
|
|
|
break
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
|