|
|
|
@ -1,12 +1,15 @@
|
|
|
|
|
use crate::{
|
|
|
|
|
compositor::{Callback, Component, Context, EventResult},
|
|
|
|
|
compositor::{Callback, Component, Context, EventResult, RenderContext},
|
|
|
|
|
ctrl, key,
|
|
|
|
|
};
|
|
|
|
|
use crossterm::event::Event;
|
|
|
|
|
use tui::buffer::Buffer as Surface;
|
|
|
|
|
|
|
|
|
|
use helix_core::Position;
|
|
|
|
|
use helix_view::graphics::{Margin, Rect};
|
|
|
|
|
use helix_view::{
|
|
|
|
|
graphics::{Margin, Rect},
|
|
|
|
|
Editor,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO: share logic with Menu, it's essentially Popup(render_fn), but render fn needs to return
|
|
|
|
|
// a width/height hint. maybe Popup(Box<Component>)
|
|
|
|
@ -53,10 +56,10 @@ impl<T: Component> Popup<T> {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_rel_position(&mut self, viewport: Rect, cx: &Context) -> (u16, u16) {
|
|
|
|
|
pub fn get_rel_position(&mut self, viewport: Rect, editor: &Editor) -> (u16, u16) {
|
|
|
|
|
let position = self
|
|
|
|
|
.position
|
|
|
|
|
.get_or_insert_with(|| cx.editor.cursor().0.unwrap_or_default());
|
|
|
|
|
.get_or_insert_with(|| editor.cursor().0.unwrap_or_default());
|
|
|
|
|
|
|
|
|
|
let (width, height) = self.size;
|
|
|
|
|
|
|
|
|
@ -176,13 +179,13 @@ impl<T: Component> Component for Popup<T> {
|
|
|
|
|
Some(self.size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) {
|
|
|
|
|
fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut RenderContext<'_>) {
|
|
|
|
|
// trigger required_size so we recalculate if the child changed
|
|
|
|
|
self.required_size((viewport.width, viewport.height));
|
|
|
|
|
|
|
|
|
|
cx.scroll = Some(self.scroll);
|
|
|
|
|
|
|
|
|
|
let (rel_x, rel_y) = self.get_rel_position(viewport, cx);
|
|
|
|
|
let (rel_x, rel_y) = self.get_rel_position(viewport, cx.editor);
|
|
|
|
|
|
|
|
|
|
// clip to viewport
|
|
|
|
|
let area = viewport.intersection(Rect::new(rel_x, rel_y, self.size.0, self.size.1));
|
|
|
|
|