on master help sign in
Remove apply_transaction helper (#5598)
a20a96aIvan Tham
helix-term/src/commands.rs+28−29
@@ -26,7 +26,6 @@ use helix_core::{
26 SmallVec, Tendril, Transaction,
26 SmallVec, Tendril, Transaction,
27};
27};
28use helix_view::{
28use helix_view::{
29− apply_transaction,
30 clipboard::ClipboardType,
29 clipboard::ClipboardType,
31 document::{FormatterError, Mode, SCRATCH_BUFFER_NAME},
30 document::{FormatterError, Mode, SCRATCH_BUFFER_NAME},
32 editor::{Action, Motion},
31 editor::{Action, Motion},
@@ -864,7 +863,7 @@ fn align_selections(cx: &mut Context) {
864 changes.sort_unstable_by_key(|(from, _, _)| *from);
863 changes.sort_unstable_by_key(|(from, _, _)| *from);
865
864
866 let transaction = Transaction::change(doc.text(), changes.into_iter());
865 let transaction = Transaction::change(doc.text(), changes.into_iter());
867− apply_transaction(&transaction, doc, view);
866+ doc.apply(&transaction, view.id);
868}
867}
869
868
870fn goto_window(cx: &mut Context, align: Align) {
869fn goto_window(cx: &mut Context, align: Align) {
@@ -1316,7 +1315,7 @@ fn replace(cx: &mut Context) {
1316 }
1315 }
1317 });
1316 });
1318
1317
1319− apply_transaction(&transaction, doc, view);
1318+ doc.apply(&transaction, view.id);
1320 exit_select_mode(cx);
1319 exit_select_mode(cx);
1321 }
1320 }
1322 })
1321 })
@@ -1334,7 +1333,7 @@ where
1334 (range.from(), range.to(), Some(text))
1333 (range.from(), range.to(), Some(text))
1335 });
1334 });
1336
1335
1337− apply_transaction(&transaction, doc, view);
1336+ doc.apply(&transaction, view.id);
1338}
1337}
1339
1338
1340fn switch_case(cx: &mut Context) {
1339fn switch_case(cx: &mut Context) {
@@ -2159,7 +2158,7 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
2159 let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
2158 let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
2160 (range.from(), range.to(), None)
2159 (range.from(), range.to(), None)
2161 });
2160 });
2162− apply_transaction(&transaction, doc, view);
2161+ doc.apply(&transaction, view.id);
2163
2162
2164 match op {
2163 match op {
2165 Operation::Delete => {
2164 Operation::Delete => {
@@ -2177,7 +2176,7 @@ fn delete_selection_insert_mode(doc: &mut Document, view: &mut View, selection:
2177 let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
2176 let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
2178 (range.from(), range.to(), None)
2177 (range.from(), range.to(), None)
2179 });
2178 });
2180− apply_transaction(&transaction, doc, view);
2179+ doc.apply(&transaction, view.id);
2181}
2180}
2182
2181
2183fn delete_selection(cx: &mut Context) {
2182fn delete_selection(cx: &mut Context) {
@@ -2273,7 +2272,7 @@ fn append_mode(cx: &mut Context) {
2273 doc.text(),
2272 doc.text(),
2274 [(end, end, Some(doc.line_ending.as_str().into()))].into_iter(),
2273 [(end, end, Some(doc.line_ending.as_str().into()))].into_iter(),
2275 );
2274 );
2276− apply_transaction(&transaction, doc, view);
2275+ doc.apply(&transaction, view.id);
2277 }
2276 }
2278
2277
2279 let selection = doc.selection(view.id).clone().transform(|range| {
2278 let selection = doc.selection(view.id).clone().transform(|range| {
@@ -2583,7 +2582,7 @@ async fn make_format_callback(
2583
2582
2584 if let Ok(format) = format {
2583 if let Ok(format) = format {
2585 if doc.version() == doc_version {
2584 if doc.version() == doc_version {
2586− apply_transaction(&format, doc, view);
2585+ doc.apply(&format, view.id);
2587 doc.append_changes_to_history(view);
2586 doc.append_changes_to_history(view);
2588 doc.detect_indent_and_line_ending();
2587 doc.detect_indent_and_line_ending();
2589 view.ensure_cursor_in_view(doc, scrolloff);
2588 view.ensure_cursor_in_view(doc, scrolloff);
@@ -2676,7 +2675,7 @@ fn open(cx: &mut Context, open: Open) {
2676
2675
2677 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
2676 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
2678
2677
2679− apply_transaction(&transaction, doc, view);
2678+ doc.apply(&transaction, view.id);
2680}
2679}
2681
2680
2682// o inserts a new line after each line with a selection
2681// o inserts a new line after each line with a selection
@@ -3104,7 +3103,7 @@ pub mod insert {
3104
3103
3105 let (view, doc) = current!(cx.editor);
3104 let (view, doc) = current!(cx.editor);
3106 if let Some(t) = transaction {
3105 if let Some(t) = transaction {
3107− apply_transaction(&t, doc, view);
3106+ doc.apply(&t, view.id);
3108 }
3107 }
3109
3108
3110 // TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc)
3109 // TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc)
@@ -3126,7 +3125,7 @@ pub mod insert {
3126 &doc.selection(view.id).clone().cursors(doc.text().slice(..)),
3125 &doc.selection(view.id).clone().cursors(doc.text().slice(..)),
3127 indent,
3126 indent,
3128 );
3127 );
3129− apply_transaction(&transaction, doc, view);
3128+ doc.apply(&transaction, view.id);
3130 }
3129 }
3131
3130
3132 pub fn insert_newline(cx: &mut Context) {
3131 pub fn insert_newline(cx: &mut Context) {
@@ -3231,7 +3230,7 @@ pub mod insert {
3231 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
3230 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
3232
3231
3233 let (view, doc) = current!(cx.editor);
3232 let (view, doc) = current!(cx.editor);
3234− apply_transaction(&transaction, doc, view);
3233+ doc.apply(&transaction, view.id);
3235 }
3234 }
3236
3235
3237 pub fn delete_char_backward(cx: &mut Context) {
3236 pub fn delete_char_backward(cx: &mut Context) {
@@ -3326,7 +3325,7 @@ pub mod insert {
3326 }
3325 }
3327 });
3326 });
3328 let (view, doc) = current!(cx.editor);
3327 let (view, doc) = current!(cx.editor);
3329− apply_transaction(&transaction, doc, view);
3328+ doc.apply(&transaction, view.id);
3330
3329
3331 lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
3330 lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
3332 }
3331 }
@@ -3344,7 +3343,7 @@ pub mod insert {
3344 None,
3343 None,
3345 )
3344 )
3346 });
3345 });
3347− apply_transaction(&transaction, doc, view);
3346+ doc.apply(&transaction, view.id);
3348
3347
3349 lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
3348 lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
3350 }
3349 }
@@ -3625,7 +3624,7 @@ fn paste_impl(
3625 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
3624 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
3626 }
3625 }
3627
3626
3628− apply_transaction(&transaction, doc, view);
3627+ doc.apply(&transaction, view.id);
3629}
3628}
3630
3629
3631pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) {
3630pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) {
@@ -3717,7 +3716,7 @@ fn replace_with_yanked(cx: &mut Context) {
3717 }
3716 }
3718 });
3717 });
3719
3718
3720− apply_transaction(&transaction, doc, view);
3719+ doc.apply(&transaction, view.id);
3721 exit_select_mode(cx);
3720 exit_select_mode(cx);
3722 }
3721 }
3723 }
3722 }
@@ -3741,7 +3740,7 @@ fn replace_selections_with_clipboard_impl(
3741 )
3740 )
3742 });
3741 });
3743
3742
3744− apply_transaction(&transaction, doc, view);
3743+ doc.apply(&transaction, view.id);
3745 doc.append_changes_to_history(view);
3744 doc.append_changes_to_history(view);
3746 }
3745 }
3747 Err(e) => return Err(e.context("Couldn't get system clipboard contents")),
3746 Err(e) => return Err(e.context("Couldn't get system clipboard contents")),
@@ -3813,7 +3812,7 @@ fn indent(cx: &mut Context) {
3813 Some((pos, pos, Some(indent.clone())))
3812 Some((pos, pos, Some(indent.clone())))
3814 }),
3813 }),
3815 );
3814 );
3816− apply_transaction(&transaction, doc, view);
3815+ doc.apply(&transaction, view.id);
3817}
3816}
3818
3817
3819fn unindent(cx: &mut Context) {
3818fn unindent(cx: &mut Context) {
@@ -3852,7 +3851,7 @@ fn unindent(cx: &mut Context) {
3852
3851
3853 let transaction = Transaction::change(doc.text(), changes.into_iter());
3852 let transaction = Transaction::change(doc.text(), changes.into_iter());
3854
3853
3855− apply_transaction(&transaction, doc, view);
3854+ doc.apply(&transaction, view.id);
3856}
3855}
3857
3856
3858fn format_selections(cx: &mut Context) {
3857fn format_selections(cx: &mut Context) {
@@ -3907,7 +3906,7 @@ fn format_selections(cx: &mut Context) {
3907 language_server.offset_encoding(),
3906 language_server.offset_encoding(),
3908 );
3907 );
3909
3908
3910− apply_transaction(&transaction, doc, view);
3909+ doc.apply(&transaction, view.id);
3911}
3910}
3912
3911
3913fn join_selections_impl(cx: &mut Context, select_space: bool) {
3912fn join_selections_impl(cx: &mut Context, select_space: bool) {
@@ -3966,7 +3965,7 @@ fn join_selections_impl(cx: &mut Context, select_space: bool) {
3966 Transaction::change(doc.text(), changes.into_iter())
3965 Transaction::change(doc.text(), changes.into_iter())
3967 };
3966 };
3968
3967
3969− apply_transaction(&transaction, doc, view);
3968+ doc.apply(&transaction, view.id);
3970}
3969}
3971
3970
3972fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
3971fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
@@ -4109,7 +4108,7 @@ fn toggle_comments(cx: &mut Context) {
4109 .map(|tc| tc.as_ref());
4108 .map(|tc| tc.as_ref());
4110 let transaction = comment::toggle_line_comments(doc.text(), doc.selection(view.id), token);
4109 let transaction = comment::toggle_line_comments(doc.text(), doc.selection(view.id), token);
4111
4110
4112− apply_transaction(&transaction, doc, view);
4111+ doc.apply(&transaction, view.id);
4113 exit_select_mode(cx);
4112 exit_select_mode(cx);
4114}
4113}
4115
4114
@@ -4165,7 +4164,7 @@ fn rotate_selection_contents(cx: &mut Context, direction: Direction) {
4165 .map(|(range, fragment)| (range.from(), range.to(), Some(fragment))),
4164 .map(|(range, fragment)| (range.from(), range.to(), Some(fragment))),
4166 );
4165 );
4167
4166
4168− apply_transaction(&transaction, doc, view);
4167+ doc.apply(&transaction, view.id);
4169}
4168}
4170
4169
4171fn rotate_selection_contents_forward(cx: &mut Context) {
4170fn rotate_selection_contents_forward(cx: &mut Context) {
@@ -4698,7 +4697,7 @@ fn surround_add(cx: &mut Context) {
4698
4697
4699 let transaction = Transaction::change(doc.text(), changes.into_iter())
4698 let transaction = Transaction::change(doc.text(), changes.into_iter())
4700 .with_selection(Selection::new(ranges, selection.primary_index()));
4699 .with_selection(Selection::new(ranges, selection.primary_index()));
4701− apply_transaction(&transaction, doc, view);
4700+ doc.apply(&transaction, view.id);
4702 exit_select_mode(cx);
4701 exit_select_mode(cx);
4703 })
4702 })
4704}
4703}
@@ -4738,7 +4737,7 @@ fn surround_replace(cx: &mut Context) {
4738 (pos, pos + 1, Some(t))
4737 (pos, pos + 1, Some(t))
4739 }),
4738 }),
4740 );
4739 );
4741− apply_transaction(&transaction, doc, view);
4740+ doc.apply(&transaction, view.id);
4742 exit_select_mode(cx);
4741 exit_select_mode(cx);
4743 });
4742 });
4744 })
4743 })
@@ -4766,7 +4765,7 @@ fn surround_delete(cx: &mut Context) {
4766
4765
4767 let transaction =
4766 let transaction =
4768 Transaction::change(doc.text(), change_pos.into_iter().map(|p| (p, p + 1, None)));
4767 Transaction::change(doc.text(), change_pos.into_iter().map(|p| (p, p + 1, None)));
4769− apply_transaction(&transaction, doc, view);
4768+ doc.apply(&transaction, view.id);
4770 exit_select_mode(cx);
4769 exit_select_mode(cx);
4771 })
4770 })
4772}
4771}
@@ -4981,7 +4980,7 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
4981 if behavior != &ShellBehavior::Ignore {
4980 if behavior != &ShellBehavior::Ignore {
4982 let transaction = Transaction::change(doc.text(), changes.into_iter())
4981 let transaction = Transaction::change(doc.text(), changes.into_iter())
4983 .with_selection(Selection::new(ranges, selection.primary_index()));
4982 .with_selection(Selection::new(ranges, selection.primary_index()));
4984− apply_transaction(&transaction, doc, view);
4983+ doc.apply(&transaction, view.id);
4985 doc.append_changes_to_history(view);
4984 doc.append_changes_to_history(view);
4986 }
4985 }
4987
4986
@@ -5044,7 +5043,7 @@ fn add_newline_impl(cx: &mut Context, open: Open) {
5044 });
5043 });
5045
5044
5046 let transaction = Transaction::change(text, changes);
5045 let transaction = Transaction::change(text, changes);
5047− apply_transaction(&transaction, doc, view);
5046+ doc.apply(&transaction, view.id);
5048}
5047}
5049
5048
5050enum IncrementDirection {
5049enum IncrementDirection {
@@ -5111,7 +5110,7 @@ fn increment_impl(cx: &mut Context, increment_direction: IncrementDirection) {
5111 let new_selection = Selection::new(new_selection_ranges, selection.primary_index());
5110 let new_selection = Selection::new(new_selection_ranges, selection.primary_index());
5112 let transaction = Transaction::change(doc.text(), changes.into_iter());
5111 let transaction = Transaction::change(doc.text(), changes.into_iter());
5113 let transaction = transaction.with_selection(new_selection);
5112 let transaction = transaction.with_selection(new_selection);
5114− apply_transaction(&transaction, doc, view);
5113+ doc.apply(&transaction, view.id);
5115 }
5114 }
5116}
5115}
5117
5116
helix-term/src/commands/lsp.rs+2−2
@@ -13,7 +13,7 @@ use tui::{
13use super::{align_view, push_jump, Align, Context, Editor, Open};
13use super::{align_view, push_jump, Align, Context, Editor, Open};
14
14
15use helix_core::{path, Selection};
15use helix_core::{path, Selection};
16−use helix_view::{apply_transaction, document::Mode, editor::Action, theme::Style};
16+use helix_view::{document::Mode, editor::Action, theme::Style};
17
17
18use crate::{
18use crate::{
19 compositor::{self, Compositor},
19 compositor::{self, Compositor},
@@ -800,7 +800,7 @@ pub fn apply_workspace_edit(
800 offset_encoding,
800 offset_encoding,
801 );
801 );
802 let view = view_mut!(editor, view_id);
802 let view = view_mut!(editor, view_id);
803− apply_transaction(&transaction, doc, view);
803+ doc.apply(&transaction, view.id);
804 doc.append_changes_to_history(view);
804 doc.append_changes_to_history(view);
805 };
805 };
806
806
helix-term/src/commands/typed.rs+5−8
@@ -4,10 +4,7 @@ use crate::job::Job;
4
4
5use super::*;
5use super::*;
6
6
7−use helix_view::{
8− apply_transaction,
9− editor::{Action, CloseError, ConfigEvent},
7+use helix_view::editor::{Action, CloseError, ConfigEvent};
10−};
11use ui::completers::{self, Completer};
8use ui::completers::{self, Completer};
12
9
13#[derive(Clone)]
10#[derive(Clone)]
@@ -480,7 +477,7 @@ fn set_line_ending(
480 }
477 }
481 }),
478 }),
482 );
479 );
483− apply_transaction(&transaction, doc, view);
480+ doc.apply(&transaction, view.id);
484 doc.append_changes_to_history(view);
481 doc.append_changes_to_history(view);
485
482
486 Ok(())
483 Ok(())
@@ -925,7 +922,7 @@ fn replace_selections_with_clipboard_impl(
925 (range.from(), range.to(), Some(contents.as_str().into()))
922 (range.from(), range.to(), Some(contents.as_str().into()))
926 });
923 });
927
924
928− apply_transaction(&transaction, doc, view);
925+ doc.apply(&transaction, view.id);
929 doc.append_changes_to_history(view);
926 doc.append_changes_to_history(view);
930 Ok(())
927 Ok(())
931 }
928 }
@@ -1596,7 +1593,7 @@ fn sort_impl(
1596 .map(|(s, fragment)| (s.from(), s.to(), Some(fragment))),
1593 .map(|(s, fragment)| (s.from(), s.to(), Some(fragment))),
1597 );
1594 );
1598
1595
1599− apply_transaction(&transaction, doc, view);
1596+ doc.apply(&transaction, view.id);
1600 doc.append_changes_to_history(view);
1597 doc.append_changes_to_history(view);
1601
1598
1602 Ok(())
1599 Ok(())
@@ -1640,7 +1637,7 @@ fn reflow(
1640 (range.from(), range.to(), Some(reflowed_text))
1637 (range.from(), range.to(), Some(reflowed_text))
1641 });
1638 });
1642
1639
1643− apply_transaction(&transaction, doc, view);
1640+ doc.apply(&transaction, view.id);
1644 doc.append_changes_to_history(view);
1641 doc.append_changes_to_history(view);
1645 view.ensure_cursor_in_view(doc, scrolloff);
1642 view.ensure_cursor_in_view(doc, scrolloff);
1646
1643
helix-term/src/ui/completion.rs+4−4
@@ -1,5 +1,5 @@
1use crate::compositor::{Component, Context, Event, EventResult};
1use crate::compositor::{Component, Context, Event, EventResult};
2−use helix_view::{apply_transaction, editor::CompleteAction, ViewId};
2+use helix_view::{editor::CompleteAction, ViewId};
3use tui::buffer::Buffer as Surface;
3use tui::buffer::Buffer as Surface;
4
4
5use std::borrow::Cow;
5use std::borrow::Cow;
@@ -183,7 +183,7 @@ impl Completion {
183
183
184 // initialize a savepoint
184 // initialize a savepoint
185 doc.savepoint();
185 doc.savepoint();
186− apply_transaction(&transaction, doc, view);
186+ doc.apply(&transaction, view.id);
187
187
188 editor.last_completion = Some(CompleteAction {
188 editor.last_completion = Some(CompleteAction {
189 trigger_offset,
189 trigger_offset,
@@ -203,7 +203,7 @@ impl Completion {
203 trigger_offset,
203 trigger_offset,
204 );
204 );
205
205
206− apply_transaction(&transaction, doc, view);
206+ doc.apply(&transaction, view.id);
207
207
208 editor.last_completion = Some(CompleteAction {
208 editor.last_completion = Some(CompleteAction {
209 trigger_offset,
209 trigger_offset,
@@ -233,7 +233,7 @@ impl Completion {
233 additional_edits.clone(),
233 additional_edits.clone(),
234 offset_encoding, // TODO: should probably transcode in Client
234 offset_encoding, // TODO: should probably transcode in Client
235 );
235 );
236− apply_transaction(&transaction, doc, view);
236+ doc.apply(&transaction, view.id);
237 }
237 }
238 }
238 }
239 }
239 }
helix-term/src/ui/editor.rs+1−2
@@ -17,7 +17,6 @@ use helix_core::{
17 visual_coords_at_pos, LineEnding, Position, Range, Selection, Transaction,
17 visual_coords_at_pos, LineEnding, Position, Range, Selection, Transaction,
18};
18};
19use helix_view::{
19use helix_view::{
20− apply_transaction,
21 document::{Mode, SCRATCH_BUFFER_NAME},
20 document::{Mode, SCRATCH_BUFFER_NAME},
22 editor::{CompleteAction, CursorShapeConfig},
21 editor::{CompleteAction, CursorShapeConfig},
23 graphics::{Color, CursorKind, Modifier, Rect, Style},
22 graphics::{Color, CursorKind, Modifier, Rect, Style},
@@ -1048,7 +1047,7 @@ impl EditorView {
1048 (shift_position(start), shift_position(end), t)
1047 (shift_position(start), shift_position(end), t)
1049 }),
1048 }),
1050 );
1049 );
1051− apply_transaction(&tx, doc, view);
1050+ doc.apply(&tx, view.id);
1052 }
1051 }
1053 InsertEvent::TriggerCompletion => {
1052 InsertEvent::TriggerCompletion => {
1054 let (_, doc) = current!(cxt.editor);
1053 let (_, doc) = current!(cxt.editor);
helix-term/tests/test/helpers.rs+2−2
@@ -130,7 +130,7 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
130 })
130 })
131 .with_selection(test_case.in_selection.clone());
131 .with_selection(test_case.in_selection.clone());
132
132
133− helix_view::apply_transaction(&transaction, doc, view);
133+ doc.apply(&transaction, view.id);
134
134
135 test_key_sequence(
135 test_key_sequence(
136 &mut app,
136 &mut app,
@@ -315,7 +315,7 @@ impl AppBuilder {
315 .with_selection(selection);
315 .with_selection(selection);
316
316
317 // replace the initial text with the input text
317 // replace the initial text with the input text
318− helix_view::apply_transaction(&trans, doc, view);
318+ doc.apply(&trans, view.id);
319 }
319 }
320
320
321 Ok(app)
321 Ok(app)
helix-view/src/document.rs+3−6
@@ -27,7 +27,7 @@ use helix_core::{
27};
27};
28
28
29use crate::editor::RedrawHandle;
29use crate::editor::RedrawHandle;
30−use crate::{apply_transaction, DocumentId, Editor, View, ViewId};
30+use crate::{DocumentId, Editor, View, ViewId};
31
31
32/// 8kB of buffer space for encoding and decoding `Rope`s.
32/// 8kB of buffer space for encoding and decoding `Rope`s.
33const BUF_SIZE: usize = 8192;
33const BUF_SIZE: usize = 8192;
@@ -650,7 +650,7 @@ impl Document {
650 // This is not considered a modification of the contents of the file regardless
650 // This is not considered a modification of the contents of the file regardless
651 // of the encoding.
651 // of the encoding.
652 let transaction = helix_core::diff::compare_ropes(self.text(), &rope);
652 let transaction = helix_core::diff::compare_ropes(self.text(), &rope);
653− apply_transaction(&transaction, self, view);
653+ self.apply(&transaction, view.id);
654 self.append_changes_to_history(view);
654 self.append_changes_to_history(view);
655 self.reset_modified();
655 self.reset_modified();
656
656
@@ -852,9 +852,6 @@ impl Document {
852 }
852 }
853
853
854 /// Apply a [`Transaction`] to the [`Document`] to change its text.
854 /// Apply a [`Transaction`] to the [`Document`] to change its text.
855− /// Instead of calling this function directly, use [crate::apply_transaction]
856− /// to ensure that the transaction is applied to the appropriate [`View`] as
857− /// well.
858 pub fn apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
855 pub fn apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
859 // store the state just before any changes are made. This allows us to undo to the
856 // store the state just before any changes are made. This allows us to undo to the
860 // state just before a transaction was applied.
857 // state just before a transaction was applied.
@@ -911,7 +908,7 @@ impl Document {
911
908
912 pub fn restore(&mut self, view: &mut View) {
909 pub fn restore(&mut self, view: &mut View) {
913 if let Some(revert) = self.savepoint.take() {
910 if let Some(revert) = self.savepoint.take() {
914− apply_transaction(&revert, self, view);
911+ self.apply(&revert, view.id);
915 }
912 }
916 }
913 }
917
914
helix-view/src/editor.rs+1−1
@@ -1502,6 +1502,6 @@ fn try_restore_indent(doc: &mut Document, view: &mut View) {
1502 let line_start_pos = text.line_to_char(range.cursor_line(text));
1502 let line_start_pos = text.line_to_char(range.cursor_line(text));
1503 (line_start_pos, pos, None)
1503 (line_start_pos, pos, None)
1504 });
1504 });
1505− crate::apply_transaction(&transaction, doc, view);
1505+ doc.apply(&transaction, view.id);
1506 }
1506 }
1507}
1507}
helix-view/src/lib.rs−11
@@ -66,17 +66,6 @@ pub fn align_view(doc: &Document, view: &mut View, align: Align) {
66 view.offset.row = line.saturating_sub(relative);
66 view.offset.row = line.saturating_sub(relative);
67}
67}
68
68
69−/// Applies a [`helix_core::Transaction`] to the given [`Document`]
70−/// and [`View`].
71−pub fn apply_transaction(
72− transaction: &helix_core::Transaction,
73− doc: &mut Document,
74− view: &View,
75−) -> bool {
76− // TODO remove this helper function. Just call Document::apply everywhere directly.
77− doc.apply(transaction, view.id)
78−}
79−
80pub use document::Document;
69pub use document::Document;
81pub use editor::Editor;
70pub use editor::Editor;
82pub use theme::Theme;
71pub use theme::Theme;
helix-view/src/view.rs−2
@@ -380,8 +380,6 @@ impl View {
380 // }
380 // }
381
381
382 /// Applies a [`Transaction`] to the view.
382 /// Applies a [`Transaction`] to the view.
383− /// Instead of calling this function directly, use [crate::apply_transaction]
384− /// which applies a transaction to the [`Document`] and view together.
385 pub fn apply(&mut self, transaction: &Transaction, doc: &mut Document) {
383 pub fn apply(&mut self, transaction: &Transaction, doc: &mut Document) {
386 self.jumps.apply(transaction, doc);
384 self.jumps.apply(transaction, doc);
387 self.doc_revisions
385 self.doc_revisions