From d4977826f20d1695a9bcf7376e0361be8340f741 Mon Sep 17 00:00:00 2001 From: ekang7 Date: Thu, 30 Oct 2025 15:52:39 -0700 Subject: [PATCH 1/5] got rid of unnecessary triple backtick code block detector --- crates/chat-cli/src/cli/chat/prompt.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/crates/chat-cli/src/cli/chat/prompt.rs b/crates/chat-cli/src/cli/chat/prompt.rs index 76caca3f5a..8af90f6644 100644 --- a/crates/chat-cli/src/cli/chat/prompt.rs +++ b/crates/chat-cli/src/cli/chat/prompt.rs @@ -402,17 +402,6 @@ impl Validator for MultiLineValidator { fn validate(&self, os: &mut ValidationContext<'_>) -> rustyline::Result { let input = os.input(); - // Check for code block markers - if input.contains("```") { - // Count the number of ``` occurrences - let triple_backtick_count = input.matches("```").count(); - - // If we have an odd number of ```, we're in an incomplete code block - if triple_backtick_count % 2 == 1 { - return Ok(ValidationResult::Incomplete); - } - } - // Check for backslash continuation if input.ends_with('\\') { return Ok(ValidationResult::Incomplete); From a28e00630e103bdd4c47f322014e9c1458e9fc2c Mon Sep 17 00:00:00 2001 From: ekang7 Date: Wed, 5 Nov 2025 15:08:54 -0800 Subject: [PATCH 2/5] added back the triple backtick validation --- crates/chat-cli/src/cli/chat/prompt.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/chat-cli/src/cli/chat/prompt.rs b/crates/chat-cli/src/cli/chat/prompt.rs index 8af90f6644..bab2195c62 100644 --- a/crates/chat-cli/src/cli/chat/prompt.rs +++ b/crates/chat-cli/src/cli/chat/prompt.rs @@ -402,6 +402,17 @@ impl Validator for MultiLineValidator { fn validate(&self, os: &mut ValidationContext<'_>) -> rustyline::Result { let input = os.input(); + // Check for code block markers + if input.contains("```") { + // Count the number of ``` occurrences + let triple_backtick_count = input.matches("```").count(); + + // If we have an odd number of ```, we're in an incomplete code block + if triple_backtick_count % 2 == 1 { + return Ok(ValidationResult::Incomplete); + } + } + // Check for backslash continuation if input.ends_with('\\') { return Ok(ValidationResult::Incomplete); From 7860f676bec3ba2d2a341a5b8cdf0d965f6f1eb7 Mon Sep 17 00:00:00 2001 From: ekang7 Date: Wed, 5 Nov 2025 15:17:06 -0800 Subject: [PATCH 3/5] multiline hint added --- crates/chat-cli/src/cli/chat/prompt.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/chat-cli/src/cli/chat/prompt.rs b/crates/chat-cli/src/cli/chat/prompt.rs index bab2195c62..e319fb3d45 100644 --- a/crates/chat-cli/src/cli/chat/prompt.rs +++ b/crates/chat-cli/src/cli/chat/prompt.rs @@ -353,6 +353,15 @@ impl ChatHinter { return None; } + // Check for unclosed triple backticks + if line.contains("```") { + let triple_backtick_count = line.matches("```").count(); + if triple_backtick_count % 2 == 1 { + // We have an odd number of ```, meaning we're in multiline mode + return Some("in multiline mode, waiting for closing backticks ```".to_string()); + } + } + // If line starts with a slash, try to find a command hint if line.starts_with('/') { return self From 353a7156506429bd379d24cecf4f0955e154b4df Mon Sep 17 00:00:00 2001 From: ekang7 Date: Wed, 5 Nov 2025 15:21:44 -0800 Subject: [PATCH 4/5] formatted after multiline hint added --- crates/chat-cli/src/cli/chat/prompt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/chat-cli/src/cli/chat/prompt.rs b/crates/chat-cli/src/cli/chat/prompt.rs index e319fb3d45..d1e994c38f 100644 --- a/crates/chat-cli/src/cli/chat/prompt.rs +++ b/crates/chat-cli/src/cli/chat/prompt.rs @@ -421,7 +421,7 @@ impl Validator for MultiLineValidator { return Ok(ValidationResult::Incomplete); } } - + // Check for backslash continuation if input.ends_with('\\') { return Ok(ValidationResult::Incomplete); From 54dc8376a0da2a795a5ad2227c3bcfbdc5436eae Mon Sep 17 00:00:00 2001 From: ekang7 Date: Thu, 6 Nov 2025 10:50:21 -0800 Subject: [PATCH 5/5] blocked undesired autocompletion for multiline hint --- crates/chat-cli/src/cli/chat/prompt.rs | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/chat-cli/src/cli/chat/prompt.rs b/crates/chat-cli/src/cli/chat/prompt.rs index d1e994c38f..35b81833de 100644 --- a/crates/chat-cli/src/cli/chat/prompt.rs +++ b/crates/chat-cli/src/cli/chat/prompt.rs @@ -358,6 +358,7 @@ impl ChatHinter { let triple_backtick_count = line.matches("```").count(); if triple_backtick_count % 2 == 1 { // We have an odd number of ```, meaning we're in multiline mode + // Show status hint (right arrow key is overridden to not complete this) return Some("in multiline mode, waiting for closing backticks ```".to_string()); } } @@ -559,6 +560,34 @@ impl rustyline::ConditionalEventHandler for PasteImageHandler { } } +/// Handler for right arrow key that prevents completing the multiline status hint +struct RightArrowHandler; + +impl rustyline::ConditionalEventHandler for RightArrowHandler { + fn handle( + &self, + _evt: &rustyline::Event, + _n: rustyline::RepeatCount, + _positive: bool, + ctx: &rustyline::EventContext<'_>, + ) -> Option { + let line = ctx.line(); + + // Check if we're in multiline mode with unclosed backticks + if line.contains("```") { + let triple_backtick_count = line.matches("```").count(); + if triple_backtick_count % 2 == 1 { + // We're in multiline mode - don't complete the hint + // Just move the cursor forward instead + return Some(Cmd::Move(rustyline::Movement::ForwardChar(1))); + } + } + + // Normal case - complete the hint + Some(Cmd::CompleteHint) + } +} + pub fn rl( os: &Os, sender: PromptQuerySender, @@ -652,6 +681,12 @@ pub fn rl( EventHandler::Conditional(Box::new(PasteImageHandler::new(paste_state))), ); + // Override right arrow key to prevent completing multiline status hints + rl.bind_sequence( + KeyEvent(KeyCode::Right, Modifiers::empty()), + EventHandler::Conditional(Box::new(RightArrowHandler)), + ); + Ok(rl) }