From 0db978d8d16a2a07f74bf981cff00d7da96e0a93 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Fri, 26 Jun 2026 13:22:02 -0400 Subject: [PATCH] feat(comment): Alt+Enter accepts and Alt+Esc discards in the vim comment box MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the vim comment editor, Alt+Enter (Option+Enter) saves the comment and Alt+Esc cancels it directly, from any sub-mode — no double-press. Alt is the one modified Enter/Esc that reaches the app across terminals, including browser/web terminals like zellij web (where Shift/Cmd+Enter get stripped or grabbed by the browser). Plain Enter still inserts a newline in vim Insert mode, so Alt+Enter is free to mean "accept". The default (non-vim) box is unchanged (Alt+Enter stays a newline there). Complements the existing :w/:q, double Enter/Esc, and Ctrl-S. --- docs/KEYBINDINGS.md | 5 ++++- src/main.rs | 19 +++++++++++++++++++ src/ui/comment_panel.rs | 2 +- src/ui/help_popup.rs | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/KEYBINDINGS.md b/docs/KEYBINDINGS.md index 26ac830e..a33329d6 100644 --- a/docs/KEYBINDINGS.md +++ b/docs/KEYBINDINGS.md @@ -96,7 +96,10 @@ With `comment_vim = true` the box uses [`edtui`](https://github.com/preiter93/ed modal editing (Normal/Insert/Visual: `hjkl`, `w`/`b`/`e`, `dd`/`D`/`ciw`/`x`, `u`/`Ctrl-r`, visual `v`+`y`/`d`/`p`). From Normal mode `:w` (or `Enter` twice) saves and `:q` (or `Esc`/`q` twice) cancels — the first press arms the action -and the header shows a confirm hint. `Tab` cycles the comment type in Normal +and the header shows a confirm hint. `Alt-Enter` (Option+Enter) accepts and +`Alt-Esc` discards directly (no double-press) — Alt is the one modified +`Enter`/`Esc` that reaches the app across terminals, including browser/web +terminals like zellij web. `Tab` cycles the comment type in Normal mode and inserts `comment_tab_width` spaces (default 4) in Insert mode; `Ctrl-s` also saves. Operator+motion combos like `dw`/`cw` aren't supported (edtui limitation). diff --git a/src/main.rs b/src/main.rs index 6ae8e4bb..803a9a67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -750,6 +750,25 @@ fn handle_comment_vim_key(app: &mut App, key: crossterm::event::KeyEvent) -> boo return true; } + // Alt+Enter (Option+Enter) accepts (save) and Alt+Esc discards (cancel) + // directly, in any mode — no double-press. Alt is the one modified Enter/Esc + // that reaches the app across terminals, including browser/web terminals + // like zellij web (where Shift/Cmd+Enter get stripped or grabbed). Plain + // Enter still inserts a newline in Insert mode, so Alt+Enter is free here. + if key.modifiers.contains(KeyModifiers::ALT) { + match key.code { + KeyCode::Enter => { + app.save_comment(); + return true; + } + KeyCode::Esc => { + app.exit_comment_mode(); + return true; + } + _ => {} + } + } + let normal = app.comment_vim_in_normal_mode(); // In Normal mode a first plain Enter/Esc arms a confirm (header shows the diff --git a/src/ui/comment_panel.rs b/src/ui/comment_panel.rs index 0ec24a22..a9ffa2c6 100644 --- a/src/ui/comment_panel.rs +++ b/src/ui/comment_panel.rs @@ -152,7 +152,7 @@ pub fn format_comment_input_lines( // Top border with type label and hints. In vim mode the hints describe the // modal bindings and a `[MODE]` tag is shown after the type label. let hint = match vim_mode { - Some(_) => "(Tab/S-Tab:type i:insert Esc:normal :w save :q cancel)".to_string(), + Some(_) => "(i:insert Alt-Enter:save Esc:normal :w save :q discard)".to_string(), None => format!("(Tab/S-Tab:type Enter:save {newline_hint}:newline Esc:cancel)"), }; let mut header_spans = vec![ diff --git a/src/ui/help_popup.rs b/src/ui/help_popup.rs index 377f16a1..cbfa7927 100644 --- a/src/ui/help_popup.rs +++ b/src/ui/help_popup.rs @@ -525,7 +525,7 @@ pub fn render_help(frame: &mut Frame, app: &mut App) { Style::default().add_modifier(Modifier::BOLD), ), Span::raw(if app.comment_vim_enabled { - "Vim modal editing ON (Esc:normal i/a:insert hjkl dd/ciw/x u; :w save :q cancel)" + "Vim ON (i/a:insert Esc:normal hjkl dd/ciw/x u; S-Enter:save S-Esc:discard :w/:q)" } else { "Set comment_vim=true (or :vim) for vim modal editing" }),