Handle paste events in editor
Only on non-windows platforms though, since crossterm doesn't support pasting on windows.
This commit is contained in:
parent
5ad9f0f3e7
commit
f7e7003788
3 changed files with 15 additions and 2 deletions
|
|
@ -17,6 +17,7 @@ Procedure when bumping the version number:
|
|||
### Added
|
||||
- New messages are now marked as unseen
|
||||
- Sub-trees can now be folded
|
||||
- Support for pasting text into editors
|
||||
- More readline-esque editor key bindings
|
||||
- Key bindings to move to prev/next sibling
|
||||
- Key binding to center cursor on screen
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ pub fn handle_editor_event(
|
|||
|
||||
// Editing
|
||||
key!(Char ch) if char_filter(*ch) => editor.insert_char(terminal.frame(), *ch),
|
||||
key!(Paste str) if str.chars().all(char_filter) => editor.insert_str(terminal.frame(), str),
|
||||
key!(Ctrl + 'h') | key!(Backspace) => editor.backspace(terminal.frame()),
|
||||
key!(Ctrl + 'd') | key!(Delete) => editor.delete(),
|
||||
key!(Ctrl + 'l') => editor.clear(),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue