@@ -27,6 +27,7 @@ use helix_core::{
27 SmallVec, Tendril, Transaction,
27 SmallVec, Tendril, Transaction,
29use helix_view::{
29use helix_view::{
30 clipboard::ClipboardType,
31 clipboard::ClipboardType,
31 document::{FormatterError, Mode, SCRATCH_BUFFER_NAME},
32 document::{FormatterError, Mode, SCRATCH_BUFFER_NAME},
32 editor::{Action, Motion},
33 editor::{Action, Motion},
@@ -859,8 +860,7 @@ fn align_selections(cx: &mut Context) {
859 changes.sort_unstable_by_key(|(from, _, _)| *from);
860 changes.sort_unstable_by_key(|(from, _, _)| *from);
861 let transaction = Transaction::change(doc.text(), changes.into_iter());
862 let transaction = Transaction::change(doc.text(), changes.into_iter());
862− doc.apply(&transaction, view.id);
863+ apply_transaction(&transaction, doc, view);
863− view.apply(&transaction, doc);
866fn goto_window(cx: &mut Context, align: Align) {
866fn goto_window(cx: &mut Context, align: Align) {
@@ -1290,8 +1290,7 @@ fn replace(cx: &mut Context) {
1293− doc.apply(&transaction, view.id);
1293+ apply_transaction(&transaction, doc, view);
1294− view.apply(&transaction, doc);
@@ -1308,8 +1307,7 @@ where
1308 (range.from(), range.to(), Some(text))
1307 (range.from(), range.to(), Some(text))
1311− doc.apply(&transaction, view.id);
1310+ apply_transaction(&transaction, doc, view);
1312− view.apply(&transaction, doc);
1315fn switch_case(cx: &mut Context) {
1313fn switch_case(cx: &mut Context) {
@@ -2115,8 +2113,7 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
2115 let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
2113 let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
2116 (range.from(), range.to(), None)
2114 (range.from(), range.to(), None)
2118− doc.apply(&transaction, view.id);
2116+ apply_transaction(&transaction, doc, view);
2119− view.apply(&transaction, doc);
2121 match op {
2118 match op {
2122 Operation::Delete => {
2119 Operation::Delete => {
@@ -2131,14 +2128,10 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
2132#[inline]
2129#[inline]
2133fn delete_selection_insert_mode(doc: &mut Document, view: &mut View, selection: &Selection) {
2130fn delete_selection_insert_mode(doc: &mut Document, view: &mut View, selection: &Selection) {
2134− let view_id = view.id;
2137 let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
2131 let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
2138 (range.from(), range.to(), None)
2132 (range.from(), range.to(), None)
2140− doc.apply(&transaction, view_id);
2134+ apply_transaction(&transaction, doc, view);
2141− view.apply(&transaction, doc);
2144fn delete_selection(cx: &mut Context) {
2137fn delete_selection(cx: &mut Context) {
@@ -2234,8 +2227,7 @@ fn append_mode(cx: &mut Context) {
2234 doc.text(),
2227 doc.text(),
2235 [(end, end, Some(doc.line_ending.as_str().into()))].into_iter(),
2228 [(end, end, Some(doc.line_ending.as_str().into()))].into_iter(),
2237− doc.apply(&transaction, view.id);
2230+ apply_transaction(&transaction, doc, view);
2238− view.apply(&transaction, doc);
2241 let selection = doc.selection(view.id).clone().transform(|range| {
2233 let selection = doc.selection(view.id).clone().transform(|range| {
@@ -2535,8 +2527,7 @@ async fn make_format_callback(
2535 let doc = doc_mut!(editor, &doc_id);
2527 let doc = doc_mut!(editor, &doc_id);
2536 let view = view_mut!(editor);
2528 let view = view_mut!(editor);
2537 if doc.version() == doc_version {
2529 if doc.version() == doc_version {
2538− doc.apply(&format, view.id);
2530+ apply_transaction(&format, doc, view);
2539− view.apply(&format, doc);
2540 doc.append_changes_to_history(view.id);
2531 doc.append_changes_to_history(view.id);
2541 doc.detect_indent_and_line_ending();
2532 doc.detect_indent_and_line_ending();
2542 view.ensure_cursor_in_view(doc, scrolloff);
2533 view.ensure_cursor_in_view(doc, scrolloff);
@@ -2623,8 +2614,7 @@ fn open(cx: &mut Context, open: Open) {
2624 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
2615 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
2626− doc.apply(&transaction, view.id);
2617+ apply_transaction(&transaction, doc, view);
2627− view.apply(&transaction, doc);
2630// o inserts a new line after each line with a selection
2620// o inserts a new line after each line with a selection
@@ -2692,8 +2682,7 @@ fn try_restore_indent(doc: &mut Document, view: &mut View) {
2692 let line_start_pos = text.line_to_char(range.cursor_line(text));
2682 let line_start_pos = text.line_to_char(range.cursor_line(text));
2693 (line_start_pos, pos, None)
2683 (line_start_pos, pos, None)
2695− doc.apply(&transaction, view.id);
2685+ apply_transaction(&transaction, doc, view);
2696− view.apply(&transaction, doc);
@@ -3007,8 +2996,7 @@ pub mod insert {
3008 let (view, doc) = current!(cx.editor);
2997 let (view, doc) = current!(cx.editor);
3009 if let Some(t) = transaction {
2998 if let Some(t) = transaction {
3010− doc.apply(&t, view.id);
2999+ apply_transaction(&t, doc, view);
3011− view.apply(&t, doc);
3014 // TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc)
3002 // TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc)
@@ -3030,8 +3018,7 @@ pub mod insert {
3030 &doc.selection(view.id).clone().cursors(doc.text().slice(..)),
3018 &doc.selection(view.id).clone().cursors(doc.text().slice(..)),
3033− doc.apply(&transaction, view.id);
3021+ apply_transaction(&transaction, doc, view);
3034− view.apply(&transaction, doc);
3037 pub fn insert_newline(cx: &mut Context) {
3024 pub fn insert_newline(cx: &mut Context) {
@@ -3118,8 +3105,7 @@ pub mod insert {
3118 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
3105 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
3120 let (view, doc) = current!(cx.editor);
3107 let (view, doc) = current!(cx.editor);
3121− doc.apply(&transaction, view.id);
3108+ apply_transaction(&transaction, doc, view);
3122− view.apply(&transaction, doc);
3125 pub fn delete_char_backward(cx: &mut Context) {
3111 pub fn delete_char_backward(cx: &mut Context) {
@@ -3213,8 +3199,7 @@ pub mod insert {
3215 let (view, doc) = current!(cx.editor);
3201 let (view, doc) = current!(cx.editor);
3216− doc.apply(&transaction, view.id);
3202+ apply_transaction(&transaction, doc, view);
3217− view.apply(&transaction, doc);
3219 lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
3204 lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
@@ -3232,8 +3217,7 @@ pub mod insert {
3235− doc.apply(&transaction, view.id);
3220+ apply_transaction(&transaction, doc, view);
3236− view.apply(&transaction, doc);
3238 lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
3222 lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
@@ -3470,8 +3454,7 @@ fn paste_impl(values: &[String], doc: &mut Document, view: &mut View, action: Pa
3471 (pos, pos, values.next())
3455 (pos, pos, values.next())
3473− doc.apply(&transaction, view.id);
3457+ apply_transaction(&transaction, doc, view);
3474− view.apply(&transaction, doc);
3477pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) {
3460pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) {
@@ -3563,8 +3546,7 @@ fn replace_with_yanked(cx: &mut Context) {
3566− doc.apply(&transaction, view.id);
3549+ apply_transaction(&transaction, doc, view);
3567− view.apply(&transaction, doc);
@@ -3587,8 +3569,7 @@ fn replace_selections_with_clipboard_impl(
3590− doc.apply(&transaction, view.id);
3572+ apply_transaction(&transaction, doc, view);
3591− view.apply(&transaction, doc);
3592 doc.append_changes_to_history(view.id);
3573 doc.append_changes_to_history(view.id);
@@ -3658,8 +3639,7 @@ fn indent(cx: &mut Context) {
3658 Some((pos, pos, Some(indent.clone())))
3639 Some((pos, pos, Some(indent.clone())))
3661− doc.apply(&transaction, view.id);
3642+ apply_transaction(&transaction, doc, view);
3662− view.apply(&transaction, doc);
3665fn unindent(cx: &mut Context) {
3645fn unindent(cx: &mut Context) {
@@ -3698,8 +3678,7 @@ fn unindent(cx: &mut Context) {
3699 let transaction = Transaction::change(doc.text(), changes.into_iter());
3679 let transaction = Transaction::change(doc.text(), changes.into_iter());
3701− doc.apply(&transaction, view.id);
3681+ apply_transaction(&transaction, doc, view);
3702− view.apply(&transaction, doc);
3705fn format_selections(cx: &mut Context) {
3684fn format_selections(cx: &mut Context) {
@@ -3746,8 +3725,7 @@ fn format_selections(cx: &mut Context) {
3746 // language_server.offset_encoding(),
3725 // language_server.offset_encoding(),
3749− // doc.apply(&transaction, view.id);
3728+ // apply_transaction(&transaction, doc, view);
3750− // view.apply(&transaction, doc);
@@ -3802,8 +3780,7 @@ fn join_selections_inner(cx: &mut Context, select_space: bool) {
3802 Transaction::change(doc.text(), changes.into_iter())
3780 Transaction::change(doc.text(), changes.into_iter())
3805− doc.apply(&transaction, view.id);
3783+ apply_transaction(&transaction, doc, view);
3806− view.apply(&transaction, doc);
3809fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
3786fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
@@ -3956,8 +3933,7 @@ fn toggle_comments(cx: &mut Context) {
3956 .map(|tc| tc.as_ref());
3933 .map(|tc| tc.as_ref());
3957 let transaction = comment::toggle_line_comments(doc.text(), doc.selection(view.id), token);
3934 let transaction = comment::toggle_line_comments(doc.text(), doc.selection(view.id), token);
3959− doc.apply(&transaction, view.id);
3936+ apply_transaction(&transaction, doc, view);
3960− view.apply(&transaction, doc);
3961 exit_select_mode(cx);
3937 exit_select_mode(cx);
@@ -4013,8 +3989,7 @@ fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
4013 .map(|(range, fragment)| (range.from(), range.to(), Some(fragment))),
3989 .map(|(range, fragment)| (range.from(), range.to(), Some(fragment))),
4016− doc.apply(&transaction, view.id);
3992+ apply_transaction(&transaction, doc, view);
4017− view.apply(&transaction, doc);
4020fn rotate_selection_contents_forward(cx: &mut Context) {
3995fn rotate_selection_contents_forward(cx: &mut Context) {
@@ -4510,8 +4485,7 @@ fn surround_add(cx: &mut Context) {
4512 let transaction = Transaction::change(doc.text(), changes.into_iter());
4487 let transaction = Transaction::change(doc.text(), changes.into_iter());
4513− doc.apply(&transaction, view.id);
4488+ apply_transaction(&transaction, doc, view);
4514− view.apply(&transaction, doc);
@@ -4550,8 +4524,7 @@ fn surround_replace(cx: &mut Context) {
4550 (pos, pos + 1, Some(t))
4524 (pos, pos + 1, Some(t))
4553− doc.apply(&transaction, view.id);
4527+ apply_transaction(&transaction, doc, view);
4554− view.apply(&transaction, doc);
@@ -4578,8 +4551,7 @@ fn surround_delete(cx: &mut Context) {
4579 let transaction =
4552 let transaction =
4580 Transaction::change(doc.text(), change_pos.into_iter().map(|p| (p, p + 1, None)));
4553 Transaction::change(doc.text(), change_pos.into_iter().map(|p| (p, p + 1, None)));
4581− doc.apply(&transaction, view.id);
4554+ apply_transaction(&transaction, doc, view);
4582− view.apply(&transaction, doc);
@@ -4754,8 +4726,7 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
4755 if behavior != &ShellBehavior::Ignore {
4727 if behavior != &ShellBehavior::Ignore {
4756 let transaction = Transaction::change(doc.text(), changes.into_iter());
4728 let transaction = Transaction::change(doc.text(), changes.into_iter());
4757− doc.apply(&transaction, view.id);
4729+ apply_transaction(&transaction, doc, view);
4758− view.apply(&transaction, doc);
4759 doc.append_changes_to_history(view.id);
4730 doc.append_changes_to_history(view.id);
@@ -4818,8 +4789,7 @@ fn add_newline_impl(cx: &mut Context, open: Open) {
4820 let transaction = Transaction::change(text, changes);
4791 let transaction = Transaction::change(text, changes);
4821− doc.apply(&transaction, view.id);
4792+ apply_transaction(&transaction, doc, view);
4822− view.apply(&transaction, doc);
4825/// Increment object under cursor by count.
4795/// Increment object under cursor by count.
@@ -4912,8 +4882,7 @@ fn increment_impl(cx: &mut Context, amount: i64) {
4912 let transaction = Transaction::change(doc.text(), changes);
4882 let transaction = Transaction::change(doc.text(), changes);
4913 let transaction = transaction.with_selection(selection.clone());
4883 let transaction = transaction.with_selection(selection.clone());
4915− doc.apply(&transaction, view.id);
4885+ apply_transaction(&transaction, doc, view);
4916− view.apply(&transaction, doc);