Skip to content

Commit

Permalink
fix: end undo groups, enter tree mode after undoing
Browse files Browse the repository at this point in the history
  • Loading branch information
e-matteson committed Apr 22, 2024
1 parent 6e40ace commit f1f1a47
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/engine/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ impl UndoGroup {
}

jump_to(s, cursor, self.restore_loc);
// Always end in tree mode, so that undoing can't unexpectedly enter text mode.
if let Some(new_cursor) = cursor.exit_text() {
*cursor = new_cursor;
}
UndoGroup::new(redo_restore_loc.bug(), redos)
}

Expand Down
4 changes: 4 additions & 0 deletions src/keymap/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ impl LayerManager {
}
}

pub fn has_open_menu(&self) -> bool {
self.active_menu.is_some()
}

/*********
* Input *
*********/
Expand Down
9 changes: 8 additions & 1 deletion src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,14 @@ impl<F: Frontend<Style = Style> + 'static> Runtime<F> {
};
match self.layers.lookup_key(mode, doc_name, key) {
None => Ok(None),
Some(KeyLookupResult::KeyProg(key_prog)) => Ok(Some(key_prog)),
Some(KeyLookupResult::KeyProg(key_prog)) => {
// Each keypress in tree mode should be a separate undo group, but multiple text
// edits (and multiple edits made in a menu) should be grouped together.
if mode != Mode::Text && !self.layers.has_open_menu() {
let _ = self.engine.end_undo_group();
}
Ok(Some(key_prog))
}
Some(KeyLookupResult::Redisplay) => {
self.display()?;
Ok(None)
Expand Down

0 comments on commit f1f1a47

Please sign in to comment.