mirror of https://github.com/helix-editor/helix
Share the padding definition too.
parent
d64f4beede
commit
77ff51cef9
|
@ -8,14 +8,12 @@ use helix_core::{
|
||||||
};
|
};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::view::View;
|
use crate::view::{View, PADDING};
|
||||||
|
|
||||||
/// A command is a function that takes the current state and a count, and does a side-effect on the
|
/// A command is a function that takes the current state and a count, and does a side-effect on the
|
||||||
/// state (usually by creating and applying a transaction).
|
/// state (usually by creating and applying a transaction).
|
||||||
pub type Command = fn(view: &mut View, count: usize);
|
pub type Command = fn(view: &mut View, count: usize);
|
||||||
|
|
||||||
const PADDING: usize = 5;
|
|
||||||
|
|
||||||
pub fn move_char_left(view: &mut View, count: usize) {
|
pub fn move_char_left(view: &mut View, count: usize) {
|
||||||
// TODO: use a transaction
|
// TODO: use a transaction
|
||||||
let selection = view
|
let selection = view
|
||||||
|
|
|
@ -10,6 +10,8 @@ use helix_core::{
|
||||||
};
|
};
|
||||||
use tui::layout::Rect;
|
use tui::layout::Rect;
|
||||||
|
|
||||||
|
pub const PADDING: usize = 5;
|
||||||
|
|
||||||
pub struct View {
|
pub struct View {
|
||||||
pub state: State,
|
pub state: State,
|
||||||
pub history: History,
|
pub history: History,
|
||||||
|
@ -39,16 +41,14 @@ impl View {
|
||||||
let line = self.state.doc().char_to_line(cursor);
|
let line = self.state.doc().char_to_line(cursor);
|
||||||
let document_end = self.first_line + (self.size.1 as usize).saturating_sub(1);
|
let document_end = self.first_line + (self.size.1 as usize).saturating_sub(1);
|
||||||
|
|
||||||
let padding = 5usize;
|
|
||||||
|
|
||||||
// TODO: side scroll
|
// TODO: side scroll
|
||||||
|
|
||||||
if line > document_end.saturating_sub(padding) {
|
if line > document_end.saturating_sub(PADDING) {
|
||||||
// scroll down
|
// scroll down
|
||||||
self.first_line += line - (document_end.saturating_sub(padding));
|
self.first_line += line - (document_end.saturating_sub(PADDING));
|
||||||
} else if line < self.first_line + padding {
|
} else if line < self.first_line + PADDING {
|
||||||
// scroll up
|
// scroll up
|
||||||
self.first_line = line.saturating_sub(padding);
|
self.first_line = line.saturating_sub(PADDING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue