on master help sign in
Share the padding definition too.
77ff51cBlaž Hrastnik
helix-view/src/commands.rs+1−3
@@ -8,14 +8,12 @@ use helix_core::{
8};
8};
9use once_cell::sync::Lazy;
9use once_cell::sync::Lazy;
10
10
11−use crate::view::View;
11+use crate::view::{View, PADDING};
12
12
13/// A command is a function that takes the current state and a count, and does a side-effect on the
13/// A command is a function that takes the current state and a count, and does a side-effect on the
14/// state (usually by creating and applying a transaction).
14/// state (usually by creating and applying a transaction).
15pub type Command = fn(view: &mut View, count: usize);
15pub type Command = fn(view: &mut View, count: usize);
16
16
17−const PADDING: usize = 5;
18−
19pub fn move_char_left(view: &mut View, count: usize) {
17pub fn move_char_left(view: &mut View, count: usize) {
20 // TODO: use a transaction
18 // TODO: use a transaction
21 let selection = view
19 let selection = view
helix-view/src/view.rs+6−6
@@ -10,6 +10,8 @@ use helix_core::{
10};
10};
11use tui::layout::Rect;
11use tui::layout::Rect;
12
12
13+pub const PADDING: usize = 5;
14+
13pub struct View {
15pub struct View {
14 pub state: State,
16 pub state: State,
15 pub history: History,
17 pub history: History,
@@ -39,16 +41,14 @@ impl View {
39 let line = self.state.doc().char_to_line(cursor);
41 let line = self.state.doc().char_to_line(cursor);
40 let document_end = self.first_line + (self.size.1 as usize).saturating_sub(1);
42 let document_end = self.first_line + (self.size.1 as usize).saturating_sub(1);
41
43
42− let padding = 5usize;
43−
44 // TODO: side scroll
44 // TODO: side scroll
45
45
46− if line > document_end.saturating_sub(padding) {
46+ if line > document_end.saturating_sub(PADDING) {
47 // scroll down
47 // scroll down
48− self.first_line += line - (document_end.saturating_sub(padding));
48+ self.first_line += line - (document_end.saturating_sub(PADDING));
49− } else if line < self.first_line + padding {
49+ } else if line < self.first_line + PADDING {
50 // scroll up
50 // scroll up
51− self.first_line = line.saturating_sub(padding);
51+ self.first_line = line.saturating_sub(PADDING);
52 }
52 }
53 }
53 }
54
54