Skip to content

Commit 696d00f

Browse files
committed
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)
1 parent dcbfa33 commit 696d00f

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

src/terminal.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -765,26 +765,26 @@ handle_pushline(int cols, const VTermScreenCell *cells, void *user)
765765
/* TODO: put the text in the buffer. */
766766
if (ga_grow(&term->tl_scrollback, 1) == OK)
767767
{
768-
VTermScreenCell *p;
769-
int len;
770-
int i;
768+
VTermScreenCell *p = NULL;
769+
int len = 0;
770+
int i;
771+
sb_line_T *line;
771772

772773
/* do not store empty cells at the end */
773774
for (i = 0; i < cols; ++i)
774775
if (cells[i].chars[0] != 0)
775776
len = i + 1;
776777

777-
p = (VTermScreenCell *)alloc((int)sizeof(VTermScreenCell) * len);
778+
if (len > 0)
779+
p = (VTermScreenCell *)alloc((int)sizeof(VTermScreenCell) * len);
778780
if (p != NULL)
779-
{
780-
sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data
781-
+ term->tl_scrollback.ga_len;
782-
783781
mch_memmove(p, cells, sizeof(VTermScreenCell) * len);
784-
line->sb_cols = len;
785-
line->sb_cells = p;
786-
++term->tl_scrollback.ga_len;
787-
}
782+
783+
line = (sb_line_T *)term->tl_scrollback.ga_data
784+
+ term->tl_scrollback.ga_len;
785+
line->sb_cols = len;
786+
line->sb_cells = p;
787+
++term->tl_scrollback.ga_len;
788788
}
789789
return 0; /* ignored */
790790
}
@@ -818,7 +818,9 @@ move_scrollback_to_buffer(term_T *term)
818818
&& cell.chars[0] != NUL)
819819
len = pos.col + 1;
820820

821-
if (len > 0)
821+
if (len == 0)
822+
++lines_skipped;
823+
else
822824
{
823825
while (lines_skipped > 0)
824826
{
@@ -865,13 +867,15 @@ move_scrollback_to_buffer(term_T *term)
865867

866868
ga.ga_len = 0;
867869
for (col = 0; col < line->sb_cols; ++col)
868-
for (i = 0; (c = line->sb_cells[col].chars[i]) != 0 || i == 0; ++i)
869-
{
870-
if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
871-
goto failed;
870+
{
871+
if (ga_grow(&ga, MB_MAXBYTES) == FAIL)
872+
goto failed;
873+
for (i = 0; (c = line->sb_cells[col].chars[i]) > 0 || i == 0; ++i)
872874
ga.ga_len += mb_char2bytes(c == NUL ? ' ' : c,
873875
(char_u *)ga.ga_data + ga.ga_len);
874-
}
876+
}
877+
if (ga_grow(&ga, 1) == FAIL)
878+
goto failed;
875879
*((char_u *)ga.ga_data + ga.ga_len) = NUL;
876880
ml_append_buf(term->tl_buffer, lnum, ga.ga_data, ga.ga_len + 1, FALSE);
877881
}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
800,
772774
/**/
773775
799,
774776
/**/

0 commit comments

Comments
 (0)