From a2ccfffda1171bde5118c1a1120af49dc87aecca Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Sun, 8 Aug 2021 14:07:14 +0900 Subject: config: Rename [terminal] to [editor] and pass it into Editor --- helix-view/src/editor.rs | 28 ++++++++++++++++++++++++++-- helix-view/src/view.rs | 6 ++---- 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'helix-view') diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 7e8548e7..e5ba0d51 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -18,6 +18,26 @@ pub use helix_core::register::Registers; use helix_core::syntax; use helix_core::Position; +use serde::Deserialize; + +#[derive(Debug, Clone, PartialEq, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub struct Config { + /// Padding to keep between the edge of the screen and the cursor when scrolling. Defaults to 5. + pub scrolloff: usize, + /// Mouse support. Defaults to true. + pub mouse: bool, +} + +impl Default for Config { + fn default() -> Self { + Self { + scrolloff: 5, + mouse: true, + } + } +} + #[derive(Debug)] pub struct Editor { pub tree: Tree, @@ -33,6 +53,8 @@ pub struct Editor { pub theme_loader: Arc, pub status_msg: Option<(String, Severity)>, + + pub config: Config, } #[derive(Debug, Copy, Clone)] @@ -48,6 +70,7 @@ impl Editor { mut area: Rect, themes: Arc, config_loader: Arc, + config: Config, ) -> Self { let language_servers = helix_lsp::Registry::new(); @@ -66,6 +89,7 @@ impl Editor { registers: Registers::default(), clipboard_provider: get_clipboard_provider(), status_msg: None, + config, } } @@ -108,7 +132,7 @@ impl Editor { fn _refresh(&mut self) { for (view, _) in self.tree.views_mut() { let doc = &self.documents[view.doc]; - view.ensure_cursor_in_view(doc) + view.ensure_cursor_in_view(doc, self.config.scrolloff) } } @@ -267,7 +291,7 @@ impl Editor { pub fn ensure_cursor_in_view(&mut self, id: ViewId) { let view = self.tree.get_mut(id); let doc = &self.documents[view.doc]; - view.ensure_cursor_in_view(doc) + view.ensure_cursor_in_view(doc, self.config.scrolloff) } pub fn document(&self, id: DocumentId) -> Option<&Document> { diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 62ab2642..25efbde5 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -8,8 +8,6 @@ use helix_core::{ Position, RopeSlice, Selection, }; -pub const PADDING: usize = 5; - type Jump = (DocumentId, Selection); #[derive(Debug)] @@ -84,7 +82,7 @@ impl View { } } - pub fn ensure_cursor_in_view(&mut self, doc: &Document) { + pub fn ensure_cursor_in_view(&mut self, doc: &Document, scrolloff: usize) { let cursor = doc .selection(self.id) .primary() @@ -95,7 +93,7 @@ impl View { let height = self.area.height.saturating_sub(1); // - 1 for statusline let last_line = (self.first_line + height as usize).saturating_sub(1); - let scrolloff = PADDING.min(self.area.height as usize / 2); // TODO: user pref + let scrolloff = scrolloff.min(self.area.height as usize / 2); // TODO: not ideal const OFFSET: usize = 7; // 1 diagnostic + 5 linenr + 1 gutter -- cgit v1.2.3-70-g09d2