on master help sign in
Accept count for goto_window (#1033)

* accept count for goto_window also fix view is not fullfilled issue * fix fulfilled mispell * Update helix-term/src/commands.rs Co-authored-by: Ivan Tham <pickfire@riseup.net> * Update helix-term/src/commands.rs Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix merge issue * revert line computation logic Co-authored-by: Ivan Tham <pickfire@riseup.net>

commit42fde95223a62bded340a1737e8be50ef94af4af authorBob <QiBaobin@users.noreply.github.com> dateMon 29 Nov 2021, 09:58 (5 years ago) parent4f9390a
1 file changed+7−4
helix-term/src/commands.rs+7−4
helix-term/src/commands.rs+7−4
@@ -733,10 +733,12 @@ fn align_fragment_to_width(fragment: &str, width: usize, align_style: usize) ->
733733}
734734
735735fn goto_window(cx: &mut Context, align: Align) {
736+ let count = cx.count() - 1;
736737 let (view, doc) = current!(cx.editor);
737738
738739 let height = view.inner_area().height as usize;
739740
741+ // respect user given count if any
740742 // - 1 so we have at least one gap in the middle.
741743 // a height of 6 with padding of 3 on each side will keep shifting the view back and forth
742744 // as we type
@@ -745,11 +747,12 @@ fn goto_window(cx: &mut Context, align: Align) {
745747 let last_line = view.last_line(doc);
746748
747749 let line = match align {
748− Align::Top => (view.offset.row + scrolloff),
749− Align::Center => (view.offset.row + (height / 2)),
750− Align::Bottom => last_line.saturating_sub(scrolloff),
750+ Align::Top => (view.offset.row + scrolloff + count),
751+ Align::Center => (view.offset.row + ((last_line - view.offset.row) / 2)),
752+ Align::Bottom => last_line.saturating_sub(scrolloff + count),
751753 }
752− .min(last_line.saturating_sub(scrolloff));
754+ .min(last_line.saturating_sub(scrolloff))
755+ .max(view.offset.row + scrolloff);
753756
754757 let pos = doc.text().line_to_char(line);
755758