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 31301e7 commit eb34c97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5177,7 +5177,7 @@ fn hover(cx: &mut Context) {
// skip if contents empty

let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
let popup = Popup::new("documentation", contents);
let popup = Popup::new("documentation", contents).auto_close(true);
if let Some(doc_popup) = compositor.find_id("documentation") {
*doc_popup = popup;
} else {
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 @@ -17,6 +17,7 @@ pub struct Popup<T: Component> {
size: (u16, u16),
child_size: (u16, u16),
scroll: usize,
auto_close: bool,
id: &'static str,
}

Expand All @@ -28,6 +29,7 @@ impl<T: Component> Popup<T> {
size: (0, 0),
child_size: (0, 0),
scroll: 0,
auto_close: false,
id,
}
}
Expand All @@ -36,6 +38,11 @@ impl<T: Component> Popup<T> {
self.position = pos;
}

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 @@ -119,11 +126,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 eb34c97

Please sign in to comment.