@@ -1162,7 +1162,12 @@ mod cmd {
1163 let fmt = doc.auto_format().map(|fmt| {
1163 let fmt = doc.auto_format().map(|fmt| {
1164 let shared = fmt.shared();
1164 let shared = fmt.shared();
1165− let callback = make_format_callback(doc.id(), doc.version(), true, shared.clone());
1165+ let callback = make_format_callback(
1168+ Modified::SetUnmodified,
1166 jobs.callback(callback);
1171 jobs.callback(callback);
@@ -1187,7 +1192,8 @@ mod cmd {
1187 let (_, doc) = current!(cx.editor);
1192 let (_, doc) = current!(cx.editor);
1189 if let Some(format) = doc.format() {
1194 if let Some(format) = doc.format() {
1190− let callback = make_format_callback(doc.id(), doc.version(), false, format);
1196+ make_format_callback(doc.id(), doc.version(), Modified::LeaveModified, format);
1191 cx.jobs.callback(callback);
1197 cx.jobs.callback(callback);
@@ -1907,6 +1913,13 @@ fn append_to_line(cx: &mut Context) {
1907 doc.set_selection(view.id, selection);
1913 doc.set_selection(view.id, selection);
1916+/// Sometimes when applying formatting changes we want to mark the buffer as unmodified, for
1917+/// example because we just applied the same changes while saving.
1910// Creates an LspCallback that waits for formatting changes to be computed. When they're done,
1923// Creates an LspCallback that waits for formatting changes to be computed. When they're done,
1911// it applies them, but only if the doc hasn't changed.
1924// it applies them, but only if the doc hasn't changed.
@@ -1915,7 +1928,7 @@ fn append_to_line(cx: &mut Context) {
1915async fn make_format_callback(
1928async fn make_format_callback(
1916 doc_id: DocumentId,
1929 doc_id: DocumentId,
1917 doc_version: i32,
1930 doc_version: i32,
1918− set_unmodified: bool,
1931+ modified: Modified,
1919 format: impl Future<Output = helix_lsp::util::LspFormatting> + Send + 'static,
1932 format: impl Future<Output = helix_lsp::util::LspFormatting> + Send + 'static,
1920) -> anyhow::Result<job::Callback> {
1933) -> anyhow::Result<job::Callback> {
1921 let format = format.await;
1934 let format = format.await;
@@ -1925,7 +1938,7 @@ async fn make_format_callback(
1925 if doc.version() == doc_version {
1938 if doc.version() == doc_version {
1926 doc.apply(&Transaction::from(format), view_id);
1939 doc.apply(&Transaction::from(format), view_id);
1927 doc.append_changes_to_history(view_id);
1940 doc.append_changes_to_history(view_id);
1928− if set_unmodified {
1941+ if let Modified::SetUnmodified = modified {
1929 doc.reset_modified();
1942 doc.reset_modified();
1931 } else {
1944 } else {