Select the language in Editor::save_as instead of Buffer::did_save

Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Nathan Sobo 2021-10-01 17:38:08 -06:00
parent fcf6a9d58a
commit 90cc01a50a
2 changed files with 6 additions and 4 deletions

View file

@ -2671,6 +2671,7 @@ impl workspace::ItemView for Editor {
cx.spawn(|buffer, mut cx| async move {
save_as.await.map(|new_file| {
buffer.update(&mut cx, |buffer, cx| {
buffer.set_language(new_file.select_language(cx), cx);
buffer.did_save(version, new_file.mtime, Some(new_file), cx);
});
})

View file

@ -710,6 +710,11 @@ impl Buffer {
&self.visible_text
}
pub fn set_language(&mut self, language: Option<Arc<Language>>, cx: &mut ModelContext<Self>) {
self.language = language;
self.reparse(cx);
}
pub fn did_save(
&mut self,
version: time::Global,
@ -720,10 +725,6 @@ impl Buffer {
self.saved_mtime = mtime;
self.saved_version = version;
if let Some(new_file) = new_file {
if let Some(language) = new_file.select_language(cx) {
self.language = Some(language);
self.reparse(cx);
}
self.file = Some(new_file);
}
cx.emit(Event::Saved);