|
|
@ -19,6 +19,7 @@ pub struct Popup {
|
|
|
|
contents: Box<dyn Component>,
|
|
|
|
contents: Box<dyn Component>,
|
|
|
|
position: Option<Position>,
|
|
|
|
position: Option<Position>,
|
|
|
|
size: (u16, u16),
|
|
|
|
size: (u16, u16),
|
|
|
|
|
|
|
|
scroll: usize,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Popup {
|
|
|
|
impl Popup {
|
|
|
@ -29,12 +30,21 @@ impl Popup {
|
|
|
|
contents,
|
|
|
|
contents,
|
|
|
|
position: None,
|
|
|
|
position: None,
|
|
|
|
size: (0, 0),
|
|
|
|
size: (0, 0),
|
|
|
|
|
|
|
|
scroll: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn set_position(&mut self, pos: Option<Position>) {
|
|
|
|
pub fn set_position(&mut self, pos: Option<Position>) {
|
|
|
|
self.position = pos;
|
|
|
|
self.position = pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn scroll(&mut self, offset: usize, direction: bool) {
|
|
|
|
|
|
|
|
if direction {
|
|
|
|
|
|
|
|
self.scroll += offset;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
self.scroll = self.scroll.saturating_sub(offset);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Component for Popup {
|
|
|
|
impl Component for Popup {
|
|
|
@ -64,6 +74,21 @@ impl Component for Popup {
|
|
|
|
code: KeyCode::Char('c'),
|
|
|
|
code: KeyCode::Char('c'),
|
|
|
|
modifiers: KeyModifiers::CONTROL,
|
|
|
|
modifiers: KeyModifiers::CONTROL,
|
|
|
|
} => close_fn,
|
|
|
|
} => close_fn,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KeyEvent {
|
|
|
|
|
|
|
|
code: KeyCode::Char('d'),
|
|
|
|
|
|
|
|
modifiers: KeyModifiers::CONTROL,
|
|
|
|
|
|
|
|
} => {
|
|
|
|
|
|
|
|
self.scroll(self.size.1 as usize / 2, true);
|
|
|
|
|
|
|
|
return EventResult::Consumed(None);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyEvent {
|
|
|
|
|
|
|
|
code: KeyCode::Char('u'),
|
|
|
|
|
|
|
|
modifiers: KeyModifiers::CONTROL,
|
|
|
|
|
|
|
|
} => {
|
|
|
|
|
|
|
|
self.scroll(self.size.1 as usize / 2, false);
|
|
|
|
|
|
|
|
return EventResult::Consumed(None);
|
|
|
|
|
|
|
|
}
|
|
|
|
_ => self.contents.handle_event(event, cx),
|
|
|
|
_ => self.contents.handle_event(event, cx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// for some events, we want to process them but send ignore, specifically all input except
|
|
|
|
// for some events, we want to process them but send ignore, specifically all input except
|
|
|
@ -85,6 +110,8 @@ impl Component for Popup {
|
|
|
|
use tui::text::Text;
|
|
|
|
use tui::text::Text;
|
|
|
|
use tui::widgets::{Paragraph, Widget, Wrap};
|
|
|
|
use tui::widgets::{Paragraph, Widget, Wrap};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cx.scroll = Some(self.scroll);
|
|
|
|
|
|
|
|
|
|
|
|
let position = self
|
|
|
|
let position = self
|
|
|
|
.position
|
|
|
|
.position
|
|
|
|
.or_else(|| cx.editor.cursor_position())
|
|
|
|
.or_else(|| cx.editor.cursor_position())
|
|
|
|