diff options
Diffstat (limited to 'helix-term/src/compositor.rs')
-rw-r--r-- | helix-term/src/compositor.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 1d94ee63..2e65f02a 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -14,6 +14,7 @@ // cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>) use crossterm::event::Event; +use helix_core::Position; use smol::Executor; use tui::buffer::Buffer as Surface; use tui::layout::Rect; @@ -52,6 +53,10 @@ pub trait Component { } fn render(&self, area: Rect, frame: &mut Surface, ctx: &mut Context); + + fn cursor_position(&self, area: Rect, ctx: &mut Context) -> Option<Position> { + None + } } // struct Editor { }; @@ -138,4 +143,13 @@ impl Compositor { layer.render(area, surface, cx) } } + + pub fn cursor_position(&self, area: Rect, cx: &mut Context) -> Position { + for layer in self.layers.iter().rev() { + if let Some(pos) = layer.cursor_position(area, cx) { + return pos; + } + } + panic!("No layer returned a position!"); + } } |