From b588ba1435d54286a1568d9f7a1b87c91537a066 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 31 Mar 2023 17:17:35 +0200 Subject: [PATCH] Avoid auto-indenting when accepting copilot suggestion Co-Authored-By: Nathan Sobo --- crates/editor/src/editor.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 623df221c4..62efad288d 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2145,6 +2145,21 @@ impl Editor { } pub fn insert(&mut self, text: &str, cx: &mut ViewContext) { + self.insert_with_autoindent_mode( + text, + Some(AutoindentMode::Block { + original_indent_columns: Vec::new(), + }), + cx, + ); + } + + fn insert_with_autoindent_mode( + &mut self, + text: &str, + autoindent_mode: Option, + cx: &mut ViewContext, + ) { let text: Arc = text.into(); self.transact(cx, |this, cx| { let old_selections = this.selections.all_adjusted(cx); @@ -2163,9 +2178,7 @@ impl Editor { old_selections .iter() .map(|s| (s.start..s.end, text.clone())), - Some(AutoindentMode::Block { - original_indent_columns: Vec::new(), - }), + autoindent_mode, cx, ); anchors @@ -2975,7 +2988,7 @@ impl Editor { .copilot_state .text_for_active_completion(cursor, &snapshot) { - self.insert(&text.to_string(), cx); + self.insert_with_autoindent_mode(&text.to_string(), None, cx); self.clear_copilot_suggestions(cx); true } else {