Mercurial > vim
comparison src/textprop.c @ 30233:8d660a45299f v9.0.0452
patch 9.0.0452: Visual highlighting extends into virtual text prop
Commit: https://github.com/vim/vim/commit/6eda17d881c9b2880ccb2a4d11951939a58f233d
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 12 19:25:11 2022 +0100
patch 9.0.0452: Visual highlighting extends into virtual text prop
Problem: Visual highlighting extends into virtual text prop.
Solution: Do not highlight what isn't actually selected. Fix ordering of
stored text props.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 12 Sep 2022 20:30:06 +0200 |
parents | 0d084880276a |
children | 8f85b5c45432 |
comparison
equal
deleted
inserted
replaced
30232:b0eb842f1c15 | 30233:8d660a45299f |
---|---|
230 text = NULL; | 230 text = NULL; |
231 } | 231 } |
232 | 232 |
233 for (lnum = start_lnum; lnum <= end_lnum; ++lnum) | 233 for (lnum = start_lnum; lnum <= end_lnum; ++lnum) |
234 { | 234 { |
235 colnr_T col; // start column | 235 colnr_T col; // start column use in tp_col |
236 long length; // in bytes | 236 colnr_T sort_col; // column where it appears |
237 long length; // in bytes | |
237 | 238 |
238 // Fetch the line to get the ml_line_len field updated. | 239 // Fetch the line to get the ml_line_len field updated. |
239 proplen = get_text_props(buf, lnum, &props, TRUE); | 240 proplen = get_text_props(buf, lnum, &props, TRUE); |
240 textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T); | 241 textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T); |
241 | 242 |
246 if (col - 1 > (colnr_T)textlen && !(col == 0 && text_arg != NULL)) | 247 if (col - 1 > (colnr_T)textlen && !(col == 0 && text_arg != NULL)) |
247 { | 248 { |
248 semsg(_(e_invalid_column_number_nr), (long)start_col); | 249 semsg(_(e_invalid_column_number_nr), (long)start_col); |
249 goto theend; | 250 goto theend; |
250 } | 251 } |
252 sort_col = col; | |
251 | 253 |
252 if (lnum == end_lnum) | 254 if (lnum == end_lnum) |
253 length = end_col - col; | 255 length = end_col - col; |
254 else | 256 else |
255 length = (int)textlen - col + 1; | 257 length = (int)textlen - col + 1; |
261 if (text_arg != NULL) | 263 if (text_arg != NULL) |
262 { | 264 { |
263 length = 1; // text is placed on one character | 265 length = 1; // text is placed on one character |
264 if (col == 0) | 266 if (col == 0) |
265 { | 267 { |
266 col = MAXCOL; // after the line | 268 col = MAXCOL; // before or after the line |
269 if ((text_flags & TP_FLAG_ALIGN_ABOVE) == 0) | |
270 sort_col = MAXCOL; | |
267 length += text_padding_left; | 271 length += text_padding_left; |
268 } | 272 } |
269 } | 273 } |
270 | 274 |
271 // Allocate the new line with space for the new property. | 275 // Allocate the new line with space for the new property. |
278 // Find the index where to insert the new property. | 282 // Find the index where to insert the new property. |
279 // Since the text properties are not aligned properly when stored with | 283 // Since the text properties are not aligned properly when stored with |
280 // the text, we need to copy them as bytes before using it as a struct. | 284 // the text, we need to copy them as bytes before using it as a struct. |
281 for (i = 0; i < proplen; ++i) | 285 for (i = 0; i < proplen; ++i) |
282 { | 286 { |
287 colnr_T prop_col; | |
288 | |
283 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T), | 289 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T), |
284 sizeof(textprop_T)); | 290 sizeof(textprop_T)); |
285 if (tmp_prop.tp_col >= col) | 291 // col is MAXCOL when the text goes above or after the line, when |
292 // above we should use column zero for sorting | |
293 prop_col = (tmp_prop.tp_flags & TP_FLAG_ALIGN_ABOVE) | |
294 ? 0 : tmp_prop.tp_col; | |
295 if (prop_col >= sort_col) | |
286 break; | 296 break; |
287 } | 297 } |
288 newprops = newtext + textlen; | 298 newprops = newtext + textlen; |
289 if (i > 0) | 299 if (i > 0) |
290 mch_memmove(newprops, props, sizeof(textprop_T) * i); | 300 mch_memmove(newprops, props, sizeof(textprop_T) * i); |