Avoid auto-indenting when accepting copilot suggestion

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2023-03-31 17:17:35 +02:00
parent 6e43e77c3f
commit b588ba1435

View file

@ -2145,6 +2145,21 @@ impl Editor {
} }
pub fn insert(&mut self, text: &str, cx: &mut ViewContext<Self>) { pub fn insert(&mut self, text: &str, cx: &mut ViewContext<Self>) {
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<AutoindentMode>,
cx: &mut ViewContext<Self>,
) {
let text: Arc<str> = text.into(); let text: Arc<str> = text.into();
self.transact(cx, |this, cx| { self.transact(cx, |this, cx| {
let old_selections = this.selections.all_adjusted(cx); let old_selections = this.selections.all_adjusted(cx);
@ -2163,9 +2178,7 @@ impl Editor {
old_selections old_selections
.iter() .iter()
.map(|s| (s.start..s.end, text.clone())), .map(|s| (s.start..s.end, text.clone())),
Some(AutoindentMode::Block { autoindent_mode,
original_indent_columns: Vec::new(),
}),
cx, cx,
); );
anchors anchors
@ -2975,7 +2988,7 @@ impl Editor {
.copilot_state .copilot_state
.text_for_active_completion(cursor, &snapshot) .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); self.clear_copilot_suggestions(cx);
true true
} else { } else {