Ensure cursor in view after format (#4047)

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
pull/4060/head
zensayyy 2 years ago committed by GitHub
parent cc257e9bf9
commit c9584251f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2504,18 +2504,23 @@ async fn make_format_callback(
) -> anyhow::Result<job::Callback> { ) -> anyhow::Result<job::Callback> {
let format = format.await?; let format = format.await?;
let call: job::Callback = Box::new(move |editor, _compositor| { let call: job::Callback = Box::new(move |editor, _compositor| {
let view_id = view!(editor).id; if !editor.documents.contains_key(&doc_id) {
if let Some(doc) = editor.document_mut(doc_id) { return;
if doc.version() == doc_version { }
doc.apply(&format, view_id);
doc.append_changes_to_history(view_id); let scrolloff = editor.config().scrolloff;
doc.detect_indent_and_line_ending(); let doc = doc_mut!(editor, &doc_id);
if let Modified::SetUnmodified = modified { let view = view_mut!(editor);
doc.reset_modified(); if doc.version() == doc_version {
} doc.apply(&format, view.id);
} else { doc.append_changes_to_history(view.id);
log::info!("discarded formatting changes because the document changed"); doc.detect_indent_and_line_ending();
view.ensure_cursor_in_view(doc, scrolloff);
if let Modified::SetUnmodified = modified {
doc.reset_modified();
} }
} else {
log::info!("discarded formatting changes because the document changed");
} }
}); });
Ok(call) Ok(call)

Loading…
Cancel
Save