2021-06-18 06:09:10 +08:00
|
|
|
#[macro_use]
|
|
|
|
pub mod macros;
|
|
|
|
|
2021-06-15 05:37:17 +08:00
|
|
|
pub mod clipboard;
|
2020-10-22 13:35:07 +08:00
|
|
|
pub mod document;
|
2020-10-16 11:29:22 +08:00
|
|
|
pub mod editor;
|
2022-11-02 09:12:40 +08:00
|
|
|
pub mod env;
|
2021-06-25 11:58:15 +08:00
|
|
|
pub mod graphics;
|
2021-11-23 11:56:46 +08:00
|
|
|
pub mod gutter;
|
2022-03-22 11:53:44 +08:00
|
|
|
pub mod handlers {
|
|
|
|
pub mod dap;
|
|
|
|
pub mod lsp;
|
|
|
|
}
|
2022-11-02 09:12:40 +08:00
|
|
|
pub mod base64;
|
2021-06-19 23:54:37 +08:00
|
|
|
pub mod info;
|
2021-06-23 01:04:04 +08:00
|
|
|
pub mod input;
|
2021-06-25 11:58:15 +08:00
|
|
|
pub mod keyboard;
|
2023-07-11 05:30:42 +08:00
|
|
|
pub mod register;
|
2020-09-21 17:24:16 +08:00
|
|
|
pub mod theme;
|
2021-02-03 18:36:54 +08:00
|
|
|
pub mod tree;
|
2020-09-21 17:24:16 +08:00
|
|
|
pub mod view;
|
|
|
|
|
2021-11-25 10:07:23 +08:00
|
|
|
use std::num::NonZeroUsize;
|
|
|
|
|
|
|
|
// uses NonZeroUsize so Option<DocumentId> use a byte rather than two
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
|
|
|
pub struct DocumentId(NonZeroUsize);
|
|
|
|
|
|
|
|
impl Default for DocumentId {
|
|
|
|
fn default() -> DocumentId {
|
|
|
|
// Safety: 1 is non-zero
|
|
|
|
DocumentId(unsafe { NonZeroUsize::new_unchecked(1) })
|
|
|
|
}
|
|
|
|
}
|
2021-11-04 12:43:45 +08:00
|
|
|
|
2021-11-10 09:06:40 +08:00
|
|
|
impl std::fmt::Display for DocumentId {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
f.write_fmt(format_args!("{}", self.0))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-23 01:04:04 +08:00
|
|
|
slotmap::new_key_type! {
|
|
|
|
pub struct ViewId;
|
|
|
|
}
|
2021-03-16 17:27:57 +08:00
|
|
|
|
2022-03-22 11:53:44 +08:00
|
|
|
pub enum Align {
|
|
|
|
Top,
|
|
|
|
Center,
|
|
|
|
Bottom,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn align_view(doc: &Document, view: &mut View, align: Align) {
|
2023-02-01 01:03:19 +08:00
|
|
|
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);
|
2022-03-22 11:53:44 +08:00
|
|
|
|
|
|
|
let relative = match align {
|
2022-10-11 01:12:48 +08:00
|
|
|
Align::Center => last_line_height / 2,
|
2022-03-22 11:53:44 +08:00
|
|
|
Align::Top => 0,
|
2022-10-11 01:12:48 +08:00
|
|
|
Align::Bottom => last_line_height,
|
2022-03-22 11:53:44 +08:00
|
|
|
};
|
|
|
|
|
2023-02-01 01:03:19 +08:00
|
|
|
let text_fmt = doc.text_format(viewport.width, None);
|
|
|
|
let annotations = view.text_annotations(doc, None);
|
|
|
|
(view.offset.anchor, view.offset.vertical_offset) = char_idx_at_visual_offset(
|
|
|
|
doc_text,
|
|
|
|
cursor,
|
|
|
|
-(relative as isize),
|
|
|
|
0,
|
|
|
|
&text_fmt,
|
|
|
|
&annotations,
|
|
|
|
);
|
2022-03-22 11:53:44 +08:00
|
|
|
}
|
|
|
|
|
2020-10-22 13:35:07 +08:00
|
|
|
pub use document::Document;
|
2020-10-16 11:29:22 +08:00
|
|
|
pub use editor::Editor;
|
2023-02-01 01:03:19 +08:00
|
|
|
use helix_core::char_idx_at_visual_offset;
|
2020-10-19 16:18:03 +08:00
|
|
|
pub use theme::Theme;
|
2020-09-21 17:24:16 +08:00
|
|
|
pub use view::View;
|