on master help sign in
Call View::apply within Document::append_changes_to_history
commit9a9e462183cb60bff6450f17173e6b18eadbbfb2 authorMichael Davis <mcarsondavis@gmail.com> dateSun 27 Nov 2022, 12:47 (4 years ago) parent2709ce3
5 files changed+19−15
helix-term/src/commands.rs+4−4 helix-term/src/commands/lsp.rs+3−2 helix-term/src/commands/typed.rs+4−4 helix-term/src/ui/editor.rs+2−2 helix-view/src/document.rs+6−3
helix-term/src/commands.rs+4−4
@@ -2564,7 +2564,7 @@ async fn make_format_callback(
25642564 if let Ok(format) = format {
25652565 if doc.version() == doc_version {
25662566 apply_transaction(&format, doc, view);
2567− doc.append_changes_to_history(view.id);
2567+ doc.append_changes_to_history(view);
25682568 doc.detect_indent_and_line_ending();
25692569 view.ensure_cursor_in_view(doc, scrolloff);
25702570 } else {
@@ -3365,7 +3365,7 @@ fn later(cx: &mut Context) {
33653365
33663366fn commit_undo_checkpoint(cx: &mut Context) {
33673367 let (view, doc) = current!(cx.editor);
3368− doc.append_changes_to_history(view.id);
3368+ doc.append_changes_to_history(view);
33693369}
33703370
33713371// Yank / Paste
@@ -3677,7 +3677,7 @@ fn replace_selections_with_clipboard_impl(
36773677 });
36783678
36793679 apply_transaction(&transaction, doc, view);
3680− doc.append_changes_to_history(view.id);
3680+ doc.append_changes_to_history(view);
36813681 }
36823682 Err(e) => return Err(e.context("Couldn't get system clipboard contents")),
36833683 }
@@ -4884,7 +4884,7 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
48844884 let transaction = Transaction::change(doc.text(), changes.into_iter())
48854885 .with_selection(Selection::new(ranges, selection.primary_index()));
48864886 apply_transaction(&transaction, doc, view);
4887− doc.append_changes_to_history(view.id);
4887+ doc.append_changes_to_history(view);
48884888 }
48894889
48904890 // after replace cursor may be out of bounds, do this to
helix-term/src/commands/lsp.rs+3−2
@@ -760,8 +760,9 @@ pub fn apply_workspace_edit(
760760 text_edits,
761761 offset_encoding,
762762 );
763− apply_transaction(&transaction, doc, view_mut!(editor, view_id));
764− doc.append_changes_to_history(view_id);
763+ let view = view_mut!(editor, view_id);
764+ apply_transaction(&transaction, doc, view);
765+ doc.append_changes_to_history(view);
765766 };
766767
767768 if let Some(ref changes) = workspace_edit.changes {
helix-term/src/commands/typed.rs+4−4
@@ -464,7 +464,7 @@ fn set_line_ending(
464464 }),
465465 );
466466 apply_transaction(&transaction, doc, view);
467− doc.append_changes_to_history(view.id);
467+ doc.append_changes_to_history(view);
468468
469469 Ok(())
470470}
@@ -909,7 +909,7 @@ fn replace_selections_with_clipboard_impl(
909909 });
910910
911911 apply_transaction(&transaction, doc, view);
912− doc.append_changes_to_history(view.id);
912+ doc.append_changes_to_history(view);
913913 Ok(())
914914 }
915915 Err(e) => Err(e.context("Couldn't get system clipboard contents")),
@@ -1573,7 +1573,7 @@ fn sort_impl(
15731573 );
15741574
15751575 apply_transaction(&transaction, doc, view);
1576− doc.append_changes_to_history(view.id);
1576+ doc.append_changes_to_history(view);
15771577
15781578 Ok(())
15791579}
@@ -1617,7 +1617,7 @@ fn reflow(
16171617 });
16181618
16191619 apply_transaction(&transaction, doc, view);
1620− doc.append_changes_to_history(view.id);
1620+ doc.append_changes_to_history(view);
16211621 view.ensure_cursor_in_view(doc, scrolloff);
16221622
16231623 Ok(())
helix-term/src/ui/editor.rs+2−2
@@ -1319,7 +1319,7 @@ impl Component for EditorView {
13191319 // Store a history state if not in insert mode. Otherwise wait till we exit insert
13201320 // to include any edits to the paste in the history state.
13211321 if mode != Mode::Insert {
1322− doc.append_changes_to_history(view.id);
1322+ doc.append_changes_to_history(view);
13231323 }
13241324
13251325 EventResult::Consumed(None)
@@ -1418,7 +1418,7 @@ impl Component for EditorView {
14181418 // Store a history state if not in insert mode. This also takes care of
14191419 // committing changes when leaving insert mode.
14201420 if mode != Mode::Insert {
1421− doc.append_changes_to_history(view.id);
1421+ doc.append_changes_to_history(view);
14221422 }
14231423 }
14241424
helix-view/src/document.rs+6−3
@@ -641,7 +641,7 @@ impl Document {
641641 // of the encoding.
642642 let transaction = helix_core::diff::compare_ropes(self.text(), &rope);
643643 apply_transaction(&transaction, self, view);
644− self.append_changes_to_history(view.id);
644+ self.append_changes_to_history(view);
645645 self.reset_modified();
646646
647647 self.detect_indent_and_line_ending();
@@ -928,7 +928,7 @@ impl Document {
928928 }
929929
930930 /// Commit pending changes to history
931− pub fn append_changes_to_history(&mut self, view_id: ViewId) {
931+ pub fn append_changes_to_history(&mut self, view: &mut View) {
932932 if self.changes.is_empty() {
933933 return;
934934 }
@@ -938,7 +938,7 @@ impl Document {
938938 // Instead of doing this messy merge we could always commit, and based on transaction
939939 // annotations either add a new layer or compose into the previous one.
940940 let transaction =
941− Transaction::from(changes).with_selection(self.selection(view_id).clone());
941+ Transaction::from(changes).with_selection(self.selection(view.id).clone());
942942
943943 // HAXX: we need to reconstruct the state as it was before the changes..
944944 let old_state = self.old_state.take().expect("no old_state available");
@@ -946,6 +946,9 @@ impl Document {
946946 let mut history = self.history.take();
947947 history.commit_revision(&transaction, &old_state);
948948 self.history.set(history);
949+
950+ // Update jumplist entries in the view.
951+ view.apply(&transaction, self);
949952 }
950953
951954 pub fn id(&self) -> DocumentId {