on master help sign in
Use the original document and view for mode transition hooks (#3508)

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.

commit9e24f2aa81f6bbb1fecbf6c7a14a56742389444f authorMichael Davis <mcarsondavis@gmail.com> dateTue 30 Aug 2022, 20:34 (4 years ago) parent1652534
1 file changed+5−2
helix-term/src/ui/editor.rs+5−2
helix-term/src/ui/editor.rs+5−2
@@ -1157,7 +1157,8 @@ impl Component for EditorView {
11571157 // clear status
11581158 cx.editor.status_msg = None;
11591159
1160− let doc = doc!(cx.editor);
1160+ let (view, doc) = current!(cx.editor);
1161+ let focus = view.id;
11611162 let mode = doc.mode();
11621163
11631164 if let Some(on_next_key) = self.on_next_key.take() {
@@ -1221,7 +1222,9 @@ impl Component for EditorView {
12211222 return EventResult::Ignored(None);
12221223 }
12231224 let config = cx.editor.config();
1224− let (view, doc) = current!(cx.editor);
1225+ let view = cx.editor.tree.get_mut(focus);
1226+ let doc = cx.editor.documents.get_mut(&view.doc).unwrap();
1227+
12251228 view.ensure_cursor_in_view(doc, config.scrolloff);
12261229
12271230 // Store a history state if not in insert mode. This also takes care of