From 9cc0f82e62c68f15c89273fb6cec60bf87809461 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sun, 31 Mar 2024 01:41:08 +0530 Subject: [PATCH] Extract popup close callback into separate function --- helix-term/src/ui/popup.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 4f379b4a1..abc3e6c32 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -213,6 +213,13 @@ impl Popup { _ => EventResult::Ignored(None), } } + + fn close_cb(&self) -> Callback { + Box::new(|compositor, _| { + // remove the layer + compositor.remove(self.id.as_ref()); + }) + } } impl Component for Popup { @@ -231,16 +238,11 @@ impl Component for Popup { return EventResult::Ignored(None); } - let close_fn: Callback = Box::new(|compositor, _| { - // remove the layer - compositor.remove(self.id.as_ref()); - }); - match key { // esc or ctrl-c aborts the completion and closes the menu key!(Esc) | ctrl!('c') => { let _ = self.contents.handle_event(event, cx); - EventResult::Consumed(Some(close_fn)) + EventResult::Consumed(Some(self.close_cb())) } ctrl!('d') => { self.scroll_half_page_down(); @@ -255,7 +257,7 @@ impl Component for Popup { if self.auto_close { if let EventResult::Ignored(None) = contents_event_result { - return EventResult::Ignored(Some(close_fn)); + return EventResult::Ignored(Some(self.close_cb())); } }