Call View::apply within Document::append_changes_to_history
This commit is contained in:
parent
2709ce3332
commit
9a9e462183
5 changed files with 19 additions and 15 deletions
|
@ -2564,7 +2564,7 @@ async fn make_format_callback(
|
|||
if let Ok(format) = format {
|
||||
if doc.version() == doc_version {
|
||||
apply_transaction(&format, doc, view);
|
||||
doc.append_changes_to_history(view.id);
|
||||
doc.append_changes_to_history(view);
|
||||
doc.detect_indent_and_line_ending();
|
||||
view.ensure_cursor_in_view(doc, scrolloff);
|
||||
} else {
|
||||
|
@ -3365,7 +3365,7 @@ fn later(cx: &mut Context) {
|
|||
|
||||
fn commit_undo_checkpoint(cx: &mut Context) {
|
||||
let (view, doc) = current!(cx.editor);
|
||||
doc.append_changes_to_history(view.id);
|
||||
doc.append_changes_to_history(view);
|
||||
}
|
||||
|
||||
// Yank / Paste
|
||||
|
@ -3677,7 +3677,7 @@ fn replace_selections_with_clipboard_impl(
|
|||
});
|
||||
|
||||
apply_transaction(&transaction, doc, view);
|
||||
doc.append_changes_to_history(view.id);
|
||||
doc.append_changes_to_history(view);
|
||||
}
|
||||
Err(e) => return Err(e.context("Couldn't get system clipboard contents")),
|
||||
}
|
||||
|
@ -4884,7 +4884,7 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
|
|||
let transaction = Transaction::change(doc.text(), changes.into_iter())
|
||||
.with_selection(Selection::new(ranges, selection.primary_index()));
|
||||
apply_transaction(&transaction, doc, view);
|
||||
doc.append_changes_to_history(view.id);
|
||||
doc.append_changes_to_history(view);
|
||||
}
|
||||
|
||||
// after replace cursor may be out of bounds, do this to
|
||||
|
|
|
@ -760,8 +760,9 @@ pub fn apply_workspace_edit(
|
|||
text_edits,
|
||||
offset_encoding,
|
||||
);
|
||||
apply_transaction(&transaction, doc, view_mut!(editor, view_id));
|
||||
doc.append_changes_to_history(view_id);
|
||||
let view = view_mut!(editor, view_id);
|
||||
apply_transaction(&transaction, doc, view);
|
||||
doc.append_changes_to_history(view);
|
||||
};
|
||||
|
||||
if let Some(ref changes) = workspace_edit.changes {
|
||||
|
|
|
@ -464,7 +464,7 @@ fn set_line_ending(
|
|||
}),
|
||||
);
|
||||
apply_transaction(&transaction, doc, view);
|
||||
doc.append_changes_to_history(view.id);
|
||||
doc.append_changes_to_history(view);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -909,7 +909,7 @@ fn replace_selections_with_clipboard_impl(
|
|||
});
|
||||
|
||||
apply_transaction(&transaction, doc, view);
|
||||
doc.append_changes_to_history(view.id);
|
||||
doc.append_changes_to_history(view);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => Err(e.context("Couldn't get system clipboard contents")),
|
||||
|
@ -1573,7 +1573,7 @@ fn sort_impl(
|
|||
);
|
||||
|
||||
apply_transaction(&transaction, doc, view);
|
||||
doc.append_changes_to_history(view.id);
|
||||
doc.append_changes_to_history(view);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1617,7 +1617,7 @@ fn reflow(
|
|||
});
|
||||
|
||||
apply_transaction(&transaction, doc, view);
|
||||
doc.append_changes_to_history(view.id);
|
||||
doc.append_changes_to_history(view);
|
||||
view.ensure_cursor_in_view(doc, scrolloff);
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1319,7 +1319,7 @@ impl Component for EditorView {
|
|||
// Store a history state if not in insert mode. Otherwise wait till we exit insert
|
||||
// to include any edits to the paste in the history state.
|
||||
if mode != Mode::Insert {
|
||||
doc.append_changes_to_history(view.id);
|
||||
doc.append_changes_to_history(view);
|
||||
}
|
||||
|
||||
EventResult::Consumed(None)
|
||||
|
@ -1418,7 +1418,7 @@ impl Component for EditorView {
|
|||
// Store a history state if not in insert mode. This also takes care of
|
||||
// committing changes when leaving insert mode.
|
||||
if mode != Mode::Insert {
|
||||
doc.append_changes_to_history(view.id);
|
||||
doc.append_changes_to_history(view);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -641,7 +641,7 @@ impl Document {
|
|||
// of the encoding.
|
||||
let transaction = helix_core::diff::compare_ropes(self.text(), &rope);
|
||||
apply_transaction(&transaction, self, view);
|
||||
self.append_changes_to_history(view.id);
|
||||
self.append_changes_to_history(view);
|
||||
self.reset_modified();
|
||||
|
||||
self.detect_indent_and_line_ending();
|
||||
|
@ -928,7 +928,7 @@ impl Document {
|
|||
}
|
||||
|
||||
/// Commit pending changes to history
|
||||
pub fn append_changes_to_history(&mut self, view_id: ViewId) {
|
||||
pub fn append_changes_to_history(&mut self, view: &mut View) {
|
||||
if self.changes.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
@ -938,7 +938,7 @@ impl Document {
|
|||
// Instead of doing this messy merge we could always commit, and based on transaction
|
||||
// annotations either add a new layer or compose into the previous one.
|
||||
let transaction =
|
||||
Transaction::from(changes).with_selection(self.selection(view_id).clone());
|
||||
Transaction::from(changes).with_selection(self.selection(view.id).clone());
|
||||
|
||||
// HAXX: we need to reconstruct the state as it was before the changes..
|
||||
let old_state = self.old_state.take().expect("no old_state available");
|
||||
|
@ -946,6 +946,9 @@ impl Document {
|
|||
let mut history = self.history.take();
|
||||
history.commit_revision(&transaction, &old_state);
|
||||
self.history.set(history);
|
||||
|
||||
// Update jumplist entries in the view.
|
||||
view.apply(&transaction, self);
|
||||
}
|
||||
|
||||
pub fn id(&self) -> DocumentId {
|
||||
|
|
Loading…
Add table
Reference in a new issue