From 45dbcb67832e31ca5eea936628f34f5dc26c4381 Mon Sep 17 00:00:00 2001 From: A-Walrus Date: Thu, 1 Sep 2022 19:59:39 +0300 Subject: Fix closing buffer with custom keymap (#3633) * Fix closing buffer with custom keymap * Add comment explaining if--- helix-term/src/ui/editor.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 539e164c..fa437a7e 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1263,17 +1263,20 @@ impl Component for EditorView { if cx.editor.should_close() { return EventResult::Ignored(None); } - let config = cx.editor.config(); - let mode = cx.editor.mode(); - 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 - // committing changes when leaving insert mode. - if mode != Mode::Insert { - doc.append_changes_to_history(view.id); + // if the focused view still exists and wasn't closed + if cx.editor.tree.contains(focus) { + let config = cx.editor.config(); + let mode = cx.editor.mode(); + 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 + // committing changes when leaving insert mode. + if mode != Mode::Insert { + doc.append_changes_to_history(view.id); + } } EventResult::Consumed(callback) -- cgit v1.2.3-70-g09d2