Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/lib.rs')
-rw-r--r--helix-view/src/lib.rs64
1 files changed, 39 insertions, 25 deletions
diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs
index a7e9f461..5ba31853 100644
--- a/helix-view/src/lib.rs
+++ b/helix-view/src/lib.rs
@@ -1,19 +1,30 @@
#[macro_use]
pub mod macros;
-pub mod annotations;
+pub mod args;
+pub mod backend {
+ #[cfg(feature = "term")]
+ pub mod term;
+}
pub mod clipboard;
+pub mod commands;
+pub mod compositor;
pub mod document;
pub mod editor;
-pub mod events;
-pub mod expansion;
-pub mod graphics;
+pub mod ui;
+pub use helix_graphics as graphics;
pub mod gutter;
-pub mod handlers;
+pub mod job;
+pub mod keymap;
+pub use keymap::macros::*;
+pub mod handlers {
+ #[cfg(feature = "dap")]
+ pub mod dap;
+ pub mod lsp;
+}
pub mod info;
pub mod input;
pub mod keyboard;
-pub mod register;
pub mod theme;
pub mod tree;
pub mod view;
@@ -41,39 +52,42 @@ slotmap::new_key_type! {
pub struct ViewId;
}
+#[cfg(not(windows))]
+pub fn true_color() -> bool {
+ std::env::var("COLORTERM")
+ .map(|v| matches!(v.as_str(), "truecolor" | "24bit"))
+ .unwrap_or(false)
+}
+#[cfg(windows)]
+pub fn true_color() -> bool {
+ true
+}
+
pub enum Align {
Top,
Center,
Bottom,
}
-pub fn align_view(doc: &mut Document, view: &View, align: Align) {
- let doc_text = doc.text().slice(..);
- let cursor = doc.selection(view.id).primary().cursor(doc_text);
- let viewport = view.inner_area(doc);
- let last_line_height = viewport.height.saturating_sub(1);
- let mut view_offset = doc.view_offset(view.id);
+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 => last_line_height / 2,
+ Align::Center => height / 2,
Align::Top => 0,
- Align::Bottom => last_line_height,
+ Align::Bottom => height,
};
- let text_fmt = doc.text_format(viewport.width, None);
- (view_offset.anchor, view_offset.vertical_offset) = char_idx_at_visual_offset(
- doc_text,
- cursor,
- -(relative as isize),
- 0,
- &text_fmt,
- &view.text_annotations(doc, None),
- );
- doc.set_view_offset(view.id, view_offset);
+ view.offset.row = line.saturating_sub(relative);
}
pub use document::Document;
pub use editor::Editor;
-use helix_core::char_idx_at_visual_offset;
pub use theme::Theme;
pub use view::View;