Skip to content

Commit

Permalink
Use the original document and view for mode transition hooks
Browse files Browse the repository at this point in the history
When changing focus, the lookup with `current!` may change the
view and end up executing mode transition hooks on the newly
focused view. We should use the same view and document to execute
mode transition hooks so that switching away from a view triggers
history save points.
  • Loading branch information
the-mikedavis committed Aug 23, 2022
1 parent e4c9d40 commit b963657
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,8 @@ impl Component for EditorView {
// clear status
cx.editor.status_msg = None;

let doc = doc!(cx.editor);
let (view, doc) = current!(cx.editor);
let focus = view.id;
let mode = doc.mode();

if let Some(on_next_key) = self.on_next_key.take() {
Expand Down Expand Up @@ -1204,7 +1205,9 @@ impl Component for EditorView {
return EventResult::Ignored(None);
}
let config = cx.editor.config();
let (view, doc) = current!(cx.editor);
let view = cx.editor.tree.get_mut(focus);
let doc = cx.editor.documents.get_mut(&view.doc).unwrap();

view.ensure_cursor_in_view(doc, config.scrolloff);

// Store a history state if not in insert mode. This also takes care of
Expand Down

0 comments on commit b963657

Please sign in to comment.