From 2ca318116c6ad8a539dd13d86475add4548c5524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 24 Feb 2017 09:37:19 +0100 Subject: vis: fix display after newline insertion at the start of viewport Previously the window content would not be scrolled down when inserting a newline exactly at the start of the display area as in the case when a file starts with an empty line and the following is performed: o --- vis.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'vis.c') diff --git a/vis.c b/vis.c index aaead35..303a5e6 100644 --- a/vis.c +++ b/vis.c @@ -1486,8 +1486,14 @@ void vis_insert_nl(Vis *vis) { Text *txt = vis->win->file->text; for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) { size_t pos = view_cursors_pos(c); - pos = vis_text_insert_nl(vis, txt, pos); - view_cursors_scroll_to(c, pos); + size_t newpos = vis_text_insert_nl(vis, txt, pos); + /* This is a bit of a hack to fix cursor positioning when + * inserting a new line at the start of the view port. + * It has the effect of reseting the mark used by the view + * code to keep track of the start of the visible region. + */ + view_cursors_to(c, pos); + view_cursors_to(c, newpos); } size_t pos = view_cursor_get(view); windows_invalidate(vis, pos, pos-1); -- cgit v1.2.3