@@ -3,7 +3,9 @@ use crate::{
33 gutter::{self, Gutter},
44 Document, DocumentId, ViewId,
55};
6−use helix_core::{pos_at_visual_coords, visual_coords_at_pos, Position, RopeSlice, Selection};
6+use helix_core::{
7+ pos_at_visual_coords, visual_coords_at_pos, Position, RopeSlice, Selection, Transaction,
8+};
79
810use std::fmt;
911
@@ -62,6 +64,22 @@ impl JumpList {
6264 pub fn get(&self) -> &[Jump] {
6365 &self.jumps
6466 }
67+
68+ /// Applies a [`Transaction`] of changes to the jumplist.
69+ /// This is necessary to ensure that changes to documents do not leave jump-list
70+ /// selections pointing to parts of the text which no longer exist.
71+ fn apply(&mut self, transaction: &Transaction, doc: &Document) {
72+ let text = doc.text().slice(..);
73+
74+ for (doc_id, selection) in &mut self.jumps {
75+ if doc.id() == *doc_id {
76+ *selection = selection
77+ .clone()
78+ .map(transaction.changes())
79+ .ensure_invariants(text);
80+ }
81+ }
82+ }
6583}
6684
6785#[derive(Clone)]
@@ -334,6 +352,14 @@ impl View {
334352 // (None, None) => return,
335353 // }
336354 // }
355+
356+ /// Applies a [`Transaction`] to the view.
357+ /// Instead of calling this function directly, use [crate::apply_transaction]
358+ /// which applies a transaction to the [`Document`] and view together.
359+ pub fn apply(&mut self, transaction: &Transaction, doc: &Document) -> bool {
360+ self.jumps.apply(transaction, doc);
361+ true
362+ }
337363}
338364
339365#[cfg(test)]