diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 46218e0d13a90..c1f00295c0129 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1142,7 +1142,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() { @@ -1209,6 +1210,12 @@ impl Component for EditorView { let (view, doc) = current!(cx.editor); view.ensure_cursor_in_view(doc, config.scrolloff); + // The focused view has changed. Consume the event and do not execute mode + // transition hooks. + if view.id != focus { + return EventResult::Consumed(None); + } + // Store a history state if not in insert mode. This also takes care of // committing changes when leaving insert mode. if doc.mode() != Mode::Insert {