Skip to content

Commit

Permalink
make auto_close configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram Hoendervangers committed Feb 22, 2022
1 parent efd52f9 commit 428dabd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,7 @@ pub mod cmd {
let call: job::Callback =
Box::new(move |editor: &mut Editor, compositor: &mut Compositor| {
let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
let popup = Popup::new("hover", contents);
let popup = Popup::new("hover", contents).auto_close(true);
compositor.replace_or_push("hover", Box::new(popup));
});
Ok(call)
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ pub fn hover(cx: &mut Context) {
// skip if contents empty

let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
let popup = Popup::new("hover", contents);
let popup = Popup::new("hover", contents).auto_close(true);
compositor.replace_or_push("hover", Box::new(popup));
}
},
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ impl EditorView {
}
}

EventResult::Ignored
EventResult::Ignored(None)
}

MouseEvent {
Expand Down
17 changes: 13 additions & 4 deletions helix-term/src/ui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Popup<T: Component> {
size: (u16, u16),
child_size: (u16, u16),
scroll: usize,
auto_close: bool,
id: &'static str,
}

Expand All @@ -33,6 +34,7 @@ impl<T: Component> Popup<T> {
size: (0, 0),
child_size: (0, 0),
scroll: 0,
auto_close: false,
id,
}
}
Expand All @@ -46,6 +48,11 @@ impl<T: Component> Popup<T> {
self
}

pub fn auto_close(mut self, auto_close: bool) -> Self {
self.auto_close = auto_close;
self
}

pub fn get_rel_position(&mut self, viewport: Rect, cx: &Context) -> (u16, u16) {
let position = self
.position
Expand Down Expand Up @@ -129,11 +136,13 @@ impl<T: Component> Component for Popup<T> {
_ => {
let contents_event_result = self.contents.handle_event(event, cx);

if let EventResult::Ignored(None) = contents_event_result {
EventResult::Ignored(Some(close_fn))
} else {
contents_event_result
if self.auto_close {
if let EventResult::Ignored(None) = contents_event_result {
return EventResult::Ignored(Some(close_fn));
}
}

contents_event_result
}
}
// for some events, we want to process them but send ignore, specifically all input except
Expand Down

0 comments on commit 428dabd

Please sign in to comment.