on master help sign in
Share the padding definition too.
commit77ff51cef9d7444e5dca92c03f6b12edce659dae authorBlaž Hrastnik <blaz@mxxn.io> dateWed 14 Oct 2020, 12:03 (6 years ago) parentd64f4be
2 files changed+7−9
helix-view/src/commands.rs+1−3 helix-view/src/view.rs+6−6
helix-view/src/commands.rs+1−3
@@ -8,14 +8,12 @@ use helix_core::{
88};
99use once_cell::sync::Lazy;
1010
11−use crate::view::View;
11+use crate::view::{View, PADDING};
1212
1313/// A command is a function that takes the current state and a count, and does a side-effect on the
1414/// state (usually by creating and applying a transaction).
1515pub type Command = fn(view: &mut View, count: usize);
1616
17−const PADDING: usize = 5;
18−
1917pub fn move_char_left(view: &mut View, count: usize) {
2018 // TODO: use a transaction
2119 let selection = view
helix-view/src/view.rs+6−6
@@ -10,6 +10,8 @@ use helix_core::{
1010};
1111use tui::layout::Rect;
1212
13+pub const PADDING: usize = 5;
14+
1315pub struct View {
1416 pub state: State,
1517 pub history: History,
@@ -39,16 +41,14 @@ impl View {
3941 let line = self.state.doc().char_to_line(cursor);
4042 let document_end = self.first_line + (self.size.1 as usize).saturating_sub(1);
4143
42− let padding = 5usize;
43−
4444 // TODO: side scroll
4545
46− if line > document_end.saturating_sub(padding) {
46+ if line > document_end.saturating_sub(PADDING) {
4747 // scroll down
48− self.first_line += line - (document_end.saturating_sub(padding));
49− } else if line < self.first_line + padding {
48+ self.first_line += line - (document_end.saturating_sub(PADDING));
49+ } else if line < self.first_line + PADDING {
5050 // scroll up
51− self.first_line = line.saturating_sub(padding);
51+ self.first_line = line.saturating_sub(PADDING);
5252 }
5353 }
5454