blob: 3811060df15587936292cb2fe59f0fe25eac8dff [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar45e4eea2022-12-01 18:38:02 +000078#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
79 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
80// using an attribute for the whole line
81# define LINE_ATTR
82#endif
83
Bram Moolenaar1306b362022-08-06 15:59:06 +010084// structure with variables passed between win_line() and other functions
85typedef struct {
86 int draw_state; // what to draw next
87
88 linenr_T lnum; // line number to be drawn
89
90 int startrow; // first row in the window to be drawn
91 int row; // row in the window, excl w_winrow
92 int screen_row; // row on the screen, incl w_winrow
93
94 long vcol; // virtual column, before wrapping
95 int col; // visual column on screen, after wrapping
96#ifdef FEAT_CONCEAL
97 int boguscols; // nonexistent columns added to "col" to force
98 // wrapping
Bram Moolenaarf53e0652023-02-19 14:16:02 +000099 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100100#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#ifdef FEAT_SYN_HL
103 int draw_color_col; // highlight colorcolumn
104 int *color_cols; // pointer to according columns array
105#endif
106 int eol_hl_off; // 1 if highlighted char after EOL
107
108 unsigned off; // offset in ScreenLines/ScreenAttrs
109
110 int win_attr; // background for the whole window, except
111 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100112 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100113#ifdef FEAT_SYN_HL
114 int cul_attr; // set when 'cursorline' active
115#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000116#ifdef LINE_ATTR
117 int line_attr; // for the whole line, includes 'cursorline'
118#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100119
120 int screen_line_flags; // flags for screen_line()
121
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100122 int fromcol; // start of inverting
123 int tocol; // end of inverting
124
125#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100126 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100127 int need_showbreak; // overlong line, skipping first x chars
128 int dont_use_showbreak; // do not use 'showbreak'
129#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100130#ifdef FEAT_PROP_POPUP
131 int text_prop_above_count;
132#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100133
Bram Moolenaar1306b362022-08-06 15:59:06 +0100134 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
135 int cul_screenline;
136
137 int char_attr; // attributes for the next character
138
139 int n_extra; // number of extra bytes
140 char_u *p_extra; // string of extra chars, plus NUL, only used
141 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100142 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000143 int extra_attr; // attributes for p_extra, should be combined
144 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000145 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100146 int c_extra; // extra chars, all the same
147 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000148 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100149
150 // saved "extra" items for when draw_state becomes WL_LINE (again)
151 int saved_n_extra;
152 char_u *saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000153 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000154 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000155 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100156 int saved_c_extra;
157 int saved_c_final;
158 int saved_char_attr;
159
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100160 char_u extra[NUMBUFLEN + MB_MAXBYTES];
161 // "%ld " and 'fdc' must fit in here, as well
162 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100163
Bram Moolenaar1306b362022-08-06 15:59:06 +0100164#ifdef FEAT_DIFF
165 hlf_T diff_hlf; // type of diff highlighting
166#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100167 int filler_lines; // nr of filler lines to be drawn
168 int filler_todo; // nr of filler lines still to do + 1
169#ifdef FEAT_SIGNS
170 sign_attrs_T sattr;
171#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100172} winlinevars_T;
173
174// draw_state values for items that are drawn in sequence:
175#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100176#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100177#ifdef FEAT_FOLDING
178# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
179#else
180# define WL_FOLD WL_CMDLINE
181#endif
182#ifdef FEAT_SIGNS
183# define WL_SIGN (WL_FOLD + 1) // column for signs
184#else
185# define WL_SIGN WL_FOLD // column for signs
186#endif
187#define WL_NR (WL_SIGN + 1) // line number
188#ifdef FEAT_LINEBREAK
189# define WL_BRI (WL_NR + 1) // 'breakindent'
190#else
191# define WL_BRI WL_NR
192#endif
193#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
194# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
195#else
196# define WL_SBR WL_BRI
197#endif
198#define WL_LINE (WL_SBR + 1) // text in the line
199
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100200#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200201/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 * Return TRUE if CursorLineSign highlight is to be used.
203 */
204 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100205use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000206{
207 return wp->w_p_cul
208 && lnum == wp->w_cursor.lnum
209 && (wp->w_p_culopt_flags & CULOPT_NBR);
210}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100211#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000212
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100213
214#ifdef FEAT_FOLDING
215/*
216 * Setup for drawing the 'foldcolumn', if there is one.
217 */
218 static void
219handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
220{
221 int fdc = compute_foldcolumn(wp, 0);
222
223 if (fdc <= 0)
224 return;
225
226 // Allocate a buffer, "wlv->extra[]" may already be in use.
227 vim_free(wlv->p_extra_free);
228 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000229 if (wlv->p_extra_free == NULL)
230 return;
231
232 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
233 wp, FALSE, wlv->lnum);
234 wlv->p_extra_free[wlv->n_extra] = NUL;
235 wlv->p_extra = wlv->p_extra_free;
236 wlv->c_extra = NUL;
237 wlv->c_final = NUL;
238 if (use_cursor_line_highlight(wp, wlv->lnum))
239 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
240 else
241 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100242}
243#endif
244
245#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000246/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100247 * Get information needed to display the sign in line "wlv->lnum" in window
248 * "wp".
249 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200250 * Otherwise the sign is going to be displayed in the sign column.
251 */
252 static void
253get_sign_display_info(
254 int nrcol,
255 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200257{
258 int text_sign;
259# ifdef FEAT_SIGN_ICONS
260 int icon_sign;
261# endif
262
263 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->c_extra = ' ';
265 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100267 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200268 else
269 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100270 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100271 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000272 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100273 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276
Bram Moolenaar1306b362022-08-06 15:59:06 +0100277 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200278#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100279 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200280#endif
281 )
282 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100283 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200284# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100285 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200286 if (gui.in_use && icon_sign != 0)
287 {
288 // Use the image in this position.
289 if (nrcol)
290 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100291 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100292 sprintf((char *)wlv->extra, "%-*c ",
293 number_width(wp), SIGN_BYTE);
294 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100295 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296 }
297 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200299# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100300 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
301 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200302 {
303 if (nrcol)
304 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100305 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100306 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100308 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100309 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200310 }
311 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100312 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200313 }
314# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100315 wlv->c_final = NUL;
316 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317 }
318 else
319# endif
320 if (text_sign != 0)
321 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100322 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100323 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200324 {
325 if (nrcol)
326 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100327 int width = number_width(wp) - 2;
328 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200329
330 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100331 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100332 vim_snprintf((char *)wlv->extra + n,
333 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100334 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200335 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100336 wlv->c_extra = NUL;
337 wlv->c_final = NUL;
338 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200339 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000340
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100341 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100342 && wlv->sattr.sat_culhl > 0)
343 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000344 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100345 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200346 }
347 }
348}
349#endif
350
Bram Moolenaard7657e92022-09-20 18:59:30 +0100351/*
352 * Display the absolute or relative line number. After the first row fill with
353 * blanks when the 'n' flag isn't in 'cpo'.
354 */
355 static void
356handle_lnum_col(
357 win_T *wp,
358 winlinevars_T *wlv,
359 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100360 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100361{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100362 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100363 int lnum_row = wlv->startrow + wlv->filler_lines
364#ifdef FEAT_PROP_POPUP
365 + wlv->text_prop_above_count
366#endif
367 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100368
Bram Moolenaard7657e92022-09-20 18:59:30 +0100369 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100370 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100371 // there is no line number in a wrapped line when "n" is in
372 // 'cpoptions', but 'breakindent' assumes it anyway.
373 && !((has_cpo_n
374#ifdef FEAT_LINEBREAK
375 && !wp->w_p_bri
376#endif
377 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100378 {
379#ifdef FEAT_SIGNS
380 // If 'signcolumn' is set to 'number' and a sign is present
381 // in 'lnum', then display the sign instead of the line
382 // number.
383 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
384 get_sign_display_info(TRUE, wp, wlv);
385 else
386#endif
387 {
388 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100389 // When there are text properties above the line put the line number
390 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100391 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100392 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100393 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100394 {
395 long num;
396 char *fmt = "%*ld ";
397
398 if (wp->w_p_nu && !wp->w_p_rnu)
399 // 'number' + 'norelativenumber'
400 num = (long)wlv->lnum;
401 else
402 {
403 // 'relativenumber', don't use negative numbers
404 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
405 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
406 {
407 // 'number' + 'relativenumber'
408 num = wlv->lnum;
409 fmt = "%-*ld ";
410 }
411 }
412
413 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100414 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100415 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
416 ++wlv->p_extra)
417 *wlv->p_extra = '-';
418#ifdef FEAT_RIGHTLEFT
419 if (wp->w_p_rl) // reverse line numbers
420 {
421 char_u *p1, *p2;
422 int t;
423
424 // like rl_mirror(), but keep the space at the end
425 p2 = skipwhite(wlv->extra);
426 p2 = skiptowhite(p2) - 1;
427 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
428 {
429 t = *p1;
430 *p1 = *p2;
431 *p2 = t;
432 }
433 }
434#endif
435 wlv->p_extra = wlv->extra;
436 wlv->c_extra = NUL;
437 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100438 }
439 else
440 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100441 wlv->c_extra = ' ';
442 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100443 }
444 wlv->n_extra = number_width(wp) + 1;
445 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
446#ifdef FEAT_SYN_HL
447 // When 'cursorline' is set highlight the line number of
448 // the current line differently.
449 // When 'cursorlineopt' does not have "line" only
450 // highlight the line number itself.
451 // TODO: Can we use CursorLine instead of CursorLineNr
452 // when CursorLineNr isn't set?
453 if (wp->w_p_cul
454 && wlv->lnum == wp->w_cursor.lnum
455 && (wp->w_p_culopt_flags & CULOPT_NBR)
456 && (wlv->row == wlv->startrow + wlv->filler_lines
457 || (wlv->row > wlv->startrow + wlv->filler_lines
458 && (wp->w_p_culopt_flags & CULOPT_LINE))))
459 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
460#endif
461 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
462 && HL_ATTR(HLF_LNA) != 0)
463 // Use LineNrAbove
464 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
465 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
466 && HL_ATTR(HLF_LNB) != 0)
467 // Use LineNrBelow
468 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
469 }
470#ifdef FEAT_SIGNS
471 if (num_attr)
472 wlv->char_attr = num_attr;
473#endif
474 }
475}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100476
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100477#ifdef FEAT_LINEBREAK
478 static void
479handle_breakindent(win_T *wp, winlinevars_T *wlv)
480{
481 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100482 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100483 // draw indent after showbreak value
484 wlv->draw_state = WL_BRI;
485 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
486 // After the showbreak, draw the breakindent
487 wlv->draw_state = WL_BRI - 1;
488
489 // draw 'breakindent': indent wrapped text accordingly
490 if (wlv->draw_state == WL_BRI - 1)
491 {
492 wlv->draw_state = WL_BRI;
493 // if wlv->need_showbreak is set, breakindent also applies
494 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
495# ifdef FEAT_DIFF
496 && wlv->filler_lines == 0
497# endif
498# ifdef FEAT_PROP_POPUP
499 && !wlv->dont_use_showbreak
500# endif
501 )
502 {
503 wlv->char_attr = 0;
504# ifdef FEAT_DIFF
505 if (wlv->diff_hlf != (hlf_T)0)
506 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
507# endif
508 wlv->p_extra = NULL;
509 wlv->c_extra = ' ';
510 wlv->c_final = NUL;
511 wlv->n_extra = get_breakindent_win(wp,
512 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
513 if (wlv->row == wlv->startrow)
514 {
515 wlv->n_extra -= win_col_off2(wp);
516 if (wlv->n_extra < 0)
517 wlv->n_extra = 0;
518 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100519 if (wp->w_skipcol > 0 && wlv->startrow == 0
520 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100521 wlv->need_showbreak = FALSE;
522 // Correct end of highlighted area for 'breakindent',
523 // required when 'linebreak' is also set.
524 if (wlv->tocol == wlv->vcol)
525 wlv->tocol += wlv->n_extra;
526 }
527 }
528}
529#endif
530
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100531#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
532 static void
533handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
534{
535# ifdef FEAT_DIFF
536 if (wlv->filler_todo > 0)
537 {
538 // Draw "deleted" diff line(s).
539 if (char2cells(wp->w_fill_chars.diff) > 1)
540 {
541 wlv->c_extra = '-';
542 wlv->c_final = NUL;
543 }
544 else
545 {
546 wlv->c_extra = wp->w_fill_chars.diff;
547 wlv->c_final = NUL;
548 }
549# ifdef FEAT_RIGHTLEFT
550 if (wp->w_p_rl)
551 wlv->n_extra = wlv->col + 1;
552 else
553# endif
554 wlv->n_extra = wp->w_width - wlv->col;
555 wlv->char_attr = HL_ATTR(HLF_DED);
556 }
557# endif
558
559# ifdef FEAT_LINEBREAK
560 char_u *sbr = get_showbreak_value(wp);
561 if (*sbr != NUL && wlv->need_showbreak)
562 {
563 // Draw 'showbreak' at the start of each broken line.
564 wlv->p_extra = sbr;
565 wlv->c_extra = NUL;
566 wlv->c_final = NUL;
567 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100568 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100569 wlv->need_showbreak = FALSE;
570 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
571 // Correct end of highlighted area for 'showbreak',
572 // required when 'linebreak' is also set.
573 if (wlv->tocol == wlv->vcol)
574 wlv->tocol += wlv->n_extra;
575 // combine 'showbreak' with 'wincolor'
576 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
577# ifdef FEAT_SYN_HL
578 // combine 'showbreak' with 'cursorline'
579 if (wlv->cul_attr != 0)
580 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
581# endif
582 }
583# endif
584}
585#endif
586
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100587#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100588/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100589 * Return the cell size of virtual text after truncation.
590 */
591 static int
592textprop_size_after_trunc(
593 win_T *wp,
594 int flags, // TP_FLAG_ALIGN_*
595 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100596 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100597 char_u *text,
598 int *n_used_ptr)
599{
600 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100601 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100602 int len = (int)STRLEN(text);
603 int strsize = 0;
604 int n_used;
605
Bram Moolenaar7e017462022-10-11 21:02:09 +0100606 // if the remaining size is to small and 'wrap' is set we wrap anyway and
607 // use the next line
608 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100609 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100610 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100611 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100612 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
613 {
614 int clen = ptr2cells(text + n_used);
615
616 if (strsize + clen > space)
617 break;
618 strsize += clen;
619 }
620 *n_used_ptr = n_used;
621 return strsize;
622}
623
624/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100625 * Take care of padding, right-align and truncation of virtual text after a
626 * line.
627 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
628 * padding, right-align and truncation. Otherwise only the size is computed.
629 * When "n_attr" is NULL returns the number of screen cells used.
630 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100631 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100632 int
633text_prop_position(
634 win_T *wp,
635 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000636 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100637 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100638 int *n_extra, // nr of bytes for virtual text
639 char_u **p_extra, // virtual text
640 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000641 int *n_attr_skip, // cells to skip attr, NULL if not used
642 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200643{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100644 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100645 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100646 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000647 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100648 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000649 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100650 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100651 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100652 int before = room; // spaces before the text
653 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 int n_used = *n_extra;
655 char_u *l = NULL;
656 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100657 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100658 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200659
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100660 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100661 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100662 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100663
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100665 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100666 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100667 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100668 if (after < 0)
669 {
670 // text "above" has too much padding to fit
671 padding += after;
672 after = 0;
673 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 }
675 else
676 {
677 // Right-align: fill with before
678 if (right)
679 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000680
681 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000682 if (below && vcol == 0 && col_with_padding == col_off
683 && wp->w_width - col_off == before)
684 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000685
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 if (before < 0
687 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000688 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
689 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100690 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100691 if (right && (wrap
692 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100693 {
694 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100695 before = wp->w_width - col_off - strsize + room;
696 if (before < 0)
697 before = 0;
698 else
699 n_used = *n_extra;
700 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000701 else if (below && before > vcol && do_skip)
702 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100703 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100704 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100705 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100706 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100707
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100708 // With 'nowrap' add one to show the "extends" character if needed (it
709 // doesn't show if the text just fits).
710 if (!wp->w_p_wrap
711 && n_used < *n_extra
712 && wp->w_lcs_chars.ext != NUL
713 && wp->w_p_list)
714 ++n_used;
715
716 // add 1 for NUL, 2 for when '…' is used
717 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100718 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100719 if (n_attr == NULL || l != NULL)
720 {
721 int off = 0;
722
723 if (n_attr != NULL)
724 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100725 vim_memset(l, ' ', before);
726 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 if (padding > 0)
728 {
729 vim_memset(l + off, ' ', padding);
730 off += padding;
731 }
732 vim_strncpy(l + off, *p_extra, n_used);
733 off += n_used;
734 }
735 else
736 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100737 off = before + after + padding + n_used;
738 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100739 }
740 if (n_attr != NULL)
741 {
742 if (n_used < *n_extra && wp->w_p_wrap)
743 {
744 char_u *lp = l + off - 1;
745
746 if (has_mbyte)
747 {
h-east4c42c7e2023-04-17 21:44:57 +0100748 char_u buf[MB_MAXBYTES + 1];
749 char_u *cp = buf;
750
751 // change the last character to '…', converted to the
752 // current 'encoding'
753 STRCPY(buf, "…");
754 if (!enc_utf8)
755 {
756 vimconv_T vc;
757
758 vc.vc_type = CONV_NONE;
759 convert_setup(&vc, (char_u *)"utf-8", p_enc);
760 if (vc.vc_type != CONV_NONE)
761 {
762 cp = string_convert(&vc, buf, NULL);
763 if (cp == NULL)
764 {
765 // when conversion fails use '>'
766 cp = buf;
767 STRCPY(buf, ">");
768 }
769 convert_setup(&vc, NULL, NULL);
770 }
771 }
772
773 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100774 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100775 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100776 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100777 if (cp != buf)
778 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100779 }
780 else
781 // change last character to '>'
782 *lp = '>';
783 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100784 else if (after > 0)
785 {
786 vim_memset(l + off, ' ', after);
787 l[off + after] = NUL;
788 }
789
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100790 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100791 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100792 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100793 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100794 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100795
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000796 // n_attr_skip will not be decremented before draw_state is
797 // WL_LINE
798 *n_attr_skip = before + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100799 }
800 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100801 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100802
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100803 if (n_attr == NULL)
804 return cells;
805 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200806}
807#endif
808
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100809/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100810 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100811 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
812 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100813 */
814 static void
815wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
816{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100817 if (wlv->row == 0 && wp->w_skipcol > 0
818#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100819 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100820 && *get_showbreak_value(wp) == NUL
821#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100822 // do not overwrite the 'listchars' "precedes" text with "<<<"
823 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100824 {
825 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100826 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100827
Bram Moolenaareb4de622022-10-15 13:42:17 +0100828 if (wp->w_p_nu && wp->w_p_rnu)
829 // Do not overwrite the line number, change "123 text" to
830 // "123>>>xt".
831 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
832 {
833 ++off;
834 ++skip;
835 }
836
837 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100838 {
839 ScreenLines[off] = '<';
840 if (enc_utf8)
841 ScreenLinesUC[off] = 0;
842 ScreenAttrs[off] = HL_ATTR(HLF_AT);
843 ++off;
844 }
845 }
846
847 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
848 negative_width ? -wp->w_width : wp->w_width,
849 wlv->screen_line_flags);
850}
851
852/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100853 * Called when finished with the line: draw the screen line and handle any
854 * highlighting until the right of the window.
855 */
856 static void
857draw_screen_line(win_T *wp, winlinevars_T *wlv)
858{
859#ifdef FEAT_SYN_HL
860 long v;
861
862 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
863 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100864 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100865 else
866 v = wp->w_leftcol;
867
868 // check if line ends before left margin
869 if (wlv->vcol < v + wlv->col - win_col_off(wp))
870 wlv->vcol = v + wlv->col - win_col_off(wp);
871# ifdef FEAT_CONCEAL
872 // Get rid of the boguscols now, we want to draw until the right
873 // edge for 'cursorcolumn'.
874 wlv->col -= wlv->boguscols;
875 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000876# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100877# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000878# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100879# endif
880
881 if (wlv->draw_color_col)
882 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
883
884 if (((wp->w_p_cuc
885 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
886 && (int)wp->w_virtcol <
887 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
888 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000889 || wlv->draw_color_col
890# ifdef LINE_ATTR
891 || wlv->line_attr != 0
892# endif
893 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100894# ifdef FEAT_RIGHTLEFT
895 && !wp->w_p_rl
896# endif
897 )
898 {
899 int rightmost_vcol = 0;
900 int i;
901
902 if (wp->w_p_cuc)
903 rightmost_vcol = wp->w_virtcol;
904 if (wlv->draw_color_col)
905 // determine rightmost colorcolumn to possibly draw
906 for (i = 0; wlv->color_cols[i] >= 0; ++i)
907 if (rightmost_vcol < wlv->color_cols[i])
908 rightmost_vcol = wlv->color_cols[i];
909
910 while (wlv->col < wp->w_width)
911 {
912 ScreenLines[wlv->off] = ' ';
913 if (enc_utf8)
914 ScreenLinesUC[wlv->off] = 0;
915 ScreenCols[wlv->off] = MAXCOL;
916 ++wlv->col;
917 if (wlv->draw_color_col)
918 wlv->draw_color_col = advance_color_col(
919 VCOL_HLC, &wlv->color_cols);
920
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000921 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100922 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000923 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100924 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000925 attr = HL_ATTR(HLF_MC);
926# ifdef LINE_ATTR
927 else if (wlv->line_attr != 0)
928 attr = wlv->line_attr;
929# endif
930 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100931
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000932 if (VCOL_HLC >= rightmost_vcol
933# ifdef LINE_ATTR
934 && wlv->line_attr == 0
935# endif
936 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100937 break;
938
939 ++wlv->vcol;
940 }
941 }
942#endif
943
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100944 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100945 ++wlv->row;
946 ++wlv->screen_row;
947}
948#undef VCOL_HLC
949
950/*
951 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100952 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100953 */
954 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100955win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100956{
957 wlv->col = 0;
958 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
959
960#ifdef FEAT_RIGHTLEFT
961 if (wp->w_p_rl)
962 {
963 // Rightleft window: process the text in the normal direction, but put
964 // it in current_ScreenLine[] from right to left. Start at the
965 // rightmost column of the window.
966 wlv->col = wp->w_width - 1;
967 wlv->off += wlv->col;
968 wlv->screen_line_flags |= SLF_RIGHTLEFT;
969 }
970#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100971 if (save_extra)
972 {
973 // reset the drawing state for the start of a wrapped line
974 wlv->draw_state = WL_START;
975 wlv->saved_n_extra = wlv->n_extra;
976 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000977 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000978 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000979 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100980 wlv->saved_c_extra = wlv->c_extra;
981 wlv->saved_c_final = wlv->c_final;
982#ifdef FEAT_SYN_HL
983 if (!(wlv->cul_screenline
984# ifdef FEAT_DIFF
985 && wlv->diff_hlf == (hlf_T)0
986# endif
987 ))
988 wlv->saved_char_attr = wlv->char_attr;
989 else
990#endif
991 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000992
993 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +0100994 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000995 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100996 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100997}
998
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001000 * Called when wlv->draw_state is set to WL_LINE.
1001 */
1002 static void
1003win_line_continue(winlinevars_T *wlv)
1004{
1005 if (wlv->saved_n_extra > 0)
1006 {
1007 // Continue item from end of wrapped line.
1008 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001009 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001010 wlv->c_extra = wlv->saved_c_extra;
1011 wlv->c_final = wlv->saved_c_final;
1012 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001013 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001014 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001015 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001016 wlv->char_attr = wlv->saved_char_attr;
1017 }
1018 else
1019 wlv->char_attr = wlv->win_attr;
1020}
1021
zeertzjqb7acea12022-12-12 13:20:43 +00001022#ifdef FEAT_SYN_HL
1023 static void
1024apply_cursorline_highlight(
1025 winlinevars_T *wlv,
1026 int sign_present UNUSED)
1027{
1028 wlv->cul_attr = HL_ATTR(HLF_CUL);
1029# ifdef FEAT_SIGNS
1030 // Combine the 'cursorline' and sign highlighting, depending on
1031 // the sign priority.
1032 if (sign_present && wlv->sattr.sat_linehl > 0)
1033 {
1034 if (wlv->sattr.sat_priority >= 100)
1035 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1036 else
1037 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1038 }
1039 else
1040# endif
1041# if defined(FEAT_QUICKFIX)
1042 // let the line attribute overrule 'cursorline', otherwise
1043 // it disappears when both have background set;
1044 // 'cursorline' can use underline or bold to make it show
1045 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1046# else
1047 wlv->line_attr = wlv->cul_attr;
1048# endif
1049}
1050#endif
1051
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001052/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001053 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001054 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001055 * When "number_only" is TRUE only update the number column.
1056 * "spv" is used to store information for spell checking, kept between
1057 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058 * wp->w_virtcol needs to be valid.
1059 *
1060 * Return the number of last row the line occupies.
1061 */
1062 int
1063win_line(
1064 win_T *wp,
1065 linenr_T lnum,
1066 int startrow,
1067 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001068 int number_only,
1069 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001070{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001071 winlinevars_T wlv; // variables passed between functions
1072
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001073 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001074 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075 char_u *line; // current line
1076 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077
Bram Moolenaar1306b362022-08-06 15:59:06 +01001078#ifdef FEAT_PROP_POPUP
1079 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1080#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001081#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001082 int in_linebreak = FALSE; // n_extra set for showing linebreak
1083#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001084 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001085 // displaying eol at end-of-line
1086 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001087 int lcs_prec_todo = wp->w_lcs_chars.prec;
1088 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001090 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001091 int saved_attr2 = 0; // char_attr saved for n_attr
1092 int n_attr3 = 0; // chars with overruling special attr
1093 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001094
Bram Moolenaarcd105412022-10-10 19:50:42 +01001095 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1096 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001097#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001098 int skip_cells = 0; // nr of cells to skip for virtual text
1099 // after the line, when w_skipcol is
1100 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001101#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001102
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001103 int fromcol_prev = -2; // start of inverting after cursor
1104 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001105 int lnum_in_visual_area = FALSE;
1106 pos_T pos;
1107 long v;
1108
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109 int attr_pri = FALSE; // char_attr has priority
1110 int area_highlighting = FALSE; // Visual or incsearch highlighting
1111 // in this line
1112 int vi_attr = 0; // attributes for Visual and incsearch
1113 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114 int area_attr = 0; // attributes desired by highlighting
1115 int search_attr = 0; // attributes desired by 'hlsearch'
1116#ifdef FEAT_SYN_HL
1117 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1118 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001119 int prev_syntax_col = -1; // column of prev_syntax_attr
1120 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001121 int has_syntax = FALSE; // this buffer has syntax highl.
1122 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001124#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001125 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001126 int text_prop_count;
1127 int text_prop_next = 0; // next text property to use
1128 textprop_T *text_props = NULL;
1129 int *text_prop_idxs = NULL;
1130 int text_props_active = 0;
1131 proptype_T *text_prop_type = NULL;
1132 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001133 int text_prop_attr_comb = 0; // text_prop_attr combined with
1134 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001135 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001136 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001137 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001138 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001139 int saved_search_attr = 0; // search_attr to be used when n_extra
1140 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001141 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001142 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143#endif
1144#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001145 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001146# define SPWORDLEN 150
1147 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1148 int nextlinecol = 0; // column where nextline[] starts
1149 int nextline_idx = 0; // index in nextline[] where next line
1150 // starts
1151 int spell_attr = 0; // attributes desired by spelling
1152 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153 int cur_checked_col = 0; // checked column for current line
1154#endif
1155 int extra_check = 0; // has extra highlighting
1156 int multi_attr = 0; // attributes desired by multibyte
1157 int mb_l = 1; // multi-byte byte length
1158 int mb_c = 0; // decoded multi-byte character
1159 int mb_utf8 = FALSE; // screen char is UTF-8 char
1160 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162 int change_start = MAXCOL; // first col of changed area
1163 int change_end = -1; // last col of changed area
1164#endif
1165 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001166 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001167 int in_multispace = FALSE; // in multiple consecutive spaces
1168 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001169#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001170 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001171#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001172 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001173 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001174#ifdef FEAT_ARABIC
1175 int prev_c = 0; // previous Arabic character
1176 int prev_c1 = 0; // first composing char for prev_c
1177#endif
1178#if defined(LINE_ATTR)
1179 int did_line_attr = 0;
1180#endif
1181#ifdef FEAT_TERMINAL
1182 int get_term_attr = FALSE;
1183#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001184
Martin Tournoijba43e762022-10-13 22:12:15 +01001185#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186 // margin columns for the screen line, needed for when 'cursorlineopt'
1187 // contains "screenline"
1188 int left_curline_col = 0;
1189 int right_curline_col = 0;
1190#endif
1191
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001192#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1193 int feedback_col = 0;
1194 int feedback_old_attr = -1;
1195#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196
1197#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1198 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001199#endif
1200#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001201 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001202#endif
1203#ifdef FEAT_CONCEAL
1204 int syntax_flags = 0;
1205 int syntax_seqnr = 0;
1206 int prev_syntax_id = 0;
1207 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1208 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209 int did_wcol = FALSE;
1210 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001211# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001212# define FIX_FOR_BOGUSCOLS \
1213 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001214 wlv.n_extra += wlv.vcol_off_co; \
1215 wlv.vcol -= wlv.vcol_off_co; \
1216 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001217 wlv.col -= wlv.boguscols; \
1218 old_boguscols = wlv.boguscols; \
1219 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220 }
1221#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001222# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223#endif
1224
1225 if (startrow > endrow) // past the end already!
1226 return startrow;
1227
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001228 CLEAR_FIELD(wlv);
1229
1230 wlv.lnum = lnum;
1231 wlv.startrow = startrow;
1232 wlv.row = startrow;
1233 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001234 wlv.fromcol = -10;
1235 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001236#ifdef FEAT_LINEBREAK
1237 wlv.vcol_sbr = -1;
1238#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239
1240 if (!number_only)
1241 {
1242 // To speed up the loop below, set extra_check when there is linebreak,
1243 // trailing white space and/or syntax processing to be done.
1244#ifdef FEAT_LINEBREAK
1245 extra_check = wp->w_p_lbr;
1246#endif
1247#ifdef FEAT_SYN_HL
1248 if (syntax_present(wp) && !wp->w_s->b_syn_error
1249# ifdef SYN_TIME_LIMIT
1250 && !wp->w_s->b_syn_slow
1251# endif
1252 )
1253 {
1254 // Prepare for syntax highlighting in this line. When there is an
1255 // error, stop syntax highlighting.
1256 save_did_emsg = did_emsg;
1257 did_emsg = FALSE;
1258 syntax_start(wp, lnum);
1259 if (did_emsg)
1260 wp->w_s->b_syn_error = TRUE;
1261 else
1262 {
1263 did_emsg = save_did_emsg;
1264#ifdef SYN_TIME_LIMIT
1265 if (!wp->w_s->b_syn_slow)
1266#endif
1267 {
1268 has_syntax = TRUE;
1269 extra_check = TRUE;
1270 }
1271 }
1272 }
1273
1274 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001275 wlv.color_cols = wp->w_p_cc_cols;
1276 if (wlv.color_cols != NULL)
1277 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001278#endif
1279
1280#ifdef FEAT_TERMINAL
1281 if (term_show_buffer(wp->w_buffer))
1282 {
1283 extra_check = TRUE;
1284 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001285 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 }
1287#endif
1288
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001289 // handle Visual active in this window
1290 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1291 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001292 pos_T *top, *bot;
1293
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1295 {
1296 // Visual is after curwin->w_cursor
1297 top = &curwin->w_cursor;
1298 bot = &VIsual;
1299 }
1300 else
1301 {
1302 // Visual is before curwin->w_cursor
1303 top = &VIsual;
1304 bot = &curwin->w_cursor;
1305 }
1306 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1307 if (VIsual_mode == Ctrl_V)
1308 {
1309 // block mode
1310 if (lnum_in_visual_area)
1311 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001312 wlv.fromcol = wp->w_old_cursor_fcol;
1313 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 }
1315 }
1316 else
1317 {
1318 // non-block mode
1319 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001320 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001321 else if (lnum == top->lnum)
1322 {
1323 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001324 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325 else
1326 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001327 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001329 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 }
1331 }
1332 if (VIsual_mode != 'V' && lnum == bot->lnum)
1333 {
1334 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1335 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001336 wlv.fromcol = -10;
1337 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338 }
1339 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001340 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 else
1342 {
1343 pos = *bot;
1344 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001345 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1346 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 else
1348 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001349 getvvcol(wp, &pos, NULL, NULL,
1350 (colnr_T *)&wlv.tocol);
1351 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 }
1353 }
1354 }
1355 }
1356
1357 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001358 if (!highlight_match && lnum == curwin->w_cursor.lnum
1359 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360#ifdef FEAT_GUI
1361 && !gui.in_use
1362#endif
1363 )
1364 noinvcur = TRUE;
1365
1366 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001367 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001368 {
1369 area_highlighting = TRUE;
1370 vi_attr = HL_ATTR(HLF_V);
1371#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1372 if ((clip_star.available && !clip_star.owned
1373 && clip_isautosel_star())
1374 || (clip_plus.available && !clip_plus.owned
1375 && clip_isautosel_plus()))
1376 vi_attr = HL_ATTR(HLF_VNC);
1377#endif
1378 }
1379 }
1380
1381 // handle 'incsearch' and ":s///c" highlighting
1382 else if (highlight_match
1383 && wp == curwin
1384 && lnum >= curwin->w_cursor.lnum
1385 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1386 {
1387 if (lnum == curwin->w_cursor.lnum)
1388 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001389 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001390 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001391 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1393 {
1394 pos.lnum = lnum;
1395 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001396 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001397 }
1398 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001399 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001401 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1402 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001403 area_highlighting = TRUE;
1404 vi_attr = HL_ATTR(HLF_I);
1405 }
1406 }
1407
1408#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001409 wlv.filler_lines = diff_check(wp, lnum);
1410 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001412 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001413 {
1414 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001415 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001417 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001419 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001420 }
1421 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001422 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001423 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 area_highlighting = TRUE;
1425 }
1426 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001427 wlv.filler_lines = wp->w_topfill;
1428 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429#endif
1430
1431#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001432 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001433 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001434 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001435#endif
1436
1437#ifdef LINE_ATTR
1438# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001439 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001440 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001441 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442# endif
1443# if defined(FEAT_QUICKFIX)
1444 // Highlight the current line in the quickfix window.
1445 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001446 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001448 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449 area_highlighting = TRUE;
1450#endif
1451
1452 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1453 ptr = line;
1454
1455#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001456 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001458 // Prepare for spell checking.
1459 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460
Luuk van Baal30805a12023-05-27 22:22:10 +01001461 // When a word wrapped from the previous line the start of the
1462 // current line is valid.
1463 if (lnum == spv->spv_checked_lnum)
1464 cur_checked_col = spv->spv_checked_col;
1465 if (lnum != spv->spv_capcol_lnum)
1466 spv->spv_cap_col = -1;
1467 spv->spv_checked_lnum = 0;
1468
1469 // For checking first word with a capital skip white space.
1470 if (spv->spv_cap_col == 0)
1471 spv->spv_cap_col = getwhitecols(line);
1472 // If current line is empty, check first word in next line for capital.
1473 else if (*skipwhite(line) == NUL)
1474 {
1475 spv->spv_cap_col = 0;
1476 spv->spv_capcol_lnum = lnum + 1;
1477 }
1478
1479
1480 // Get the start of the next line, so that words that wrap to the
1481 // next line are found too: "et<line-break>al.".
1482 // Trick: skip a few chars for C/shell/Vim comments
1483 nextline[SPWORDLEN] = NUL;
1484 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1485 spell_cat_line(nextline + SPWORDLEN,
1486 ml_get_buf(wp->w_buffer, lnum + 1, FALSE), SPWORDLEN);
1487 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488 if (nextline[SPWORDLEN] == NUL)
1489 {
1490 // No next line or it is empty.
1491 nextlinecol = MAXCOL;
1492 nextline_idx = 0;
1493 }
1494 else
1495 {
1496 v = (long)STRLEN(line);
1497 if (v < SPWORDLEN)
1498 {
1499 // Short line, use it completely and append the start of the
1500 // next line.
1501 nextlinecol = 0;
1502 mch_memmove(nextline, line, (size_t)v);
1503 STRMOVE(nextline + v, nextline + SPWORDLEN);
1504 nextline_idx = v + 1;
1505 }
1506 else
1507 {
1508 // Long line, use only the last SPWORDLEN bytes.
1509 nextlinecol = v - SPWORDLEN;
1510 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1511 nextline_idx = SPWORDLEN + 1;
1512 }
1513 }
1514 }
1515#endif
1516
1517 if (wp->w_p_list)
1518 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001519 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001520 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001521 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001522 || wp->w_lcs_chars.trail
1523 || wp->w_lcs_chars.lead
1524 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001525 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001526
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001528 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001529 {
1530 trailcol = (colnr_T)STRLEN(ptr);
1531 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1532 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001533 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001535 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001536 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001537 {
1538 leadcol = 0;
1539 while (VIM_ISWHITE(ptr[leadcol]))
1540 ++leadcol;
1541 if (ptr[leadcol] == NUL)
1542 // in a line full of spaces all of them are treated as trailing
1543 leadcol = (colnr_T)0;
1544 else
1545 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001546 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001547 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001548 }
1549
Bram Moolenaard7657e92022-09-20 18:59:30 +01001550 wlv.wcr_attr = get_wcr_attr(wp);
1551 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001553 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001554 area_highlighting = TRUE;
1555 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001556
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001557 // When w_skipcol is non-zero and there is virtual text above the actual
1558 // text, then this much of the virtual text is skipped.
1559 int skipcol_in_text_prop_above = 0;
1560
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001561#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001563 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001564
1565 char_u *prop_start;
1566 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1567 if (text_prop_count > 0)
1568 {
1569 // Make a copy of the properties, so that they are properly
1570 // aligned.
1571 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1572 if (text_props != NULL)
1573 mch_memmove(text_props, prop_start,
1574 text_prop_count * sizeof(textprop_T));
1575
1576 // Allocate an array for the indexes.
1577 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1578 if (text_prop_idxs == NULL)
1579 VIM_CLEAR(text_props);
1580
1581 if (text_props != NULL)
1582 {
1583 area_highlighting = TRUE;
1584 extra_check = TRUE;
1585
1586 // When skipping virtual text the props need to be sorted. The
1587 // order is reversed!
1588 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1589 {
1590 for (int i = 0; i < text_prop_count; ++i)
1591 text_prop_idxs[i] = i;
1592 sort_text_props(wp->w_buffer, text_props,
1593 text_prop_idxs, text_prop_count);
1594 }
1595
1596 // Text props "above" move the line number down to where the text
1597 // is. Only count the ones that are visible, not those that are
1598 // skipped because of w_skipcol.
1599 int text_width = wp->w_width - win_col_off(wp);
1600 for (int i = text_prop_count - 1; i >= 0; --i)
1601 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1602 {
1603 if (lnum == wp->w_topline
1604 && wp->w_skipcol - skipcol_in_text_prop_above
1605 >= text_width)
1606 {
1607 // This virtual text above is skipped, remove it from
1608 // the array.
1609 skipcol_in_text_prop_above += text_width;
1610 for (int j = i + 1; j < text_prop_count; ++j)
1611 text_props[j - 1] = text_props[j];
1612 ++i;
1613 --text_prop_count;
1614 }
1615 else
1616 ++wlv.text_prop_above_count;
1617 }
1618 }
1619 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001620
1621 if (number_only)
1622 {
1623 // skip over rows only used for virtual text above
1624 wlv.row += wlv.text_prop_above_count;
1625 if (wlv.row > endrow)
1626 return wlv.row;
1627 wlv.screen_row += wlv.text_prop_above_count;
1628 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001629#endif
1630
1631 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1632 // first character to be displayed.
1633 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001634 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635 else
1636 v = wp->w_leftcol;
1637 if (v > 0 && !number_only)
1638 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001639 char_u *prev_ptr = ptr;
1640 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001641 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001643 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001644 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001645 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001646 charsize = win_lbr_chartabsize(&cts, NULL);
1647 cts.cts_vcol += charsize;
1648 prev_ptr = cts.cts_ptr;
1649 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001651 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001652 ptr = cts.cts_ptr;
1653 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654
1655 // When:
1656 // - 'cuc' is set, or
1657 // - 'colorcolumn' is set, or
1658 // - 'virtualedit' is set, or
1659 // - the visual mode is active,
1660 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001661 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001663 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001664#endif
1665 virtual_active() ||
1666 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001667 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001668
1669 // Handle a character that's not completely on the screen: Put ptr at
1670 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001671 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001673 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674 ptr = prev_ptr;
1675 // If the character fits on the screen, don't need to skip it.
1676 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001677 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1678 && wlv.col == 0)
1679 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680 }
1681
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001682#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001683 // If there the text doesn't reach to the desired column, need to skip
1684 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001685 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1686 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001687 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001688#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001689
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690 // Adjust for when the inverted text is before the screen,
1691 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001692 if (wlv.tocol <= wlv.vcol)
1693 wlv.fromcol = 0;
1694 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1695 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696
1697#ifdef FEAT_LINEBREAK
1698 // When w_skipcol is non-zero, first line needs 'showbreak'
1699 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001700 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701#endif
1702#ifdef FEAT_SPELL
1703 // When spell checking a word we need to figure out the start of the
1704 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001705 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 {
1707 int len;
1708 colnr_T linecol = (colnr_T)(ptr - line);
1709 hlf_T spell_hlf = HLF_COUNT;
1710
1711 pos = wp->w_cursor;
1712 wp->w_cursor.lnum = lnum;
1713 wp->w_cursor.col = linecol;
1714 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1715
1716 // spell_move_to() may call ml_get() and make "line" invalid
1717 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1718 ptr = line + linecol;
1719
1720 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1721 {
1722 // no bad word found at line start, don't check until end of a
1723 // word
1724 spell_hlf = HLF_COUNT;
1725 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1726 }
1727 else
1728 {
1729 // bad word found, use attributes until end of word
1730 word_end = wp->w_cursor.col + len + 1;
1731
1732 // Turn index into actual attributes.
1733 if (spell_hlf != HLF_COUNT)
1734 spell_attr = highlight_attr[spell_hlf];
1735 }
1736 wp->w_cursor = pos;
1737
1738# ifdef FEAT_SYN_HL
1739 // Need to restart syntax highlighting for this line.
1740 if (has_syntax)
1741 syntax_start(wp, lnum);
1742# endif
1743 }
1744#endif
1745 }
1746
1747 // Correct highlighting for cursor that can't be disabled.
1748 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001749 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 {
1751 if (noinvcur)
1752 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001753 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 {
1755 // highlighting starts at cursor, let it start just after the
1756 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001757 fromcol_prev = wlv.fromcol;
1758 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001760 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761 // restart highlighting after the cursor
1762 fromcol_prev = wp->w_virtcol;
1763 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001764 if (wlv.fromcol >= wlv.tocol)
1765 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766 }
1767
1768#ifdef FEAT_SEARCH_EXTRA
1769 if (!number_only)
1770 {
1771 v = (long)(ptr - line);
1772 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1773 &line, &screen_search_hl,
1774 &search_attr);
1775 ptr = line + v; // "line" may have been updated
1776 }
1777#endif
1778
1779#ifdef FEAT_SYN_HL
1780 // Cursor line highlighting for 'cursorline' in the current window.
1781 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1782 {
1783 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001784 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 if (!(wp == curwin && VIsual_active)
1786 && wp->w_p_culopt_flags != CULOPT_NBR)
1787 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001788 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1790
zeertzjqb7acea12022-12-12 13:20:43 +00001791 // Only apply CursorLine highlight here when "screenline" is not
1792 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001793 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001794 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001795 else
1796 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001797 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1799 }
1800 area_highlighting = TRUE;
1801 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802 }
1803#endif
1804
Bram Moolenaar1306b362022-08-06 15:59:06 +01001805 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806
1807 // Repeat for the whole displayed line.
1808 for (;;)
1809 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001810 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001812 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813#endif
1814#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001815 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001816#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001817
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001819 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001821#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001822 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001823 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001824 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001825 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001826 }
1827#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001828 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001830 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 if (cmdwin_type != 0 && wp == curwin)
1832 {
1833 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001834 wlv.n_extra = 1;
1835 wlv.c_extra = cmdwin_type;
1836 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001837 wlv.char_attr =
1838 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001839 }
1840 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001842 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001844 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001845 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001846 }
1847#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001849 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001851 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001852 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001853 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001854 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001855 }
1856#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001857 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001858 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001859 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001860 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001861 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001862 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001864 // Check if 'breakindent' applies and show it.
1865 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1866 if (wlv.n_extra == 0)
1867 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001869#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001870 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001872 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001873 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001874 }
1875#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001876 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001878 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001879 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880 }
1881 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001882
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001884 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001885 && wlv.vcol >= left_curline_col
1886 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 {
zeertzjqb7acea12022-12-12 13:20:43 +00001888 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001889 }
1890#endif
1891
1892 // When still displaying '$' of change command, stop at cursor.
1893 // When only displaying the (relative) line number and that's done,
1894 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001895 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001896 && lnum == wp->w_cursor.lnum
1897 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001898 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001900 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901#endif
1902 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001904 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 // Pretend we have finished updating the window. Except when
1906 // 'cursorcolumn' is set.
1907#ifdef FEAT_SYN_HL
1908 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001909 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001910 else
1911#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001912 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 break;
1914 }
1915
Bram Moolenaar1306b362022-08-06 15:59:06 +01001916 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001917 {
1918 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001919 if (wlv.vcol == wlv.fromcol
1920 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1921 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001922 && (*mb_ptr2cells)(ptr) > 1)
1923 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001924 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001925 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 area_attr = vi_attr; // start highlighting
1927 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001928 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001929 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 area_attr = 0; // stop highlighting
1931
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001932#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933 if (text_props != NULL)
1934 {
1935 int pi;
1936 int bcol = (int)(ptr - line);
1937
Bram Moolenaar1306b362022-08-06 15:59:06 +01001938 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001939# ifdef FEAT_LINEBREAK
1940 && !in_linebreak
1941# endif
1942 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943 --bcol; // still working on the previous char, e.g. Tab
1944
1945 // Check if any active property ends.
1946 for (pi = 0; pi < text_props_active; ++pi)
1947 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001948 int tpi = text_prop_idxs[pi];
1949 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001951 // An inline property ends when after the start column plus
1952 // length. An "above" property ends when used and n_extra
1953 // is zero.
1954 if ((tp->tp_col != MAXCOL
1955 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001956 {
1957 if (pi + 1 < text_props_active)
1958 mch_memmove(text_prop_idxs + pi,
1959 text_prop_idxs + pi + 1,
1960 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001961 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001962 --text_props_active;
1963 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001964# ifdef FEAT_LINEBREAK
1965 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001966 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001967 syntax_attr = 0;
1968# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001969 }
1970 }
1971
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001972# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001973 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001974 // not on the next char yet, don't start another prop
1975 --bcol;
1976# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001977 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001978
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001979 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001980 // With 'nowrap' and not in the first screen line only "below"
1981 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001983 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001984 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001985 && (wp->w_p_wrap
1986 || wlv.row == startrow
1987 || (text_props[text_prop_next].tp_flags
1988 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001989 || (bcol == 0
1990 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001991 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001992 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001993 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001994 if (text_props[text_prop_next].tp_col == MAXCOL
1995 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001996 + text_props[text_prop_next].tp_len)
1997 text_prop_idxs[text_props_active++] = text_prop_next;
1998 ++text_prop_next;
1999 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002000
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002001 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002002 {
2003 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002004 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002005 text_prop_flags = 0;
2006 text_prop_type = NULL;
2007 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002008 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002009 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002010 if (text_props_active > 0 && wlv.n_extra == 0
2011 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002013 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002014 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002015 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002016
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002017 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002018 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002019
2020 // Sort the properties on priority and/or starting last.
2021 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002022 sort_text_props(wp->w_buffer, text_props,
2023 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002024
2025 for (pi = 0; pi < text_props_active; ++pi)
2026 {
2027 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002028 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002030 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002031
Bram Moolenaarcd105412022-10-10 19:50:42 +01002032 // Only use a text property that can be displayed.
2033 // Skip "after" properties when wrap is off and at the
2034 // end of the window.
2035 if (pt != NULL
2036 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2037 && tp->tp_id != -MAXCOL
2038 && !(tp->tp_id < 0
2039 && !wp->w_p_wrap
2040 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2041 | TP_FLAG_ALIGN_ABOVE
2042 | TP_FLAG_ALIGN_BELOW)) == 0
2043 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002044 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002045 if (tp->tp_col == MAXCOL
2046 && *ptr == NUL
2047 && ((wp->w_p_list && lcs_eol_one > 0
2048 && (tp->tp_flags
2049 & TP_FLAG_ALIGN_ABOVE) == 0)
2050 || (ptr == line
2051 && !did_line
2052 && (tp->tp_flags
2053 & TP_FLAG_ALIGN_BELOW))))
2054 {
2055 // skip this prop, first display the '$' after
2056 // the line or display an empty line
2057 text_prop_follows = TRUE;
2058 if (used_tpi < 0)
2059 display_text_first = TRUE;
2060 continue;
2061 }
2062
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002063 if (pt->pt_hl_id > 0)
2064 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002065 text_prop_type = pt;
2066 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002067 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002068 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2069 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002070 text_prop_flags = pt->pt_flags;
2071 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002072 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002073 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002074 }
2075 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002076 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002077 && -text_prop_id
2078 <= wp->w_buffer->b_textprop_text.ga_len)
2079 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002080 textprop_T *tp = &text_props[used_tpi];
2081 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002082 ->b_textprop_text.ga_data)[
2083 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002084 int above = (tp->tp_flags
2085 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002086 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002087
2088 // reset the ID in the copy to avoid it being used
2089 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002090 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002091
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002092 if (p != NULL)
2093 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002094 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002095 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002096 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002097 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002098 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2099 int padding = tp->tp_col == MAXCOL
2100 && tp->tp_len > 1
2101 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002102
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002103 // Insert virtual text before the current
2104 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002105 wlv.p_extra = p;
2106 wlv.c_extra = NUL;
2107 wlv.c_final = NUL;
2108 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002109 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002110 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2111 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002112 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002113 // restore search_attr and area_attr when n_extra
2114 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002115 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002116 saved_area_attr = area_attr;
2117 search_attr = 0;
2118 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002119 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002120 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002121 if (*ptr == NUL)
2122 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002123 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002124#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002125 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002126 {
2127 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002128 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002129 wlv.need_showbreak = FALSE;
2130 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002131 }
2132#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002133 if ((right || above || below || !wrap
2134 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002135 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002136 char_u *prev_p_extra = wlv.p_extra;
2137 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002138
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002139 // Take care of padding, right-align and
2140 // truncation.
2141 // Shared with win_lbr_chartabsize(), must do
2142 // exactly the same.
2143 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002144 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002145 wlv.col,
2146 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002147 &n_attr, &wlv.n_attr_skip,
2148 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002149 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002150 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002151 // wlv.p_extra was allocated
2152 vim_free(p_extra_free2);
2153 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002154 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002155
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002156 if (above)
2157 wlv.vcol_off_tp = wlv.n_extra;
2158
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002159 if (lcs_eol_one < 0
2160 && wp->w_p_wrap
2161 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002162 + wlv.n_extra - 2 > wp->w_width)
2163 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002164 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002165
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002166 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002167 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002168 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002169 {
2170 draw_screen_line(wp, &wlv);
2171
2172 // When line got too long for screen break
2173 // here.
2174 if (wlv.row == endrow)
2175 {
2176 ++wlv.row;
2177 break;
2178 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002179 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002180 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002181 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002182 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002183 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002184
Bram Moolenaarcd105412022-10-10 19:50:42 +01002185 // If the text didn't reach until the first window
2186 // column we need to skip cells.
2187 if (skip_cells > 0)
2188 {
2189 if (wlv.n_extra > skip_cells)
2190 {
2191 wlv.n_extra -= skip_cells;
2192 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002193 wlv.n_attr_skip -= skip_cells;
2194 if (wlv.n_attr_skip < 0)
2195 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002196 skip_cells = 0;
2197 }
2198 else
2199 {
2200 // the whole text is left of the window, drop
2201 // it and advance to the next one
2202 skip_cells -= wlv.n_extra;
2203 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002204 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002205 bail_out = TRUE;
2206 }
2207 }
2208
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002209 // If another text prop follows the condition below at
2210 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002211 // If this is an "above" text prop and 'nowrap' the we
2212 // must wrap anyway.
2213 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002214 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002215 && (wp->w_p_wrap
2216 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002217 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002218
2219 if (bail_out)
2220 // starting a new line for "below"
2221 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002222 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002224 else if (text_prop_next < text_prop_count
2225 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002226 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2227 || (!wp->w_p_wrap
2228 && wlv.col == wp->w_width - 1
2229 && (text_props[text_prop_next].tp_flags
2230 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002231 // When at last-but-one character and a text property
2232 // follows after it, we may need to flush the line after
2233 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002234 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002235 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002236 }
2237#endif
2238
Bram Moolenaare38fc862022-08-11 17:24:50 +01002239#ifdef FEAT_SEARCH_EXTRA
2240 if (wlv.n_extra == 0)
2241 {
2242 // Check for start/end of 'hlsearch' and other matches.
2243 // After end, check for start/end of next match.
2244 // When another match, have to check for start again.
2245 v = (long)(ptr - line);
2246 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2247 &screen_search_hl, &has_match_conc,
2248 &match_conc, did_line_attr, lcs_eol_one,
2249 &on_last_col);
2250 ptr = line + v; // "line" may have been changed
2251 prev_ptr = ptr;
2252
2253 // Do not allow a conceal over EOL otherwise EOL will be missed
2254 // and bad things happen.
2255 if (*ptr == NUL)
2256 has_match_conc = 0;
2257 }
2258#endif
2259
2260#ifdef FEAT_DIFF
2261 if (wlv.diff_hlf != (hlf_T)0)
2262 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002263 // When there is extra text (e.g. virtual text) it gets the
2264 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002265 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2266 && wlv.n_extra == 0)
2267 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002268 if (wlv.diff_hlf == HLF_TXD
2269 && ((ptr - line > change_end && wlv.n_extra == 0)
2270 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002271 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002272 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002273 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2274 && wp->w_p_culopt_flags != CULOPT_NBR
2275 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2276 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002277 wlv.line_attr = hl_combine_attr(
2278 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002279 }
2280#endif
2281
Bram Moolenaara74fda62019-10-19 17:38:03 +02002282#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002283 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002284 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002285 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002286# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002287 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002288 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002289# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002290 // Get syntax attribute.
2291 if (has_syntax)
2292 {
2293 // Get the syntax attribute for the character. If there
2294 // is an error, disable syntax highlighting.
2295 save_did_emsg = did_emsg;
2296 did_emsg = FALSE;
2297
2298 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002299 if (v == prev_syntax_col)
2300 // at same column again
2301 syntax_attr = prev_syntax_attr;
2302 else
2303 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002304# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002305 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002306# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002307 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002308# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002309 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002310# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002311 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002312 prev_syntax_col = v;
2313 prev_syntax_attr = syntax_attr;
2314 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002315
Bram Moolenaar34390282019-10-16 14:38:26 +02002316 if (did_emsg)
2317 {
2318 wp->w_s->b_syn_error = TRUE;
2319 has_syntax = FALSE;
2320 syntax_attr = 0;
2321 }
2322 else
2323 did_emsg = save_did_emsg;
2324# ifdef SYN_TIME_LIMIT
2325 if (wp->w_s->b_syn_slow)
2326 has_syntax = FALSE;
2327# endif
2328
2329 // Need to get the line again, a multi-line regexp may
2330 // have made it invalid.
2331 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2332 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002333 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002334# ifdef FEAT_CONCEAL
2335 // no concealing past the end of the line, it interferes
2336 // with line highlighting
2337 if (*ptr == NUL)
2338 syntax_flags = 0;
2339 else
2340 syntax_flags = get_syntax_info(&syntax_seqnr);
2341# endif
2342 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002343 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002344# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002345 // Combine text property highlight into syntax highlight.
2346 if (text_prop_type != NULL)
2347 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002348 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002349 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2350 else
2351 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002352 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002353 }
2354# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002355#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002356
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002357 // Decide which of the highlight attributes to use.
2358 attr_pri = TRUE;
2359#ifdef LINE_ATTR
2360 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002361 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002362 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002363 if (!highlight_match)
2364 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002365 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002366# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002367 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002368# endif
2369 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002371 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002372 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002373# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002374 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002375# endif
2376 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002377 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002378 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2379 || wlv.vcol < wlv.fromcol
2380 || vcol_prev < fromcol_prev
2381 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002383 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002385# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002386 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002387# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002388 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002389# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 attr_pri = FALSE;
2391 }
2392#else
2393 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002394 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002396 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002397#endif
2398 else
2399 {
2400 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002401#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002402 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002403#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002404 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002405#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002406 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002407#ifdef FEAT_PROP_POPUP
2408 // override with text property highlight when "override" is TRUE
2409 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002410 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002411#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002412 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002413
2414 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002415 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002416 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002417 if (wlv.char_attr == 0)
2418 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002419 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002420 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002421 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002422
2423 // Get the next character to put on the screen.
2424
2425 // The "p_extra" points to the extra stuff that is inserted to
2426 // represent special characters (non-printable stuff) and other
2427 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002428 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002429 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2430 // "p_extra[n_extra]".
2431 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002432 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002434 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002435 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002436 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2437 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2439 if (enc_utf8 && utf_char2len(c) > 1)
2440 {
2441 mb_utf8 = TRUE;
2442 u8cc[0] = 0;
2443 c = 0xc0;
2444 }
2445 else
2446 mb_utf8 = FALSE;
2447 }
2448 else
2449 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002450 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451 if (has_mbyte)
2452 {
2453 mb_c = c;
2454 if (enc_utf8)
2455 {
2456 // If the UTF-8 character is more than one byte:
2457 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002458 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002460 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461 mb_l = 1;
2462 else if (mb_l > 1)
2463 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002464 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 mb_utf8 = TRUE;
2466 c = 0xc0;
2467 }
2468 }
2469 else
2470 {
2471 // if this is a DBCS character, put it in "mb_c"
2472 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002473 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474 mb_l = 1;
2475 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002476 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477 }
2478 if (mb_l == 0) // at the NUL at end-of-line
2479 mb_l = 1;
2480
2481 // If a double-width char doesn't fit display a '>' in the
2482 // last column.
2483 if ((
2484# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002485 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002487 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 && (*mb_char2cells)(mb_c) == 2)
2489 {
2490 c = '>';
2491 mb_c = c;
2492 mb_l = 1;
2493 mb_utf8 = FALSE;
2494 multi_attr = HL_ATTR(HLF_AT);
2495#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002496 if (wlv.cul_attr)
2497 multi_attr = hl_combine_attr(
2498 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002500 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002501
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 // put the pointer back to output the double-width
2503 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002504 ++wlv.n_extra;
2505 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506 }
2507 else
2508 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002509 wlv.n_extra -= mb_l - 1;
2510 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511 }
2512 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002513 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002514 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002515 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002516#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002517 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002518 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002519 // Only restore search_attr and area_attr after "n_extra" in
2520 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002521 if (wlv.saved_n_extra <= 0)
2522 {
2523 if (search_attr == 0)
2524 search_attr = saved_search_attr;
2525 if (area_attr == 0 && *ptr != NUL)
2526 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002527
2528 if (wlv.extra_for_textprop)
2529 // wlv.extra_attr should be used at this position but
2530 // not any further.
2531 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002532 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002533
2534 wlv.extra_for_textprop = FALSE;
2535 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002536 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002537#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 }
2539 else
2540 {
2541#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002542 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002544 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 // Get a character from the line itself.
2547 c = *ptr;
2548#ifdef FEAT_LINEBREAK
2549 c0 = *ptr;
2550#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002551#ifdef FEAT_PROP_POPUP
2552 if (c == NUL)
2553 // text is finished, may display a "below" virtual text
2554 did_line = TRUE;
2555#endif
2556
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 if (has_mbyte)
2558 {
2559 mb_c = c;
2560 if (enc_utf8)
2561 {
2562 // If the UTF-8 character is more than one byte: Decode it
2563 // into "mb_c".
2564 mb_l = utfc_ptr2len(ptr);
2565 mb_utf8 = FALSE;
2566 if (mb_l > 1)
2567 {
2568 mb_c = utfc_ptr2char(ptr, u8cc);
2569 // Overlong encoded ASCII or ASCII with composing char
2570 // is displayed normally, except a NUL.
2571 if (mb_c < 0x80)
2572 {
2573 c = mb_c;
2574#ifdef FEAT_LINEBREAK
2575 c0 = mb_c;
2576#endif
2577 }
2578 mb_utf8 = TRUE;
2579
2580 // At start of the line we can have a composing char.
2581 // Draw it as a space with a composing char.
2582 if (utf_iscomposing(mb_c))
2583 {
2584 int i;
2585
2586 for (i = Screen_mco - 1; i > 0; --i)
2587 u8cc[i] = u8cc[i - 1];
2588 u8cc[0] = mb_c;
2589 mb_c = ' ';
2590 }
2591 }
2592
2593 if ((mb_l == 1 && c >= 0x80)
2594 || (mb_l >= 1 && mb_c == 0)
2595 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2596 {
2597 // Illegal UTF-8 byte: display as <xx>.
2598 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002599 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600# ifdef FEAT_RIGHTLEFT
2601 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002602 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002604 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002605 c = *wlv.p_extra;
2606 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002608 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2609 wlv.c_extra = NUL;
2610 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002611 if (area_attr == 0 && search_attr == 0)
2612 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002613 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002614 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002615 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002616 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002617 }
2618 }
2619 else if (mb_l == 0) // at the NUL at end-of-line
2620 mb_l = 1;
2621#ifdef FEAT_ARABIC
2622 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2623 {
2624 // Do Arabic shaping.
2625 int pc, pc1, nc;
2626 int pcc[MAX_MCO];
2627
2628 // The idea of what is the previous and next
2629 // character depends on 'rightleft'.
2630 if (wp->w_p_rl)
2631 {
2632 pc = prev_c;
2633 pc1 = prev_c1;
2634 nc = utf_ptr2char(ptr + mb_l);
2635 prev_c1 = u8cc[0];
2636 }
2637 else
2638 {
2639 pc = utfc_ptr2char(ptr + mb_l, pcc);
2640 nc = prev_c;
2641 pc1 = pcc[0];
2642 }
2643 prev_c = mb_c;
2644
2645 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2646 }
2647 else
2648 prev_c = mb_c;
2649#endif
2650 }
2651 else // enc_dbcs
2652 {
2653 mb_l = MB_BYTE2LEN(c);
2654 if (mb_l == 0) // at the NUL at end-of-line
2655 mb_l = 1;
2656 else if (mb_l > 1)
2657 {
2658 // We assume a second byte below 32 is illegal.
2659 // Hopefully this is OK for all double-byte encodings!
2660 if (ptr[1] >= 32)
2661 mb_c = (c << 8) + ptr[1];
2662 else
2663 {
2664 if (ptr[1] == NUL)
2665 {
2666 // head byte at end of line
2667 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002668 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669 }
2670 else
2671 {
2672 // illegal tail byte
2673 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002674 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002676 wlv.p_extra = wlv.extra;
2677 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002678 wlv.c_extra = NUL;
2679 wlv.c_final = NUL;
2680 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002681 if (area_attr == 0 && search_attr == 0)
2682 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002683 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002684 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002685 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002686 // save current attr
2687 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002688 }
2689 mb_c = c;
2690 }
2691 }
2692 }
2693 // If a double-width char doesn't fit display a '>' in the
2694 // last column; the character is displayed at the start of the
2695 // next line.
2696 if ((
2697# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002698 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002700 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 && (*mb_char2cells)(mb_c) == 2)
2702 {
2703 c = '>';
2704 mb_c = c;
2705 mb_utf8 = FALSE;
2706 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002707 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708 // Put pointer back so that the character will be
2709 // displayed at the start of the next line.
2710 --ptr;
2711#ifdef FEAT_CONCEAL
2712 did_decrement_ptr = TRUE;
2713#endif
2714 }
2715 else if (*ptr != NUL)
2716 ptr += mb_l - 1;
2717
2718 // If a double-width char doesn't fit at the left side display
2719 // a '<' in the first column. Don't do this for unprintable
2720 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002721 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002722 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002723 wlv.n_extra = 1;
2724 wlv.c_extra = MB_FILLER_CHAR;
2725 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726 c = ' ';
2727 if (area_attr == 0 && search_attr == 0)
2728 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002729 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002730 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002731 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002732 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 }
2734 mb_c = c;
2735 mb_utf8 = FALSE;
2736 mb_l = 1;
2737 }
2738
2739 }
2740 ++ptr;
2741
2742 if (extra_check)
2743 {
2744#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002745 // Check spelling (unless at the end of the line).
2746 // Only do this when there is no syntax highlighting, the
2747 // @Spell cluster is not used or the current syntax item
2748 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002749 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002750 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002751 {
2752 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002753 // do not calculate cap_col at the end of the line or when
2754 // only white space is following
2755 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002756# ifdef FEAT_SYN_HL
2757 !has_syntax ||
2758# endif
2759 can_spell))
2760 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002761 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762 int len;
2763 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002764
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002765 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002767
2768 // Use nextline[] if possible, it has the start of the
2769 // next line concatenated.
2770 if ((prev_ptr - line) - nextlinecol >= 0)
2771 p = nextline + (prev_ptr - line) - nextlinecol;
2772 else
2773 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002774 spv->spv_cap_col -= (int)(prev_ptr - line);
2775 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2776 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777 word_end = v + len;
2778
2779 // In Insert mode only highlight a word that
2780 // doesn't touch the cursor.
2781 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002782 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002783 && wp->w_cursor.lnum == lnum
2784 && wp->w_cursor.col >=
2785 (colnr_T)(prev_ptr - line)
2786 && wp->w_cursor.col < (colnr_T)word_end)
2787 {
2788 spell_hlf = HLF_COUNT;
2789 spell_redraw_lnum = lnum;
2790 }
2791
2792 if (spell_hlf == HLF_COUNT && p != prev_ptr
2793 && (p - nextline) + len > nextline_idx)
2794 {
2795 // Remember that the good word continues at the
2796 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002797 spv->spv_checked_lnum = lnum + 1;
2798 spv->spv_checked_col = (p - nextline) + len
2799 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 }
2801
2802 // Turn index into actual attributes.
2803 if (spell_hlf != HLF_COUNT)
2804 spell_attr = highlight_attr[spell_hlf];
2805
Luuk van Baal30805a12023-05-27 22:22:10 +01002806 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807 {
2808 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002809 && (p - nextline) + spv->spv_cap_col
2810 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002811 {
2812 // Remember that the word in the next line
2813 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002814 spv->spv_capcol_lnum = lnum + 1;
2815 spv->spv_cap_col = ((p - nextline)
2816 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 }
2818 else
2819 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002820 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 }
2822 }
2823 }
2824 if (spell_attr != 0)
2825 {
2826 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002827 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2828 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002829 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002830 wlv.char_attr = hl_combine_attr(spell_attr,
2831 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832 }
2833#endif
2834#ifdef FEAT_LINEBREAK
2835 // Found last space before word: check for line break.
2836 if (wp->w_p_lbr && c0 == c
2837 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2838 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002839 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2840 : 0;
2841 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002842 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002843
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002844 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002845# ifdef FEAT_PROP_POPUP
2846 // do not want virtual text counted here
2847 cts.cts_has_prop_with_text = FALSE;
2848# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002849 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002850 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002851
2852 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002853 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002854 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002855 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002856 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2857 if (wlv.n_extra < 0)
2858 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002859 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002860 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002861 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002862 // line break, but for TABs the highlighting should
2863 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002864 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002865
Bram Moolenaar1306b362022-08-06 15:59:06 +01002866 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002868 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002869 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870 wp->w_buffer->b_p_vts_array) - 1;
2871# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002872 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002873 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874# endif
2875
Bram Moolenaar1306b362022-08-06 15:59:06 +01002876 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2877 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002878# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002879 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002880 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002881# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882 if (VIM_ISWHITE(c))
2883 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002884# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002885 if (c == TAB)
2886 // See "Tab alignment" below.
2887 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002888# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889 if (!wp->w_p_list)
2890 c = ' ';
2891 }
2892 }
2893#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002894 in_multispace = c == ' '
2895 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2896 if (!in_multispace)
2897 multispace_pos = 0;
2898
Bram Moolenaareed9d462021-02-15 20:38:25 +01002899 // 'list': Change char 160 to 'nbsp' and space to 'space'
2900 // setting in 'listchars'. But not when the character is
2901 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 if (wp->w_p_list
2903 && ((((c == 160 && mb_l == 1)
2904 || (mb_utf8
2905 && ((mb_c == 160 && mb_l == 2)
2906 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002907 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 || (c == ' '
2909 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002910 && (wp->w_lcs_chars.space
2911 || (in_multispace
2912 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002913 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 && ptr - line <= trailcol)))
2915 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002916 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2917 {
2918 c = wp->w_lcs_chars.multispace[multispace_pos++];
2919 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2920 multispace_pos = 0;
2921 }
2922 else
2923 c = (c == ' ') ? wp->w_lcs_chars.space
2924 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 if (area_attr == 0 && search_attr == 0)
2926 {
2927 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002928 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002929 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002930 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931 }
2932 mb_c = c;
2933 if (enc_utf8 && utf_char2len(c) > 1)
2934 {
2935 mb_utf8 = TRUE;
2936 u8cc[0] = 0;
2937 c = 0xc0;
2938 }
2939 else
2940 mb_utf8 = FALSE;
2941 }
2942
zeertzjq2e7cba32022-06-10 15:30:32 +01002943 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2944 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002946 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2947 && wp->w_lcs_chars.leadmultispace != NULL)
2948 {
2949 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002950 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2951 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002952 multispace_pos = 0;
2953 }
2954
2955 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2956 c = wp->w_lcs_chars.trail;
2957
2958 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2959 c = wp->w_lcs_chars.lead;
2960
zeertzjq2e7cba32022-06-10 15:30:32 +01002961 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002962 c = wp->w_lcs_chars.space;
2963
2964
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 if (!attr_pri)
2966 {
2967 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002968 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002969 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002970 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 }
2972 mb_c = c;
2973 if (enc_utf8 && utf_char2len(c) > 1)
2974 {
2975 mb_utf8 = TRUE;
2976 u8cc[0] = 0;
2977 c = 0xc0;
2978 }
2979 else
2980 mb_utf8 = FALSE;
2981 }
2982 }
2983
2984 // Handling of non-printable characters.
2985 if (!vim_isprintc(c))
2986 {
2987 // when getting a character from the file, we may have to
2988 // turn it into something else on the way to putting it
2989 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002990 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002992 int tab_len = 0;
2993 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002995 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01002996
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 // only adjust the tab_len, when at the first column
2998 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002999 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003000 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001#endif
3002 // tab amount depends on current column
3003#ifdef FEAT_VARTABS
3004 tab_len = tabstop_padding(vcol_adjusted,
3005 wp->w_buffer->b_p_ts,
3006 wp->w_buffer->b_p_vts_array) - 1;
3007#else
3008 tab_len = (int)wp->w_buffer->b_p_ts
3009 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3010#endif
3011
3012#ifdef FEAT_LINEBREAK
3013 if (!wp->w_p_lbr || !wp->w_p_list)
3014#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003015 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003017 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003018 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019#ifdef FEAT_LINEBREAK
3020 else
3021 {
3022 char_u *p;
3023 int len;
3024 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003025 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003027# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003028 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003030 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003031
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003033 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003034 && old_boguscols > 0
3035 && wlv.n_extra > tab_len)
3036 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003037# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003038 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003040 // If wlv.n_extra > 0, it gives the number of chars
3041 // to use for a tab, else we need to calculate the
3042 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003043 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3044 len = tab_len * tab2_len;
3045 if (wp->w_lcs_chars.tab3)
3046 len += mb_char2len(wp->w_lcs_chars.tab3)
3047 - tab2_len;
3048 if (wlv.n_extra > 0)
3049 len += wlv.n_extra - tab_len;
3050 c = wp->w_lcs_chars.tab1;
3051 p = alloc(len + 1);
3052 if (p == NULL)
3053 wlv.n_extra = 0;
3054 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003055 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003056 vim_memset(p, ' ', len);
3057 p[len] = NUL;
3058 vim_free(wlv.p_extra_free);
3059 wlv.p_extra_free = p;
3060 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003061 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003062 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003063
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003064 if (*p == NUL)
3065 {
3066 tab_len = i;
3067 break;
3068 }
3069
3070 // if tab3 is given, use it for the last
3071 // char
3072 if (wp->w_lcs_chars.tab3
3073 && i == tab_len - 1)
3074 lcs = wp->w_lcs_chars.tab3;
3075 p += mb_char2bytes(lcs, p);
3076 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003078 }
3079 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003080# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003081 // n_extra will be increased by
3082 // FIX_FOX_BOGUSCOLS macro below, so need to
3083 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003084 if (wlv.vcol_off_co > 0)
3085 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003086# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003087 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089 }
3090#endif
3091#ifdef FEAT_CONCEAL
3092 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003093 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094
3095 // Tab alignment should be identical regardless of
3096 // 'conceallevel' value. So tab compensates of all
3097 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003098 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 // line. Note that the tab can be longer than
3100 // 'tabstop' when there are concealed characters.
3101 FIX_FOR_BOGUSCOLS;
3102
3103 // Make sure, the highlighting for the tab char will be
3104 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003105 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003106 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003107 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108 tab_len += vc_saved;
3109 }
3110#endif
3111 mb_utf8 = FALSE; // don't draw as UTF-8
3112 if (wp->w_p_list)
3113 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003114 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003115 ? wp->w_lcs_chars.tab3
3116 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003118 if (wp->w_p_lbr && wlv.p_extra != NULL
3119 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003120 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 else
3122#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003123 wlv.c_extra = wp->w_lcs_chars.tab2;
3124 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003126 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003127 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003128 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 mb_c = c;
3130 if (enc_utf8 && utf_char2len(c) > 1)
3131 {
3132 mb_utf8 = TRUE;
3133 u8cc[0] = 0;
3134 c = 0xc0;
3135 }
3136 }
3137 else
3138 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003139 wlv.c_final = NUL;
3140 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141 c = ' ';
3142 }
3143 }
3144 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003145 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003147 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3148 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 && VIsual_mode != Ctrl_V
3150 && (
3151# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003152 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003154 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 && !(noinvcur
3156 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003157 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158 && lcs_eol_one > 0)
3159 {
3160 // Display a '$' after the line or highlight an extra
3161 // character if the line break is included.
3162#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3163 // For a diff line the highlighting continues after the
3164 // "$".
3165 if (
3166# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003167 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003168# ifdef LINE_ATTR
3169 &&
3170# endif
3171# endif
3172# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003173 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174# endif
3175 )
3176#endif
3177 {
3178 // In virtualedit, visual selections may extend
3179 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003180 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003181 && wlv.tocol != MAXCOL
3182 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003183 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003184 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003185 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003186 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3187 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 else
3189 c = ' ';
3190 lcs_eol_one = -1;
3191 --ptr; // put it back at the NUL
3192 if (!attr_pri)
3193 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003194 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003195 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 n_attr = 1;
3197 }
3198 mb_c = c;
3199 if (enc_utf8 && utf_char2len(c) > 1)
3200 {
3201 mb_utf8 = TRUE;
3202 u8cc[0] = 0;
3203 c = 0xc0;
3204 }
3205 else
3206 mb_utf8 = FALSE; // don't draw as UTF-8
3207 }
3208 else if (c != NUL)
3209 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003210 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3211 if (wlv.n_extra == 0)
3212 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213#ifdef FEAT_RIGHTLEFT
3214 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003215 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003217 wlv.c_extra = NUL;
3218 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219#ifdef FEAT_LINEBREAK
3220 if (wp->w_p_lbr)
3221 {
3222 char_u *p;
3223
Bram Moolenaar1306b362022-08-06 15:59:06 +01003224 c = *wlv.p_extra;
3225 p = alloc(wlv.n_extra + 1);
3226 vim_memset(p, ' ', wlv.n_extra);
3227 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3228 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003229 vim_free(wlv.p_extra_free);
3230 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231 }
3232 else
3233#endif
3234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003235 wlv.n_extra = byte2cells(c) - 1;
3236 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237 }
3238 if (!attr_pri)
3239 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003240 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003241 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003242 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003243 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003244 }
3245 mb_utf8 = FALSE; // don't draw as UTF-8
3246 }
3247 else if (VIsual_active
3248 && (VIsual_mode == Ctrl_V
3249 || VIsual_mode == 'v')
3250 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003251 && wlv.tocol != MAXCOL
3252 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253 && (
3254#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003255 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003257 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258 {
3259 c = ' ';
3260 --ptr; // put it back at the NUL
3261 }
3262#if defined(LINE_ATTR)
3263 else if ((
3264# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003265 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266# endif
3267# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003268 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003270 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 ) && (
3272# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003273 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003275 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003277 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278# endif
3279 < wp->w_width)))
3280 {
3281 // Highlight until the right side of the window
3282 c = ' ';
3283 --ptr; // put it back at the NUL
3284
3285 // Remember we do the char for line highlighting.
3286 ++did_line_attr;
3287
3288 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003289 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003291 || (wp->w_p_list &&
3292 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003293 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003295 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003297 wlv.diff_hlf = HLF_CHD;
3298 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003300 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003301 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3302 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003303 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003304 || (wlv.vcol >= left_curline_col
3305 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003306 wlv.char_attr = hl_combine_attr(
3307 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003308 }
3309 }
3310# endif
3311# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003312 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003314 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003315 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3316 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003318 if (!wlv.cul_screenline
3319 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003320 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003321 wlv.char_attr = hl_combine_attr(
3322 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003324 else if (wlv.line_attr)
3325 wlv.char_attr = hl_combine_attr(
3326 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327 }
3328# endif
3329 }
3330#endif
3331 }
3332
3333#ifdef FEAT_CONCEAL
3334 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003335 && (wp != curwin || lnum != wp->w_cursor.lnum
3336 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3338 && !(lnum_in_visual_area
3339 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3340 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003341 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003342 if (((prev_syntax_id != syntax_seqnr
3343 && (syntax_flags & HL_CONCEAL) != 0)
3344 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003345 && (syn_get_sub_char() != NUL
3346 || (has_match_conc && match_conc)
3347 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003348 && wp->w_p_cole != 3)
3349 {
3350 // First time at this concealed item: display one
3351 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003352 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 c = match_conc;
3354 else if (syn_get_sub_char() != NUL)
3355 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003356 else if (wp->w_lcs_chars.conceal != NUL)
3357 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358 else
3359 c = ' ';
3360
3361 prev_syntax_id = syntax_seqnr;
3362
Bram Moolenaar1306b362022-08-06 15:59:06 +01003363 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003364 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003365 wlv.vcol += wlv.n_extra;
3366 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367 {
3368# ifdef FEAT_RIGHTLEFT
3369 if (wp->w_p_rl)
3370 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003371 wlv.col -= wlv.n_extra;
3372 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 }
3374 else
3375# endif
3376 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003377 wlv.boguscols += wlv.n_extra;
3378 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379 }
3380 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003381 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 n_attr = 0;
3383 }
3384 else if (n_skip == 0)
3385 {
3386 is_concealing = TRUE;
3387 n_skip = 1;
3388 }
3389 mb_c = c;
3390 if (enc_utf8 && utf_char2len(c) > 1)
3391 {
3392 mb_utf8 = TRUE;
3393 u8cc[0] = 0;
3394 c = 0xc0;
3395 }
3396 else
3397 mb_utf8 = FALSE; // don't draw as UTF-8
3398 }
3399 else
3400 {
3401 prev_syntax_id = 0;
3402 is_concealing = FALSE;
3403 }
3404
3405 if (n_skip > 0 && did_decrement_ptr)
3406 // not showing the '>', put pointer back to avoid getting stuck
3407 ++ptr;
3408
3409#endif // FEAT_CONCEAL
3410 }
3411
3412#ifdef FEAT_CONCEAL
3413 // In the cursor line and we may be concealing characters: correct
3414 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003415 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003416 && wp == curwin && lnum == wp->w_cursor.lnum
3417 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003420# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003422 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003423 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003424# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 wp->w_wcol = wlv.col - wlv.boguscols;
3426 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427 did_wcol = TRUE;
3428 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003429# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003430 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003431# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 }
3433#endif
3434
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003435 // Use "wlv.extra_attr", but don't override visual selection
3436 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003437 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3438 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003440 && (!attr_pri
3441#ifdef FEAT_PROP_POPUP
3442 || (text_prop_flags & PT_FLAG_OVERRIDE)
3443#endif
3444 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 {
3446#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003447 if (wlv.line_attr)
3448 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 else
3450#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003451 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003452#ifdef FEAT_PROP_POPUP
3453 if (reset_extra_attr)
3454 {
3455 reset_extra_attr = FALSE;
3456 wlv.extra_attr = 0;
3457 }
3458#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 }
3460
3461#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3462 // XIM don't send preedit_start and preedit_end, but they send
3463 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3464 // im_is_preediting() here.
3465 if (p_imst == IM_ON_THE_SPOT
3466 && xic != NULL
3467 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003468 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469 && !p_imdisable
3470 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003471 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472 {
3473 colnr_T tcol;
3474
3475 if (preedit_end_col == MAXCOL)
3476 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3477 else
3478 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003479 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 {
3481 if (feedback_old_attr < 0)
3482 {
3483 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003484 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003486 wlv.char_attr = im_get_feedback_attr(feedback_col);
3487 if (wlv.char_attr < 0)
3488 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489 feedback_col++;
3490 }
3491 else if (feedback_old_attr >= 0)
3492 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003493 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 feedback_old_attr = -1;
3495 feedback_col = 0;
3496 }
3497 }
3498#endif
3499 // Handle the case where we are in column 0 but not on the first
3500 // character of the line and the user wants us to show us a
3501 // special character (via 'listchars' option "precedes:<char>".
3502 if (lcs_prec_todo != NUL
3503 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003504 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3505 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003507 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003509 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510 && c != NUL)
3511 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003512 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 lcs_prec_todo = NUL;
3514 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3515 {
3516 // Double-width character being overwritten by the "precedes"
3517 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003518 wlv.c_extra = MB_FILLER_CHAR;
3519 wlv.c_final = NUL;
3520 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003521 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003522 wlv.extra_attr =
3523 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003524 }
3525 mb_c = c;
3526 if (enc_utf8 && utf_char2len(c) > 1)
3527 {
3528 mb_utf8 = TRUE;
3529 u8cc[0] = 0;
3530 c = 0xc0;
3531 }
3532 else
3533 mb_utf8 = FALSE; // don't draw as UTF-8
3534 if (!attr_pri)
3535 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003536 saved_attr3 = wlv.char_attr; // save current attr
3537 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538 n_attr3 = 1;
3539 }
3540 }
3541
3542 // At end of the text line or just after the last character.
3543 if ((c == NUL
3544#if defined(LINE_ATTR)
3545 || did_line_attr == 1
3546#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003547 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003548 {
3549#ifdef FEAT_SEARCH_EXTRA
3550 // flag to indicate whether prevcol equals startcol of search_hl or
3551 // one of the matches
3552 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3553 (long)(ptr - line) - (c == NUL));
3554#endif
3555 // Invert at least one char, used for Visual and empty line or
3556 // highlight match at end of line. If it's beyond the last
3557 // char on the screen, just overwrite that one (tricky!) Not
3558 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003559 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003560 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561 && (VIsual_mode != Ctrl_V
3562 || lnum == VIsual.lnum
3563 || lnum == curwin->w_cursor.lnum)
3564 && c == NUL)
3565#ifdef FEAT_SEARCH_EXTRA
3566 // highlight 'hlsearch' match at end of line
3567 || (prevcol_hl_flag
3568# ifdef FEAT_SYN_HL
3569 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3570 && !(wp == curwin && VIsual_active))
3571# endif
3572# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003573 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574# endif
3575# if defined(LINE_ATTR)
3576 && did_line_attr <= 1
3577# endif
3578 )
3579#endif
3580 ))
3581 {
3582 int n = 0;
3583
3584#ifdef FEAT_RIGHTLEFT
3585 if (wp->w_p_rl)
3586 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003587 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588 n = 1;
3589 }
3590 else
3591#endif
3592 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003593 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 n = -1;
3595 }
3596 if (n != 0)
3597 {
3598 // At the window boundary, highlight the last character
3599 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 wlv.off += n;
3601 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602 }
3603 else
3604 {
3605 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003606 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003608 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 }
3610#ifdef FEAT_SEARCH_EXTRA
3611 if (area_attr == 0)
3612 {
3613 // Use attributes from match with highest priority among
3614 // 'search_hl' and the match list.
3615 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003616 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 }
3618#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003619 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003620 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621#ifdef FEAT_RIGHTLEFT
3622 if (wp->w_p_rl)
3623 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003624 --wlv.col;
3625 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 }
3627 else
3628#endif
3629 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003630 ++wlv.col;
3631 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003633 ++wlv.vcol;
3634 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635 }
3636 }
3637
3638 // At end of the text line.
3639 if (c == NUL)
3640 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003641#ifdef FEAT_PROP_POPUP
3642 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003643 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003644 // Put the pointer back to the NUL.
3645 --ptr;
3646 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003648 else
3649#endif
3650 {
3651 draw_screen_line(wp, &wlv);
3652
3653 // Update w_cline_height and w_cline_folded if the cursor line
3654 // was updated (saves a call to plines() later).
3655 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3656 {
3657 curwin->w_cline_row = startrow;
3658 curwin->w_cline_height = wlv.row - startrow;
3659#ifdef FEAT_FOLDING
3660 curwin->w_cline_folded = FALSE;
3661#endif
3662 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3663 }
3664 break;
3665 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003666 }
3667
3668 // Show "extends" character from 'listchars' if beyond the line end and
3669 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003670 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003671 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003672 && wp->w_p_list
3673 && !wp->w_p_wrap
3674#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003675 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676#endif
3677 && (
3678#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003679 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003681 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003683 || lcs_eol_one > 0
3684 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003685 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003687 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003688 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003689 mb_c = c;
3690 if (enc_utf8 && utf_char2len(c) > 1)
3691 {
3692 mb_utf8 = TRUE;
3693 u8cc[0] = 0;
3694 c = 0xc0;
3695 }
3696 else
3697 mb_utf8 = FALSE;
3698 }
3699
3700#ifdef FEAT_SYN_HL
3701 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003702 if (wlv.draw_color_col)
3703 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704
3705 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3706 // highlight the cursor position itself.
3707 // Also highlight the 'colorcolumn' if it is different than
3708 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003709 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3710 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003712 if (((wlv.draw_state == WL_LINE
3713 || wlv.draw_state == WL_BRI
3714 || wlv.draw_state == WL_SBR)
3715 && !lnum_in_visual_area
3716 && search_attr == 0
3717 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003718# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003719 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003720# endif
3721 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722 {
3723 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3724 && lnum != wp->w_cursor.lnum)
3725 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003726 vcol_save_attr = wlv.char_attr;
3727 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3728 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003730 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003732 vcol_save_attr = wlv.char_attr;
3733 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003734 }
3735 }
3736#endif
3737
3738 // Store character to be displayed.
3739 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003740 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003741 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742 {
3743 // Store the character.
3744#if defined(FEAT_RIGHTLEFT)
3745 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3746 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003747 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003748 --wlv.off;
3749 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750 }
3751#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003752 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753 if (enc_dbcs == DBCS_JPNU)
3754 {
3755 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 ScreenLines[wlv.off] = 0x8e;
3757 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 }
3759 else if (enc_utf8)
3760 {
3761 if (mb_utf8)
3762 {
3763 int i;
3764
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003766 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003767 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768 for (i = 0; i < Screen_mco; ++i)
3769 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003770 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003771 if (u8cc[i] == 0)
3772 break;
3773 }
3774 }
3775 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 }
3778 if (multi_attr)
3779 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003780 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003781 multi_attr = 0;
3782 }
3783 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003784 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003785
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003786 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003787
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3789 {
3790 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003791 ++wlv.off;
3792 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793 if (enc_utf8)
3794 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003795 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796 else
3797 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003798 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003799 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003801 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802#endif
3803 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003804 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003805 // When "wlv.tocol" is halfway a character, set it to the end
3806 // of the character, otherwise highlighting won't stop.
3807 if (wlv.tocol == wlv.vcol)
3808 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003809
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003810 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003811
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812#ifdef FEAT_RIGHTLEFT
3813 if (wp->w_p_rl)
3814 {
3815 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003816 --wlv.off;
3817 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818 }
3819#endif
3820 }
3821#ifdef FEAT_RIGHTLEFT
3822 if (wp->w_p_rl)
3823 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003824 --wlv.off;
3825 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826 }
3827 else
3828#endif
3829 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003830 ++wlv.off;
3831 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832 }
3833 }
3834#ifdef FEAT_CONCEAL
3835 else if (wp->w_p_cole > 0 && is_concealing)
3836 {
3837 --n_skip;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003838 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003839 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003840 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003841 if (wp->w_p_wrap)
3842 {
3843 // Special voodoo required if 'wrap' is on.
3844 //
3845 // Advance the column indicator to force the line
3846 // drawing to wrap early. This will make the line
3847 // take up the same screen space when parts are concealed,
3848 // so that cursor line computations aren't messed up.
3849 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003850 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851 // trailing junk to be written out of the screen line
3852 // we are building, 'boguscols' keeps track of the number
3853 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003854 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003855 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003856 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003857# ifdef FEAT_RIGHTLEFT
3858 if (wp->w_p_rl)
3859 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003860 wlv.col -= wlv.n_extra;
3861 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862 }
3863 else
3864# endif
3865 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003866 wlv.col += wlv.n_extra;
3867 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003869 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003870 n_attr = 0;
3871 }
3872
3873
3874 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3875 {
3876 // Need to fill two screen columns.
3877# ifdef FEAT_RIGHTLEFT
3878 if (wp->w_p_rl)
3879 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003880 --wlv.boguscols;
3881 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882 }
3883 else
3884# endif
3885 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003886 ++wlv.boguscols;
3887 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003888 }
3889 }
3890
3891# ifdef FEAT_RIGHTLEFT
3892 if (wp->w_p_rl)
3893 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003894 --wlv.boguscols;
3895 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003896 }
3897 else
3898# endif
3899 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003900 ++wlv.boguscols;
3901 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003902 }
3903 }
3904 else
3905 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003906 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003907 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003908 wlv.vcol += wlv.n_extra;
3909 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003910 n_attr = 0;
3911 }
3912 }
3913
3914 }
3915#endif // FEAT_CONCEAL
3916 else
3917 --n_skip;
3918
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003919 // Only advance the "wlv.vcol" when after the 'number' or
3920 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003921 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003922#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003923 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003924#endif
3925 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003926 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003927
3928#ifdef FEAT_SYN_HL
3929 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003930 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003931#endif
3932
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003933 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003934 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3935 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003936
3937 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003938 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003939 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003940 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003941 if (wlv.n_attr_skip > 0)
3942 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943
3944 // At end of screen line and there is more to come: Display the line
3945 // so far. If there is no more to display it is caught above.
3946 if ((
3947#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003948 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003949#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003950 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003951 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003952 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003953#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003954 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003955#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003956#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003957 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003958#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003959 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003960 && wlv.p_extra != at_end_str)
3961 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3962 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003963 )
3964 {
3965#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003966 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003967 wlv_screen_line(wp, &wlv, FALSE);
3968 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003969 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003970 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003971#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003972 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003973#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003974 ++wlv.row;
3975 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003976
3977 // When not wrapping and finished diff lines, or when displayed
3978 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003979 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003980#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003981 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003982#endif
3983#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003984 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003985#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003986 ) || lcs_eol_one == -1)
3987#ifdef FEAT_PROP_POPUP
3988 && !text_prop_follows
3989#endif
3990 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003991 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003992#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003993 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003994 {
3995 // do not output more of the line, only the "below" prop
3996 ptr += STRLEN(ptr);
3997# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003998 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003999# endif
4000 }
4001#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004002
4003 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004004 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004005#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004006 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004007#endif
4008 )
4009 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004010 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4011 draw_vsep_win(wp, wlv.row);
4012 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004013 }
4014
4015 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004016 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004017 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004018 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004019 break;
4020 }
4021
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004022 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004023#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004024 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004025#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004026#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004027 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004028#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004029 && wp->w_width == Columns)
4030 {
4031 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004032 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004033
4034 // Special trick to make copy/paste of wrapped lines work with
4035 // xterm/screen: write an extra character beyond the end of
4036 // the line. This will work with all terminal types
4037 // (regardless of the xn,am settings).
4038 // Only do this on a fast tty.
4039 // Only do this if the cursor is on the current line
4040 // (something has been written in it).
4041 // Don't do this for the GUI.
4042 // Don't do this for double-width characters.
4043 // Don't do this for a window not at the right screen border.
4044 if (p_tf
4045#ifdef FEAT_GUI
4046 && !gui.in_use
4047#endif
4048 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004049 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4050 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004051 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004052 || (*mb_off2cells)(
4053 LineOffset[wlv.screen_row - 1]
4054 + (int)Columns - 2,
4055 LineOffset[wlv.screen_row]
4056 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004057 {
4058 // First make sure we are at the end of the screen line,
4059 // then output the same character again to let the
4060 // terminal know about the wrap. If the terminal doesn't
4061 // auto-wrap, we overwrite the character.
4062 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004063 screen_char(LineOffset[wlv.screen_row - 1]
4064 + (unsigned)Columns - 1,
4065 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004066
4067 // When there is a multi-byte character, just output a
4068 // space to keep it simple.
4069 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004070 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004071 out_char(' ');
4072 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004073 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004074 + (Columns - 1)]);
4075 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004076 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004077 screen_start(); // don't know where cursor is now
4078 }
4079 }
4080
Bram Moolenaar1306b362022-08-06 15:59:06 +01004081 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004082
Bram Moolenaareed9d462021-02-15 20:38:25 +01004083 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004084#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004085 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004086# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004087 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004088# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004089 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004090 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004091#endif
4092#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004093 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004094 // When the filler lines are actually below the last line of the
4095 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004096 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004097 break;
4098#endif
4099 }
4100
4101 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004102#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004103 vim_free(text_props);
4104 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004105 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004106#endif
4107
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004108 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004109 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004110}