Skip to content

Commit a7f41ac

Browse files
committed
Fix :w in insert mode
1 parent 16ccc7e commit a7f41ac

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

helix-view/src/document.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ impl Document {
468468

469469
let language_server = self.language_server.clone();
470470

471+
// ensure changes are commited
472+
self.commit_pending_changes(None);
471473
// mark changes up to now as saved
472474
self.reset_modified();
473475

@@ -831,6 +833,10 @@ impl Document {
831833

832834
/// Commit pending changes to history
833835
pub fn append_changes_to_history(&mut self, view_id: ViewId) {
836+
self.commit_pending_changes(Some(view_id))
837+
}
838+
839+
fn commit_pending_changes(&mut self, view_id: Option<ViewId>) {
834840
if self.changes.is_empty() {
835841
return;
836842
}
@@ -839,8 +845,10 @@ impl Document {
839845
let changes = std::mem::replace(&mut self.changes, new_changeset);
840846
// Instead of doing this messy merge we could always commit, and based on transaction
841847
// annotations either add a new layer or compose into the previous one.
842-
let transaction =
843-
Transaction::from(changes).with_selection(self.selection(view_id).clone());
848+
let mut transaction = Transaction::from(changes);
849+
if let Some(view_id) = view_id {
850+
transaction = transaction.with_selection(self.selection(view_id).clone());
851+
}
844852

845853
// HAXX: we need to reconstruct the state as it was before the changes..
846854
let old_state = self.old_state.take().expect("no old_state available");

0 commit comments

Comments
 (0)