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 #4745)
diff --git a/src/channel.c b/src/channel.c
index 5d1b83a..6351c89 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -2537,19 +2537,26 @@
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);