changeset 11840:3c1f89d85151 v8.0.0800

patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes #1891) commit https://github.com/vim/vim/commit/696d00f488dc0599692993f226a7dd95a187920d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 29 14:52:43 2017 +0200 patch 8.0.0800 Problem: Terminal window scrollback contents is wrong. Solution: Fix handling of multi-byte characters (Yasuhiro Matsumoto) Handle empty lines correctly. (closes https://github.com/vim/vim/issues/1891)
author Christian Brabandt <cb@256bit.org>
date Sat, 29 Jul 2017 15:00:04 +0200
parents 6693f3c940e0
children b0a9c124b737
files src/terminal.c src/version.c
diffstat 2 files changed, 24 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -765,26 +765,26 @@ handle_pushline(int cols, const VTermScr
     /* TODO: put the text in the buffer. */
     if (ga_grow(&term->tl_scrollback, 1) == OK)
     {
-	VTermScreenCell *p;
-	int len;
-	int i;
+	VTermScreenCell *p = NULL;
+	int		len = 0;
+	int		i;
+	sb_line_T	*line;
 
 	/* do not store empty cells at the end */
 	for (i = 0; i < cols; ++i)
 	    if (cells[i].chars[0] != 0)
 		len = i + 1;
 
-	p = (VTermScreenCell *)alloc((int)sizeof(VTermScreenCell) * len);
+	if (len > 0)
+	    p = (VTermScreenCell *)alloc((int)sizeof(VTermScreenCell) * len);
 	if (p != NULL)
-	{
-	    sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
-						  + term->tl_scrollback.ga_len;
+	    mch_memmove(p, cells, sizeof(VTermScreenCell) * len);
 
-	    mch_memmove(p, cells, sizeof(VTermScreenCell) * len);
-	    line->sb_cols = len;
-	    line->sb_cells = p;
-	    ++term->tl_scrollback.ga_len;
-	}
+	line = (sb_line_T *)term->tl_scrollback.ga_data
+						  + term->tl_scrollback.ga_len;
+	line->sb_cols = len;
+	line->sb_cells = p;
+	++term->tl_scrollback.ga_len;
     }
     return 0; /* ignored */
 }
@@ -818,7 +818,9 @@ move_scrollback_to_buffer(term_T *term)
 						       && cell.chars[0] != NUL)
 		len = pos.col + 1;
 
-	if (len > 0)
+	if (len == 0)
+	    ++lines_skipped;
+	else
 	{
 	    while (lines_skipped > 0)
 	    {
@@ -865,13 +867,15 @@ move_scrollback_to_buffer(term_T *term)
 
 	ga.ga_len = 0;
 	for (col = 0; col < line->sb_cols; ++col)
-	    for (i = 0; (c = line->sb_cells[col].chars[i]) != 0 || i == 0; ++i)
-	    {
-		if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
-		    goto failed;
+	{
+	    if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
+		goto failed;
+	    for (i = 0; (c = line->sb_cells[col].chars[i]) > 0 || i == 0; ++i)
 		ga.ga_len += mb_char2bytes(c == NUL ? ' ' : c,
 					     (char_u *)ga.ga_data + ga.ga_len);
-	    }
+	}
+	if (ga_grow(&ga, 1) == FAIL)
+	    goto failed;
 	*((char_u *)ga.ga_data + ga.ga_len) = NUL;
 	ml_append_buf(term->tl_buffer, lnum, ga.ga_data, ga.ga_len + 1, FALSE);
     }
--- a/src/version.c
+++ b/src/version.c
@@ -770,6 +770,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    800,
+/**/
     799,
 /**/
     798,