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.
pull/2634/head
Michael Davis 2 years ago committed by GitHub
parent 16525349db
commit 9e24f2aa81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1157,7 +1157,8 @@ impl Component for EditorView {
// clear status // clear status
cx.editor.status_msg = None; cx.editor.status_msg = None;
let doc = doc!(cx.editor); let (view, doc) = current!(cx.editor);
let focus = view.id;
let mode = doc.mode(); let mode = doc.mode();
if let Some(on_next_key) = self.on_next_key.take() { if let Some(on_next_key) = self.on_next_key.take() {
@ -1221,7 +1222,9 @@ impl Component for EditorView {
return EventResult::Ignored(None); return EventResult::Ignored(None);
} }
let config = cx.editor.config(); 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); view.ensure_cursor_in_view(doc, config.scrolloff);
// Store a history state if not in insert mode. This also takes care of // Store a history state if not in insert mode. This also takes care of

Loading…
Cancel
Save