diff options
author | Blaž Hrastnik | 2022-03-22 03:53:44 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-03-28 02:01:59 +0000 |
commit | 9a6ee88e66d29f7158150bab2045e3a5d3ba3ea7 (patch) | |
tree | 6b3ebcc636dc86f5d3edbfed055828b29787adb2 /helix-view/src/lib.rs | |
parent | 85264a861aeda7a002dda548403258620e914b57 (diff) |
Split off dap event handlers into helix-view to allow reuse
Diffstat (limited to 'helix-view/src/lib.rs')
-rw-r--r-- | helix-view/src/lib.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs index e0964e1c..788304bc 100644 --- a/helix-view/src/lib.rs +++ b/helix-view/src/lib.rs @@ -6,6 +6,10 @@ pub mod document; pub mod editor; pub mod graphics; pub mod gutter; +pub mod handlers { + pub mod dap; + pub mod lsp; +} pub mod info; pub mod input; pub mod keyboard; @@ -36,6 +40,30 @@ slotmap::new_key_type! { pub struct ViewId; } +pub enum Align { + Top, + Center, + Bottom, +} + +pub fn align_view(doc: &Document, view: &mut View, align: Align) { + let pos = doc + .selection(view.id) + .primary() + .cursor(doc.text().slice(..)); + let line = doc.text().char_to_line(pos); + + let height = view.inner_area().height as usize; + + let relative = match align { + Align::Center => height / 2, + Align::Top => 0, + Align::Bottom => height, + }; + + view.offset.row = line.saturating_sub(relative); +} + pub use document::Document; pub use editor::Editor; pub use theme::Theme; |