Handle paste events in editor

Only on non-windows platforms though, since crossterm doesn't support
pasting on windows.
This commit is contained in:
Joscha 2022-08-10 23:59:40 +02:00
parent 5ad9f0f3e7
commit f7e7003788
3 changed files with 15 additions and 2 deletions

View file

@ -182,8 +182,15 @@ impl InnerEditorState {
/// accordingly.
fn insert_char(&mut self, frame: &mut Frame, ch: char) {
self.text.insert(self.idx, ch);
self.idx += 1;
self.move_cursor_to_grapheme_boundary();
self.idx += ch.len_utf8();
self.record_cursor_col(frame);
}
/// Insert a string at the current cursor position and move the cursor
/// accordingly.
fn insert_str(&mut self, frame: &mut Frame, str: &str) {
self.text.insert_str(self.idx, str);
self.idx += str.len();
self.record_cursor_col(frame);
}
@ -347,6 +354,10 @@ impl EditorState {
self.0.lock().insert_char(frame, ch);
}
pub fn insert_str(&self, frame: &mut Frame, str: &str) {
self.0.lock().insert_str(frame, str);
}
/// Delete the grapheme before the cursor position.
pub fn backspace(&self, frame: &mut Frame) {
self.0.lock().backspace(frame);