summaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-08-08 05:07:14 +0000
committerBlaž Hrastnik2021-08-08 05:10:01 +0000
commita2ccfffda1171bde5118c1a1120af49dc87aecca (patch)
tree54138341e17ebf600c37c9830914a546ce39fb04 /helix-view
parentf0eb6ed96a6e61ee6abe3aa14071cfc003d0b37f (diff)
config: Rename [terminal] to [editor] and pass it into Editor
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/editor.rs28
-rw-r--r--helix-view/src/view.rs6
2 files changed, 28 insertions, 6 deletions
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<theme::Loader>,
pub status_msg: Option<(String, Severity)>,
+
+ pub config: Config,
}
#[derive(Debug, Copy, Clone)]
@@ -48,6 +70,7 @@ impl Editor {
mut area: Rect,
themes: Arc<theme::Loader>,
config_loader: Arc<syntax::Loader>,
+ 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