@@ -18,6 +18,26 @@ pub use helix_core::register::Registers;
18use helix_core::syntax;
18use helix_core::syntax;
19use helix_core::Position;
19use helix_core::Position;
21+use serde::Deserialize;
23+#[derive(Debug, Clone, PartialEq, Deserialize)]
24+#[serde(rename_all = "kebab-case")]
26+ /// Padding to keep between the edge of the screen and the cursor when scrolling. Defaults to 5.
27+ pub scrolloff: usize,
28+ /// Mouse support. Defaults to true.
32+impl Default for Config {
33+ fn default() -> Self {
21#[derive(Debug)]
41#[derive(Debug)]
22pub struct Editor {
42pub struct Editor {
23 pub tree: Tree,
43 pub tree: Tree,
@@ -33,6 +53,8 @@ pub struct Editor {
33 pub theme_loader: Arc<theme::Loader>,
53 pub theme_loader: Arc<theme::Loader>,
35 pub status_msg: Option<(String, Severity)>,
55 pub status_msg: Option<(String, Severity)>,
38#[derive(Debug, Copy, Clone)]
60#[derive(Debug, Copy, Clone)]
@@ -48,6 +70,7 @@ impl Editor {
48 mut area: Rect,
70 mut area: Rect,
49 themes: Arc<theme::Loader>,
71 themes: Arc<theme::Loader>,
50 config_loader: Arc<syntax::Loader>,
72 config_loader: Arc<syntax::Loader>,
51 ) -> Self {
74 ) -> Self {
52 let language_servers = helix_lsp::Registry::new();
75 let language_servers = helix_lsp::Registry::new();
@@ -66,6 +89,7 @@ impl Editor {
66 registers: Registers::default(),
89 registers: Registers::default(),
67 clipboard_provider: get_clipboard_provider(),
90 clipboard_provider: get_clipboard_provider(),
68 status_msg: None,
91 status_msg: None,
@@ -108,7 +132,7 @@ impl Editor {
108 fn _refresh(&mut self) {
132 fn _refresh(&mut self) {
109 for (view, _) in self.tree.views_mut() {
133 for (view, _) in self.tree.views_mut() {
110 let doc = &self.documents[view.doc];
134 let doc = &self.documents[view.doc];
111− view.ensure_cursor_in_view(doc)
135+ view.ensure_cursor_in_view(doc, self.config.scrolloff)
@@ -267,7 +291,7 @@ impl Editor {
267 pub fn ensure_cursor_in_view(&mut self, id: ViewId) {
291 pub fn ensure_cursor_in_view(&mut self, id: ViewId) {
268 let view = self.tree.get_mut(id);
292 let view = self.tree.get_mut(id);
269 let doc = &self.documents[view.doc];
293 let doc = &self.documents[view.doc];
270− view.ensure_cursor_in_view(doc)
294+ view.ensure_cursor_in_view(doc, self.config.scrolloff)
273 pub fn document(&self, id: DocumentId) -> Option<&Document> {
297 pub fn document(&self, id: DocumentId) -> Option<&Document> {