@@ -110,10 +110,12 @@ fn align_view(doc: &Document, view: &mut View, align: Align) {
110110 .cursor(doc.text().slice(..));
111111 let line = doc.text().char_to_line(pos);
112112
113+ let height = view.area.height.saturating_sub(1) as usize; // -1 for statusline
114+
113115 let relative = match align {
114− Align::Center => view.area.height as usize / 2,
116+ Align::Center => height / 2,
115117 Align::Top => 0,
116− Align::Bottom => view.area.height as usize,
118+ Align::Bottom => height,
117119 };
118120
119121 view.first_line = line.saturating_sub(relative);
@@ -448,17 +450,21 @@ fn goto_first_nonwhitespace(cx: &mut Context) {
448450fn goto_window(cx: &mut Context, align: Align) {
449451 let (view, doc) = current!(cx.editor);
450452
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
456+ // as we type
451457 let scrolloff = cx
452458 .editor
453459 .config
454460 .scrolloff
455− .min(view.area.height as usize / 2); // TODO: user pref
461+ .min(height.saturating_sub(1) / 2);
456462
457463 let last_line = view.last_line(doc);
458464
459465 let line = match align {
460466 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)),
462468 Align::Bottom => last_line.saturating_sub(scrolloff),
463469 }
464470 .min(last_line.saturating_sub(scrolloff));
@@ -894,7 +900,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
894900 .editor
895901 .config
896902 .scrolloff
897− .min(view.area.height as usize / 2); // TODO: user pref
903+ .min(view.area.height as usize / 2);
898904
899905 view.first_line = match direction {
900906 Forward => view.first_line + offset,