Fix pasting multi-line strings

This commit is contained in:
Joscha 2022-08-20 16:31:09 +02:00
parent fe381e1146
commit ade06efa01
2 changed files with 8 additions and 1 deletions

View file

@ -17,6 +17,7 @@ Procedure when bumping the version number:
### Fixed ### Fixed
- Crash when connecting to nonexistent rooms - Crash when connecting to nonexistent rooms
- Crash when connecting to rooms that require authentication - Crash when connecting to rooms that require authentication
- Pasting multi-line strings into the editor
## v0.2.1 - 2022-08-11 ## v0.2.1 - 2022-08-11

View file

@ -78,7 +78,13 @@ pub fn handle_editor_event(
// Editing // Editing
key!(Char ch) if char_filter(*ch) => editor.insert_char(terminal.frame(), *ch), 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!(Paste str) if str.chars().all(char_filter) => {
// It seems that when pasting, '\n' are converted into '\r' for some
// reason. I don't really know why, or at what point this happens.
// Vim converts any '\r' pasted via the terminal into '\n', so I
// decided to mirror that behaviour.
editor.insert_str(terminal.frame(), &str.replace('\r', "\n"))
}
key!(Ctrl + 'h') | key!(Backspace) => editor.backspace(terminal.frame()), key!(Ctrl + 'h') | key!(Backspace) => editor.backspace(terminal.frame()),
key!(Ctrl + 'd') | key!(Delete) => editor.delete(), key!(Ctrl + 'd') | key!(Delete) => editor.delete(),
key!(Ctrl + 'l') => editor.clear(), key!(Ctrl + 'l') => editor.clear(),