summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-23 14:30:49 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-23 14:30:49 -0500
commit88f7f5f8675a15d567837bd076e39e09bfe1aa74 (patch)
tree2b12ed6c901fbed71abe88a5420c5e2841155b6f /buffer.c
parentf4172376d933c5c9033ff421f04db828825f9017 (diff)
goto line preview
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c10
1 files changed, 9 insertions, 1 deletions
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.