diff src/channel.c @ 17557:4a22102fda8f v8.1.1776

patch 8.1.1776: text added with a job isn't displayed commit https://github.com/vim/vim/commit/4641a122f2ffb820ec6d05526532ab38930c5286 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 29 22:10:23 2019 +0200 patch 8.1.1776: text added with a job isn't displayed Problem: Text added with a job to another buffer isn't displayed. Solution: Update topline after adding a line. (closes https://github.com/vim/vim/issues/4745)
author Bram Moolenaar <Bram@vim.org>
date Mon, 29 Jul 2019 22:15:04 +0200
parents d04de6c49f59
children ff097edaae89
line wrap: on
line diff
--- a/src/channel.c
+++ b/src/channel.c
@@ -2537,19 +2537,26 @@ append_to_buffer(buf_T *buffer, char_u *
 
 	FOR_ALL_WINDOWS(wp)
 	{
-	    if (wp->w_buffer == buffer
-		    && (save_write_to
-			? wp->w_cursor.lnum == lnum + 1
-			: (wp->w_cursor.lnum == lnum
-			    && wp->w_cursor.col == 0)))
+	    if (wp->w_buffer == buffer)
 	    {
-		++wp->w_cursor.lnum;
-		save_curwin = curwin;
-		curwin = wp;
-		curbuf = curwin->w_buffer;
-		scroll_cursor_bot(0, FALSE);
-		curwin = save_curwin;
-		curbuf = curwin->w_buffer;
+		int move_cursor = save_write_to
+			    ? wp->w_cursor.lnum == lnum + 1
+			    : (wp->w_cursor.lnum == lnum
+				&& wp->w_cursor.col == 0);
+
+		// If the cursor is at or above the new line, move it one line
+		// down.  If the topline is outdated update it now.
+		if (move_cursor || wp->w_topline > buffer->b_ml.ml_line_count)
+		{
+		    if (move_cursor)
+			++wp->w_cursor.lnum;
+		    save_curwin = curwin;
+		    curwin = wp;
+		    curbuf = curwin->w_buffer;
+		    scroll_cursor_bot(0, FALSE);
+		    curwin = save_curwin;
+		    curbuf = curwin->w_buffer;
+		}
 	    }
 	}
 	redraw_buf_and_status_later(buffer, VALID);