Mercurial > vim
comparison src/charset.c @ 29816:bbe62ea78aac v9.0.0247
patch 9.0.0247: cannot add padding to virtual text without highlight
Commit: https://github.com/vim/vim/commit/f396ce83eebf6c61596184231d39ce4d41eeac04
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 23 18:39:37 2022 +0100
patch 9.0.0247: cannot add padding to virtual text without highlight
Problem: Cannot add padding to virtual text without highlight.
Solution: Add the "text_padding_left" argument. (issue https://github.com/vim/vim/issues/10906)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 23 Aug 2022 19:45:05 +0200 |
parents | b167c91b5f6b |
children | e6e0f1c39edb |
comparison
equal
deleted
inserted
replaced
29815:9941dc321348 | 29816:bbe62ea78aac |
---|---|
955 cts->cts_line = line; | 955 cts->cts_line = line; |
956 cts->cts_ptr = ptr; | 956 cts->cts_ptr = ptr; |
957 #ifdef FEAT_PROP_POPUP | 957 #ifdef FEAT_PROP_POPUP |
958 if (lnum > 0) | 958 if (lnum > 0) |
959 { | 959 { |
960 char_u *prop_start; | 960 char_u *prop_start; |
961 | 961 int count; |
962 cts->cts_text_prop_count = get_text_props(wp->w_buffer, lnum, | 962 |
963 &prop_start, FALSE); | 963 count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE); |
964 if (cts->cts_text_prop_count > 0) | 964 cts->cts_text_prop_count = count; |
965 if (count > 0) | |
965 { | 966 { |
966 // Make a copy of the properties, so that they are properly | 967 // Make a copy of the properties, so that they are properly |
967 // aligned. | 968 // aligned. Make it twice as long for the sorting below. |
968 cts->cts_text_props = ALLOC_MULT(textprop_T, | 969 cts->cts_text_props = ALLOC_MULT(textprop_T, count * 2); |
969 cts->cts_text_prop_count); | |
970 if (cts->cts_text_props == NULL) | 970 if (cts->cts_text_props == NULL) |
971 cts->cts_text_prop_count = 0; | 971 cts->cts_text_prop_count = 0; |
972 else | 972 else |
973 { | 973 { |
974 int i; | 974 int i; |
975 | 975 |
976 mch_memmove(cts->cts_text_props, prop_start, | 976 mch_memmove(cts->cts_text_props + count, prop_start, |
977 cts->cts_text_prop_count * sizeof(textprop_T)); | 977 count * sizeof(textprop_T)); |
978 for (i = 0; i < cts->cts_text_prop_count; ++i) | 978 for (i = 0; i < count; ++i) |
979 if (cts->cts_text_props[i].tp_id < 0) | 979 if (cts->cts_text_props[i + count].tp_id < 0) |
980 { | 980 { |
981 cts->cts_has_prop_with_text = TRUE; | 981 cts->cts_has_prop_with_text = TRUE; |
982 break; | 982 break; |
983 } | 983 } |
984 if (!cts->cts_has_prop_with_text) | 984 if (!cts->cts_has_prop_with_text) |
985 { | 985 { |
986 // won't use the text properties, free them | 986 // won't use the text properties, free them |
987 VIM_CLEAR(cts->cts_text_props); | 987 VIM_CLEAR(cts->cts_text_props); |
988 cts->cts_text_prop_count = 0; | 988 cts->cts_text_prop_count = 0; |
989 } | |
990 else | |
991 { | |
992 int *text_prop_idxs; | |
993 | |
994 // Need to sort the array to get any truncation right. | |
995 // Do the sorting in the second part of the array, then | |
996 // move the sorted props to the first part of the array. | |
997 text_prop_idxs = ALLOC_MULT(int, count); | |
998 if (text_prop_idxs != NULL) | |
999 { | |
1000 for (i = 0; i < count; ++i) | |
1001 text_prop_idxs[i] = i + count; | |
1002 sort_text_props(curbuf, cts->cts_text_props, | |
1003 text_prop_idxs, count); | |
1004 // Here we want the reverse order. | |
1005 for (i = 0; i < count; ++i) | |
1006 cts->cts_text_props[count - i - 1] = | |
1007 cts->cts_text_props[text_prop_idxs[i]]; | |
1008 vim_free(text_prop_idxs); | |
1009 } | |
989 } | 1010 } |
990 } | 1011 } |
991 } | 1012 } |
992 } | 1013 } |
993 #endif | 1014 #endif |
1157 int charlen = *s == NUL ? 1 : mb_ptr2len(s); | 1178 int charlen = *s == NUL ? 1 : mb_ptr2len(s); |
1158 int i; | 1179 int i; |
1159 int col = (int)(s - line); | 1180 int col = (int)(s - line); |
1160 garray_T *gap = &wp->w_buffer->b_textprop_text; | 1181 garray_T *gap = &wp->w_buffer->b_textprop_text; |
1161 | 1182 |
1183 // The "$" for 'list' mode will go between the EOL and | |
1184 // the text prop, account for that. | |
1185 if (wp->w_p_list && wp->w_lcs_chars.eol != NUL) | |
1186 ++vcol; | |
1187 | |
1162 for (i = 0; i < cts->cts_text_prop_count; ++i) | 1188 for (i = 0; i < cts->cts_text_prop_count; ++i) |
1163 { | 1189 { |
1164 textprop_T *tp = cts->cts_text_props + i; | 1190 textprop_T *tp = cts->cts_text_props + i; |
1165 | 1191 |
1166 // Watch out for the text being deleted. "cts_text_props" is a | 1192 // Watch out for the text being deleted. "cts_text_props" is a |
1174 { | 1200 { |
1175 char_u *p = ((char_u **)gap->ga_data)[-tp->tp_id - 1]; | 1201 char_u *p = ((char_u **)gap->ga_data)[-tp->tp_id - 1]; |
1176 | 1202 |
1177 if (p != NULL) | 1203 if (p != NULL) |
1178 { | 1204 { |
1179 int cells = vim_strsize(p); | 1205 int cells; |
1180 | 1206 |
1181 if (tp->tp_col == MAXCOL) | 1207 if (tp->tp_col == MAXCOL) |
1182 { | 1208 { |
1183 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW); | 1209 int n_extra = (int)STRLEN(p); |
1184 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT); | 1210 |
1185 int wrap = (tp->tp_flags & TP_FLAG_WRAP); | 1211 cells = text_prop_position(wp, tp, |
1186 int len = (int)STRLEN(p); | 1212 (vcol + size) % wp->w_width, |
1187 int n_used = len; | 1213 &n_extra, &p, NULL, NULL); |
1188 | |
1189 // The "$" for 'list' mode will go between the EOL and | |
1190 // the text prop, account for that. | |
1191 if (wp->w_p_list && wp->w_lcs_chars.eol != NUL) | |
1192 ++vcol; | |
1193 | |
1194 // Keep in sync with where textprop_size_after_trunc() | |
1195 // is called in win_line(). | |
1196 if (!wrap) | |
1197 { | |
1198 added = wp->w_width - (vcol + size) % wp->w_width; | |
1199 cells = textprop_size_after_trunc(wp, | |
1200 below, added, p, &n_used); | |
1201 } | |
1202 if (below) | |
1203 cells += wp->w_width - (vcol + size) % wp->w_width; | |
1204 else if (right) | |
1205 { | |
1206 len = wp->w_width - vcol % wp->w_width; | |
1207 if (len > cells + size) | |
1208 // add the padding for right-alignment | |
1209 cells = len - size; | |
1210 else if (len == 0) | |
1211 // padding to right-align in the next line | |
1212 cells += cells > wp->w_width ? 0 | |
1213 :wp->w_width - cells; | |
1214 } | |
1215 #ifdef FEAT_LINEBREAK | 1214 #ifdef FEAT_LINEBREAK |
1216 no_sbr = TRUE; // don't use 'showbreak' now | 1215 no_sbr = TRUE; // don't use 'showbreak' now |
1217 #endif | 1216 #endif |
1218 } | 1217 } |
1218 else | |
1219 cells = vim_strsize(p); | |
1219 cts->cts_cur_text_width += cells; | 1220 cts->cts_cur_text_width += cells; |
1220 cts->cts_start_incl = tp->tp_flags & TP_FLAG_START_INCL; | 1221 cts->cts_start_incl = tp->tp_flags & TP_FLAG_START_INCL; |
1221 size += cells; | 1222 size += cells; |
1222 if (*s == TAB) | 1223 if (*s == TAB) |
1223 { | 1224 { |
1229 } | 1230 } |
1230 } | 1231 } |
1231 if (tp->tp_col != MAXCOL && tp->tp_col - 1 > col) | 1232 if (tp->tp_col != MAXCOL && tp->tp_col - 1 > col) |
1232 break; | 1233 break; |
1233 } | 1234 } |
1235 if (wp->w_p_list && wp->w_lcs_chars.eol != NUL) | |
1236 --vcol; | |
1234 } | 1237 } |
1235 # endif | 1238 # endif |
1236 | 1239 |
1237 # ifdef FEAT_LINEBREAK | 1240 # ifdef FEAT_LINEBREAK |
1238 c = *s; | 1241 c = *s; |