@@ -110,10 +110,12 @@ fn align_view(doc: &Document, view: &mut View, align: Align) {
110 .cursor(doc.text().slice(..));
110 .cursor(doc.text().slice(..));
111 let line = doc.text().char_to_line(pos);
111 let line = doc.text().char_to_line(pos);
113+ let height = view.area.height.saturating_sub(1) as usize; // -1 for statusline
113 let relative = match align {
115 let relative = match align {
114− Align::Center => view.area.height as usize / 2,
116+ Align::Center => height / 2,
115 Align::Top => 0,
117 Align::Top => 0,
116− Align::Bottom => view.area.height as usize,
118+ Align::Bottom => height,
119 view.first_line = line.saturating_sub(relative);
121 view.first_line = line.saturating_sub(relative);
@@ -448,17 +450,21 @@ fn goto_first_nonwhitespace(cx: &mut Context) {
448fn goto_window(cx: &mut Context, align: Align) {
450fn goto_window(cx: &mut Context, align: Align) {
449 let (view, doc) = current!(cx.editor);
451 let (view, doc) = current!(cx.editor);
453+ let height = view.area.height.saturating_sub(1) as usize; // -1 for statusline
454+ // - 1 so we have at least one gap in the middle.
455+ // a height of 6 with padding of 3 on each side will keep shifting the view back and forth
451 let scrolloff = cx
457 let scrolloff = cx
454 .scrolloff
460 .scrolloff
455− .min(view.area.height as usize / 2); // TODO: user pref
461+ .min(height.saturating_sub(1) / 2);
457 let last_line = view.last_line(doc);
463 let last_line = view.last_line(doc);
459 let line = match align {
465 let line = match align {
460 Align::Top => (view.first_line + scrolloff),
466 Align::Top => (view.first_line + scrolloff),
461− Align::Center => (view.first_line + (view.area.height as usize / 2)),
467+ Align::Center => (view.first_line + (height / 2)),
462 Align::Bottom => last_line.saturating_sub(scrolloff),
468 Align::Bottom => last_line.saturating_sub(scrolloff),
464 .min(last_line.saturating_sub(scrolloff));
470 .min(last_line.saturating_sub(scrolloff));
@@ -894,7 +900,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
896 .scrolloff
902 .scrolloff
897− .min(view.area.height as usize / 2); // TODO: user pref
903+ .min(view.area.height as usize / 2);
899 view.first_line = match direction {
905 view.first_line = match direction {
900 Forward => view.first_line + offset,
906 Forward => view.first_line + offset,