Mercurial > vim
comparison src/terminal.c @ 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 | e6080ed193f6 |
children | 6bfcedcc0262 |
comparison
equal
deleted
inserted
replaced
11839:6693f3c940e0 | 11840:3c1f89d85151 |
---|---|
763 | 763 |
764 /* TODO: Limit the number of lines that are stored. */ | 764 /* TODO: Limit the number of lines that are stored. */ |
765 /* TODO: put the text in the buffer. */ | 765 /* TODO: put the text in the buffer. */ |
766 if (ga_grow(&term->tl_scrollback, 1) == OK) | 766 if (ga_grow(&term->tl_scrollback, 1) == OK) |
767 { | 767 { |
768 VTermScreenCell *p; | 768 VTermScreenCell *p = NULL; |
769 int len; | 769 int len = 0; |
770 int i; | 770 int i; |
771 sb_line_T *line; | |
771 | 772 |
772 /* do not store empty cells at the end */ | 773 /* do not store empty cells at the end */ |
773 for (i = 0; i < cols; ++i) | 774 for (i = 0; i < cols; ++i) |
774 if (cells[i].chars[0] != 0) | 775 if (cells[i].chars[0] != 0) |
775 len = i + 1; | 776 len = i + 1; |
776 | 777 |
777 p = (VTermScreenCell *)alloc((int)sizeof(VTermScreenCell) * len); | 778 if (len > 0) |
779 p = (VTermScreenCell *)alloc((int)sizeof(VTermScreenCell) * len); | |
778 if (p != NULL) | 780 if (p != NULL) |
779 { | 781 mch_memmove(p, cells, sizeof(VTermScreenCell) * len); |
780 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data | 782 |
783 line = (sb_line_T *)term->tl_scrollback.ga_data | |
781 + term->tl_scrollback.ga_len; | 784 + term->tl_scrollback.ga_len; |
782 | 785 line->sb_cols = len; |
783 mch_memmove(p, cells, sizeof(VTermScreenCell) * len); | 786 line->sb_cells = p; |
784 line->sb_cols = len; | 787 ++term->tl_scrollback.ga_len; |
785 line->sb_cells = p; | |
786 ++term->tl_scrollback.ga_len; | |
787 } | |
788 } | 788 } |
789 return 0; /* ignored */ | 789 return 0; /* ignored */ |
790 } | 790 } |
791 | 791 |
792 /* | 792 /* |
816 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col) | 816 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col) |
817 if (vterm_screen_get_cell(screen, pos, &cell) != 0 | 817 if (vterm_screen_get_cell(screen, pos, &cell) != 0 |
818 && cell.chars[0] != NUL) | 818 && cell.chars[0] != NUL) |
819 len = pos.col + 1; | 819 len = pos.col + 1; |
820 | 820 |
821 if (len > 0) | 821 if (len == 0) |
822 ++lines_skipped; | |
823 else | |
822 { | 824 { |
823 while (lines_skipped > 0) | 825 while (lines_skipped > 0) |
824 { | 826 { |
825 /* Line was skipped, add an empty line. */ | 827 /* Line was skipped, add an empty line. */ |
826 --lines_skipped; | 828 --lines_skipped; |
863 { | 865 { |
864 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data + lnum; | 866 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data + lnum; |
865 | 867 |
866 ga.ga_len = 0; | 868 ga.ga_len = 0; |
867 for (col = 0; col < line->sb_cols; ++col) | 869 for (col = 0; col < line->sb_cols; ++col) |
868 for (i = 0; (c = line->sb_cells[col].chars[i]) != 0 || i == 0; ++i) | 870 { |
869 { | 871 if (ga_grow(&ga, MB_MAXBYTES) == FAIL) |
870 if (ga_grow(&ga, MB_MAXBYTES) == FAIL) | 872 goto failed; |
871 goto failed; | 873 for (i = 0; (c = line->sb_cells[col].chars[i]) > 0 || i == 0; ++i) |
872 ga.ga_len += mb_char2bytes(c == NUL ? ' ' : c, | 874 ga.ga_len += mb_char2bytes(c == NUL ? ' ' : c, |
873 (char_u *)ga.ga_data + ga.ga_len); | 875 (char_u *)ga.ga_data + ga.ga_len); |
874 } | 876 } |
877 if (ga_grow(&ga, 1) == FAIL) | |
878 goto failed; | |
875 *((char_u *)ga.ga_data + ga.ga_len) = NUL; | 879 *((char_u *)ga.ga_data + ga.ga_len) = NUL; |
876 ml_append_buf(term->tl_buffer, lnum, ga.ga_data, ga.ga_len + 1, FALSE); | 880 ml_append_buf(term->tl_buffer, lnum, ga.ga_data, ga.ga_len + 1, FALSE); |
877 } | 881 } |
878 | 882 |
879 /* Delete the empty line that was in the empty buffer. */ | 883 /* Delete the empty line that was in the empty buffer. */ |