diff options
author | zensayyy | 2022-10-01 14:32:09 +0000 |
---|---|---|
committer | GitHub | 2022-10-01 14:32:09 +0000 |
commit | c9584251f321a8540cf530561896b2f48f0b76a2 (patch) | |
tree | 33f425467695661fc7df5c11ce97a3c720d5b78f /helix-term | |
parent | cc257e9bf9a7eee7e68e04d04523a8fae10807cd (diff) |
Ensure cursor in view after format (#4047)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index c87ad0ca..fb1a4b38 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2504,18 +2504,23 @@ async fn make_format_callback( ) -> anyhow::Result<job::Callback> { let format = format.await?; let call: job::Callback = Box::new(move |editor, _compositor| { - let view_id = view!(editor).id; - if let Some(doc) = editor.document_mut(doc_id) { - if doc.version() == doc_version { - doc.apply(&format, view_id); - doc.append_changes_to_history(view_id); - doc.detect_indent_and_line_ending(); - if let Modified::SetUnmodified = modified { - doc.reset_modified(); - } - } else { - log::info!("discarded formatting changes because the document changed"); + if !editor.documents.contains_key(&doc_id) { + return; + } + + let scrolloff = editor.config().scrolloff; + let doc = doc_mut!(editor, &doc_id); + let view = view_mut!(editor); + if doc.version() == doc_version { + doc.apply(&format, view.id); + doc.append_changes_to_history(view.id); + 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) |