From f14e9b8998163411c88a61ab0ce92c87f3f39d66 Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 2 Aug 2022 22:35:15 +0200 Subject: [PATCH] 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. --- src/ui/chat/tree.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ui/chat/tree.rs b/src/ui/chat/tree.rs index e9177a9..f20771d 100644 --- a/src/ui/chat/tree.rs +++ b/src/ui/chat/tree.rs @@ -66,14 +66,14 @@ impl> InnerTreeViewState { coming_from: Option, parent: Option, ) -> Reaction { - 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> InnerTreeViewState { 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);