Enter newlines via modifier+enter

As long as the modifier doesn't get swallowed by the terminal, the
editor will insert a newline at the current cursor location. My own
terminal emulator swallows ctrl and shift but not alt, so alt+enter
works for me.
This commit is contained in:
Joscha 2022-08-02 22:35:15 +02:00
parent 76352f9b6b
commit f14e9b8998

View file

@ -66,14 +66,14 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
coming_from: Option<M::Id>,
parent: Option<M::Id>,
) -> Reaction<M> {
let harmless_char = event.modifiers.difference(KeyModifiers::SHIFT).is_empty();
let harmless_char = (event.modifiers - KeyModifiers::SHIFT).is_empty();
match event.code {
KeyCode::Esc => {
self.cursor = coming_from.map(Cursor::Msg).unwrap_or(Cursor::Bottom);
Reaction::Handled
}
KeyCode::Enter => {
KeyCode::Enter if event.modifiers.is_empty() => {
let content = self.editor.text();
if content.trim().is_empty() {
Reaction::Handled
@ -85,6 +85,13 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
Reaction::Composed { parent, content }
}
}
KeyCode::Enter => {
// Enter with *any* modifier pressed - if ctrl and shift don't
// work, maybe alt does
self.editor.insert_char('\n');
self.correction = Some(Correction::MakeCursorVisible);
Reaction::Handled
}
KeyCode::Backspace => {
self.editor.backspace();
self.correction = Some(Correction::MakeCursorVisible);