From 88f7f5f8675a15d567837bd076e39e09bfe1aa74 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Tue, 23 Feb 2021 14:30:49 -0500 Subject: goto line preview --- buffer.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'buffer.c') diff --git a/buffer.c b/buffer.c index 57325b8..0c226ea 100644 --- a/buffer.c +++ b/buffer.c @@ -864,7 +864,15 @@ void buffer_scroll_to_pos(TextBuffer *buffer, BufferPos pos) { } // scroll in such a way that this position is in the center of the screen -void buffer_scroll_center_pos(TextBuffer *buffer) { +void buffer_scroll_center_pos(TextBuffer *buffer, BufferPos pos) { + double line = pos.line; + double col = buffer_index_to_column(buffer, pos.line, pos.index); + + double display_lines = buffer_display_lines(buffer); + double display_cols = buffer_display_cols(buffer); + buffer->scroll_x = col - display_cols * 0.5; + buffer->scroll_y = line - display_lines * 0.5; + buffer_correct_scroll(buffer); } // if the cursor is offscreen, this will scroll to make it onscreen. -- cgit v1.2.3