@@ -441,35 +441,35 @@ fn goto_first_nonwhitespace(cx: &mut Context) {
441441 doc.set_selection(view.id, selection);
442442}
443443
444−fn goto_window_top(cx: &mut Context) {
444+fn goto_window(cx: &mut Context, align: Align) {
445445 let (view, doc) = current!(cx.editor);
446446
447447 let scrolloff = PADDING.min(view.area.height as usize / 2); // TODO: user pref
448− let line = (view.first_line + scrolloff).min(view.last_line(doc).saturating_sub(scrolloff));
449− let pos = doc.text().line_to_char(line);
450448
451− doc.set_selection(view.id, Selection::point(pos));
452−}
449+ let last_line = view.last_line(doc);
453450
454−fn goto_window_middle(cx: &mut Context) {
455− let (view, doc) = current!(cx.editor);
451+ let line = match align {
452+ Align::Top => (view.first_line + scrolloff),
453+ Align::Center => (view.first_line + (view.area.height as usize / 2)),
454+ Align::Bottom => last_line.saturating_sub(scrolloff),
455+ }
456+ .min(last_line.saturating_sub(scrolloff));
456457
457− let scrolloff = PADDING.min(view.area.height as usize / 2); // TODO: user pref
458− let line = view.first_line + (view.area.height as usize / 2);
459− let line = line.min(view.last_line(doc).saturating_sub(scrolloff));
460458 let pos = doc.text().line_to_char(line);
461459
462460 doc.set_selection(view.id, Selection::point(pos));
463461}
464462
465−fn goto_window_bottom(cx: &mut Context) {
466− let (view, doc) = current!(cx.editor);
463+fn goto_window_top(cx: &mut Context) {
464+ goto_window(cx, Align::Top)
465+}
467466
468− let scrolloff = PADDING.min(view.area.height as usize / 2); // TODO: user pref
469− let line = view.last_line(doc).saturating_sub(scrolloff);
470− let pos = doc.text().line_to_char(line);
467+fn goto_window_middle(cx: &mut Context) {
468+ goto_window(cx, Align::Center)
469+}
471470
472− doc.set_selection(view.id, Selection::point(pos));
471+fn goto_window_bottom(cx: &mut Context) {
472+ goto_window(cx, Align::Bottom)
473473}
474474
475475// TODO: move vs extend could take an extra type Extend/Move that would
@@ -3722,7 +3722,7 @@ mode_info! {
37223722 "i" => goto_implementation,
37233723 /// window top
37243724 "t" => goto_window_top,
3725− /// window center
3725+ /// window middle
37263726 "m" => goto_window_middle,
37273727 /// window bottom
37283728 "b" => goto_window_bottom,