on master help sign in
Accept count for goto_window (#1033)
42fde95Bob
helix-term/src/commands.rs+7−4
@@ -733,10 +733,12 @@ fn align_fragment_to_width(fragment: &str, width: usize, align_style: usize) ->
733}
733}
734
734
735fn goto_window(cx: &mut Context, align: Align) {
735fn goto_window(cx: &mut Context, align: Align) {
736+ let count = cx.count() - 1;
736 let (view, doc) = current!(cx.editor);
737 let (view, doc) = current!(cx.editor);
737
738
738 let height = view.inner_area().height as usize;
739 let height = view.inner_area().height as usize;
739
740
741+ // respect user given count if any
740 // - 1 so we have at least one gap in the middle.
742 // - 1 so we have at least one gap in the middle.
741 // a height of 6 with padding of 3 on each side will keep shifting the view back and forth
743 // a height of 6 with padding of 3 on each side will keep shifting the view back and forth
742 // as we type
744 // as we type
@@ -745,11 +747,12 @@ fn goto_window(cx: &mut Context, align: Align) {
745 let last_line = view.last_line(doc);
747 let last_line = view.last_line(doc);
746
748
747 let line = match align {
749 let line = match align {
748− Align::Top => (view.offset.row + scrolloff),
750+ Align::Top => (view.offset.row + scrolloff + count),
749− Align::Center => (view.offset.row + (height / 2)),
751+ Align::Center => (view.offset.row + ((last_line - view.offset.row) / 2)),
750− Align::Bottom => last_line.saturating_sub(scrolloff),
752+ Align::Bottom => last_line.saturating_sub(scrolloff + count),
751 }
753 }
752− .min(last_line.saturating_sub(scrolloff));
754+ .min(last_line.saturating_sub(scrolloff))
755+ .max(view.offset.row + scrolloff);
753
756
754 let pos = doc.text().line_to_char(line);
757 let pos = doc.text().line_to_char(line);
755
758