|
|
|
|
@ -53,22 +53,47 @@ 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 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); |
|
|
|
|
} |
|
|
|
|
// i shouldn't have to do this
|
|
|
|
|
*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 { |
|
|
|
|
|