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;
|
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;
|
|
|
|
}
|
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;
|
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) {
|
|
|
|
let pos = doc
|
|
|
|
.selection(view.id)
|
|
|
|
.primary()
|
|
|
|
.cursor(doc.text().slice(..));
|
|
|
|
let line = doc.text().char_to_line(pos);
|
|
|
|
|
2022-10-11 01:12:48 +08:00
|
|
|
let last_line_height = view.inner_area().height.saturating_sub(1) as usize;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
view.offset.row = line.saturating_sub(relative);
|
|
|
|
}
|
|
|
|
|
2022-10-11 04:15:37 +08:00
|
|
|
/// Applies a [`helix_core::Transaction`] to the given [`Document`]
|
|
|
|
/// and [`View`].
|
|
|
|
pub fn apply_transaction(
|
|
|
|
transaction: &helix_core::Transaction,
|
|
|
|
doc: &mut Document,
|
|
|
|
view: &mut View,
|
|
|
|
) -> bool {
|
|
|
|
// This is a short function but it's easy to call `Document::apply`
|
|
|
|
// without calling `View::apply` or in the wrong order. The transaction
|
|
|
|
// must be applied to the document before the view.
|
|
|
|
doc.apply(transaction, view.id) && view.apply(transaction, doc)
|
|
|
|
}
|
|
|
|
|
2020-10-22 13:35:07 +08:00
|
|
|
pub use document::Document;
|
2020-10-16 11:29:22 +08:00
|
|
|
pub use editor::Editor;
|
2020-10-19 16:18:03 +08:00
|
|
|
pub use theme::Theme;
|
2020-09-21 17:24:16 +08:00
|
|
|
pub use view::View;
|