Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure cursor in view after format #4047

Merged
merged 3 commits into from
Oct 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2505,17 +2505,19 @@ async fn make_format_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");
let scrolloff = editor.config().scrolloff;
let doc = doc_mut!(editor, &doc_id);
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
let view = view_mut!(editor);
if doc.version() == doc_version {
doc.apply(&format, view_id);
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
view.ensure_cursor_in_view(doc, scrolloff);
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");
}
});
Ok(call)
Expand Down