blob: c7510a65a2408fc5a910d502194bb00593114eb3 [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
Bram Moolenaareb4de622022-10-15 13:42:17 +0100392 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
393 || (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 Moolenaar04e0ed12022-09-10 20:00:56 +0100668 }
669 else
670 {
671 // Right-align: fill with before
672 if (right)
673 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000674
675 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000676 if (below && vcol == 0 && col_with_padding == col_off
677 && wp->w_width - col_off == before)
678 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000679
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100680 if (before < 0
681 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000682 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
683 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100684 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100685 if (right && (wrap
686 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100687 {
688 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100689 before = wp->w_width - col_off - strsize + room;
690 if (before < 0)
691 before = 0;
692 else
693 n_used = *n_extra;
694 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000695 else if (below && before > vcol && do_skip)
696 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100697 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100698 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100699 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100700 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100701
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100702 // With 'nowrap' add one to show the "extends" character if needed (it
703 // doesn't show if the text just fits).
704 if (!wp->w_p_wrap
705 && n_used < *n_extra
706 && wp->w_lcs_chars.ext != NUL
707 && wp->w_p_list)
708 ++n_used;
709
710 // add 1 for NUL, 2 for when '…' is used
711 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100712 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100713 if (n_attr == NULL || l != NULL)
714 {
715 int off = 0;
716
717 if (n_attr != NULL)
718 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100719 vim_memset(l, ' ', before);
720 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100721 if (padding > 0)
722 {
723 vim_memset(l + off, ' ', padding);
724 off += padding;
725 }
726 vim_strncpy(l + off, *p_extra, n_used);
727 off += n_used;
728 }
729 else
730 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100731 off = before + after + padding + n_used;
732 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100733 }
734 if (n_attr != NULL)
735 {
736 if (n_used < *n_extra && wp->w_p_wrap)
737 {
738 char_u *lp = l + off - 1;
739
740 if (has_mbyte)
741 {
h-east4c42c7e2023-04-17 21:44:57 +0100742 char_u buf[MB_MAXBYTES + 1];
743 char_u *cp = buf;
744
745 // change the last character to '…', converted to the
746 // current 'encoding'
747 STRCPY(buf, "…");
748 if (!enc_utf8)
749 {
750 vimconv_T vc;
751
752 vc.vc_type = CONV_NONE;
753 convert_setup(&vc, (char_u *)"utf-8", p_enc);
754 if (vc.vc_type != CONV_NONE)
755 {
756 cp = string_convert(&vc, buf, NULL);
757 if (cp == NULL)
758 {
759 // when conversion fails use '>'
760 cp = buf;
761 STRCPY(buf, ">");
762 }
763 convert_setup(&vc, NULL, NULL);
764 }
765 }
766
767 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100768 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100769 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100770 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100771 if (cp != buf)
772 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100773 }
774 else
775 // change last character to '>'
776 *lp = '>';
777 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100778 else if (after > 0)
779 {
780 vim_memset(l + off, ' ', after);
781 l[off + after] = NUL;
782 }
783
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100784 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100785 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100786 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100787 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100788 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100789
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000790 // n_attr_skip will not be decremented before draw_state is
791 // WL_LINE
792 *n_attr_skip = before + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100793 }
794 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100795 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100796
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100797 if (n_attr == NULL)
798 return cells;
799 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200800}
801#endif
802
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100803/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100804 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100805 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
806 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100807 */
808 static void
809wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
810{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100811 if (wlv->row == 0 && wp->w_skipcol > 0
812#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100813 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100814 && *get_showbreak_value(wp) == NUL
815#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100816 // do not overwrite the 'listchars' "precedes" text with "<<<"
817 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100818 {
819 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100820 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100821
Bram Moolenaareb4de622022-10-15 13:42:17 +0100822 if (wp->w_p_nu && wp->w_p_rnu)
823 // Do not overwrite the line number, change "123 text" to
824 // "123>>>xt".
825 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
826 {
827 ++off;
828 ++skip;
829 }
830
831 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100832 {
833 ScreenLines[off] = '<';
834 if (enc_utf8)
835 ScreenLinesUC[off] = 0;
836 ScreenAttrs[off] = HL_ATTR(HLF_AT);
837 ++off;
838 }
839 }
840
841 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
842 negative_width ? -wp->w_width : wp->w_width,
843 wlv->screen_line_flags);
844}
845
846/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100847 * Called when finished with the line: draw the screen line and handle any
848 * highlighting until the right of the window.
849 */
850 static void
851draw_screen_line(win_T *wp, winlinevars_T *wlv)
852{
853#ifdef FEAT_SYN_HL
854 long v;
855
856 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
857 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100858 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100859 else
860 v = wp->w_leftcol;
861
862 // check if line ends before left margin
863 if (wlv->vcol < v + wlv->col - win_col_off(wp))
864 wlv->vcol = v + wlv->col - win_col_off(wp);
865# ifdef FEAT_CONCEAL
866 // Get rid of the boguscols now, we want to draw until the right
867 // edge for 'cursorcolumn'.
868 wlv->col -= wlv->boguscols;
869 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000870# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100871# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000872# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100873# endif
874
875 if (wlv->draw_color_col)
876 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
877
878 if (((wp->w_p_cuc
879 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
880 && (int)wp->w_virtcol <
881 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
882 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000883 || wlv->draw_color_col
884# ifdef LINE_ATTR
885 || wlv->line_attr != 0
886# endif
887 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100888# ifdef FEAT_RIGHTLEFT
889 && !wp->w_p_rl
890# endif
891 )
892 {
893 int rightmost_vcol = 0;
894 int i;
895
896 if (wp->w_p_cuc)
897 rightmost_vcol = wp->w_virtcol;
898 if (wlv->draw_color_col)
899 // determine rightmost colorcolumn to possibly draw
900 for (i = 0; wlv->color_cols[i] >= 0; ++i)
901 if (rightmost_vcol < wlv->color_cols[i])
902 rightmost_vcol = wlv->color_cols[i];
903
904 while (wlv->col < wp->w_width)
905 {
906 ScreenLines[wlv->off] = ' ';
907 if (enc_utf8)
908 ScreenLinesUC[wlv->off] = 0;
909 ScreenCols[wlv->off] = MAXCOL;
910 ++wlv->col;
911 if (wlv->draw_color_col)
912 wlv->draw_color_col = advance_color_col(
913 VCOL_HLC, &wlv->color_cols);
914
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000915 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100916 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000917 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100918 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000919 attr = HL_ATTR(HLF_MC);
920# ifdef LINE_ATTR
921 else if (wlv->line_attr != 0)
922 attr = wlv->line_attr;
923# endif
924 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100925
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000926 if (VCOL_HLC >= rightmost_vcol
927# ifdef LINE_ATTR
928 && wlv->line_attr == 0
929# endif
930 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100931 break;
932
933 ++wlv->vcol;
934 }
935 }
936#endif
937
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100938 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100939 ++wlv->row;
940 ++wlv->screen_row;
941}
942#undef VCOL_HLC
943
944/*
945 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100946 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100947 */
948 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100949win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100950{
951 wlv->col = 0;
952 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
953
954#ifdef FEAT_RIGHTLEFT
955 if (wp->w_p_rl)
956 {
957 // Rightleft window: process the text in the normal direction, but put
958 // it in current_ScreenLine[] from right to left. Start at the
959 // rightmost column of the window.
960 wlv->col = wp->w_width - 1;
961 wlv->off += wlv->col;
962 wlv->screen_line_flags |= SLF_RIGHTLEFT;
963 }
964#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100965 if (save_extra)
966 {
967 // reset the drawing state for the start of a wrapped line
968 wlv->draw_state = WL_START;
969 wlv->saved_n_extra = wlv->n_extra;
970 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000971 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000972 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000973 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100974 wlv->saved_c_extra = wlv->c_extra;
975 wlv->saved_c_final = wlv->c_final;
976#ifdef FEAT_SYN_HL
977 if (!(wlv->cul_screenline
978# ifdef FEAT_DIFF
979 && wlv->diff_hlf == (hlf_T)0
980# endif
981 ))
982 wlv->saved_char_attr = wlv->char_attr;
983 else
984#endif
985 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000986
987 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +0100988 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000989 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100990 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100991}
992
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200993/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100994 * Called when wlv->draw_state is set to WL_LINE.
995 */
996 static void
997win_line_continue(winlinevars_T *wlv)
998{
999 if (wlv->saved_n_extra > 0)
1000 {
1001 // Continue item from end of wrapped line.
1002 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001003 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001004 wlv->c_extra = wlv->saved_c_extra;
1005 wlv->c_final = wlv->saved_c_final;
1006 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001007 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001008 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001009 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001010 wlv->char_attr = wlv->saved_char_attr;
1011 }
1012 else
1013 wlv->char_attr = wlv->win_attr;
1014}
1015
zeertzjqb7acea12022-12-12 13:20:43 +00001016#ifdef FEAT_SYN_HL
1017 static void
1018apply_cursorline_highlight(
1019 winlinevars_T *wlv,
1020 int sign_present UNUSED)
1021{
1022 wlv->cul_attr = HL_ATTR(HLF_CUL);
1023# ifdef FEAT_SIGNS
1024 // Combine the 'cursorline' and sign highlighting, depending on
1025 // the sign priority.
1026 if (sign_present && wlv->sattr.sat_linehl > 0)
1027 {
1028 if (wlv->sattr.sat_priority >= 100)
1029 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1030 else
1031 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1032 }
1033 else
1034# endif
1035# if defined(FEAT_QUICKFIX)
1036 // let the line attribute overrule 'cursorline', otherwise
1037 // it disappears when both have background set;
1038 // 'cursorline' can use underline or bold to make it show
1039 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1040# else
1041 wlv->line_attr = wlv->cul_attr;
1042# endif
1043}
1044#endif
1045
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001046/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001047 * Display line "lnum" of window 'wp' on the screen.
1048 * Start at row "startrow", stop when "endrow" is reached.
1049 * wp->w_virtcol needs to be valid.
1050 *
1051 * Return the number of last row the line occupies.
1052 */
1053 int
1054win_line(
1055 win_T *wp,
1056 linenr_T lnum,
1057 int startrow,
1058 int endrow,
1059 int nochange UNUSED, // not updating for changed text
1060 int number_only) // only update the number column
1061{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001062 winlinevars_T wlv; // variables passed between functions
1063
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001064 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001065 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066 char_u *line; // current line
1067 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001068
Bram Moolenaar1306b362022-08-06 15:59:06 +01001069#ifdef FEAT_PROP_POPUP
1070 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1071#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001072#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001073 int in_linebreak = FALSE; // n_extra set for showing linebreak
1074#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001076 // displaying eol at end-of-line
1077 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001078 int lcs_prec_todo = wp->w_lcs_chars.prec;
1079 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001080
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001081 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001082 int saved_attr2 = 0; // char_attr saved for n_attr
1083 int n_attr3 = 0; // chars with overruling special attr
1084 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085
Bram Moolenaarcd105412022-10-10 19:50:42 +01001086 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1087 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001088#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001089 int skip_cells = 0; // nr of cells to skip for virtual text
1090 // after the line, when w_skipcol is
1091 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001092#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001093
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001094 int fromcol_prev = -2; // start of inverting after cursor
1095 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001096 int lnum_in_visual_area = FALSE;
1097 pos_T pos;
1098 long v;
1099
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100 int attr_pri = FALSE; // char_attr has priority
1101 int area_highlighting = FALSE; // Visual or incsearch highlighting
1102 // in this line
1103 int vi_attr = 0; // attributes for Visual and incsearch
1104 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001105 int area_attr = 0; // attributes desired by highlighting
1106 int search_attr = 0; // attributes desired by 'hlsearch'
1107#ifdef FEAT_SYN_HL
1108 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1109 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001110 int prev_syntax_col = -1; // column of prev_syntax_attr
1111 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001112 int has_syntax = FALSE; // this buffer has syntax highl.
1113 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001115#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001116 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117 int text_prop_count;
1118 int text_prop_next = 0; // next text property to use
1119 textprop_T *text_props = NULL;
1120 int *text_prop_idxs = NULL;
1121 int text_props_active = 0;
1122 proptype_T *text_prop_type = NULL;
1123 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001124 int text_prop_attr_comb = 0; // text_prop_attr combined with
1125 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001126 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001127 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001128 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001129 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001130 int saved_search_attr = 0; // search_attr to be used when n_extra
1131 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001132 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001133 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001134#endif
1135#ifdef FEAT_SPELL
1136 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001137 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138# define SPWORDLEN 150
1139 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1140 int nextlinecol = 0; // column where nextline[] starts
1141 int nextline_idx = 0; // index in nextline[] where next line
1142 // starts
1143 int spell_attr = 0; // attributes desired by spelling
1144 int word_end = 0; // last byte with same spell_attr
1145 static linenr_T checked_lnum = 0; // line number for "checked_col"
1146 static int checked_col = 0; // column in "checked_lnum" up to which
1147 // there are no spell errors
1148 static int cap_col = -1; // column to check for Cap word
1149 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1150 int cur_checked_col = 0; // checked column for current line
1151#endif
1152 int extra_check = 0; // has extra highlighting
1153 int multi_attr = 0; // attributes desired by multibyte
1154 int mb_l = 1; // multi-byte byte length
1155 int mb_c = 0; // decoded multi-byte character
1156 int mb_utf8 = FALSE; // screen char is UTF-8 char
1157 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001159 int change_start = MAXCOL; // first col of changed area
1160 int change_end = -1; // last col of changed area
1161#endif
1162 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001163 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001164 int in_multispace = FALSE; // in multiple consecutive spaces
1165 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001166#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001167 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001168#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001170 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001171#ifdef FEAT_ARABIC
1172 int prev_c = 0; // previous Arabic character
1173 int prev_c1 = 0; // first composing char for prev_c
1174#endif
1175#if defined(LINE_ATTR)
1176 int did_line_attr = 0;
1177#endif
1178#ifdef FEAT_TERMINAL
1179 int get_term_attr = FALSE;
1180#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001181
Martin Tournoijba43e762022-10-13 22:12:15 +01001182#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001183 // margin columns for the screen line, needed for when 'cursorlineopt'
1184 // contains "screenline"
1185 int left_curline_col = 0;
1186 int right_curline_col = 0;
1187#endif
1188
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1190 int feedback_col = 0;
1191 int feedback_old_attr = -1;
1192#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001193
1194#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1195 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001196#endif
1197#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001198 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001199#endif
1200#ifdef FEAT_CONCEAL
1201 int syntax_flags = 0;
1202 int syntax_seqnr = 0;
1203 int prev_syntax_id = 0;
1204 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1205 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001206 int did_wcol = FALSE;
1207 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001208# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209# define FIX_FOR_BOGUSCOLS \
1210 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001211 wlv.n_extra += wlv.vcol_off_co; \
1212 wlv.vcol -= wlv.vcol_off_co; \
1213 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001214 wlv.col -= wlv.boguscols; \
1215 old_boguscols = wlv.boguscols; \
1216 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001217 }
1218#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001219# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220#endif
1221
1222 if (startrow > endrow) // past the end already!
1223 return startrow;
1224
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001225 CLEAR_FIELD(wlv);
1226
1227 wlv.lnum = lnum;
1228 wlv.startrow = startrow;
1229 wlv.row = startrow;
1230 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001231 wlv.fromcol = -10;
1232 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001233#ifdef FEAT_LINEBREAK
1234 wlv.vcol_sbr = -1;
1235#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236
1237 if (!number_only)
1238 {
1239 // To speed up the loop below, set extra_check when there is linebreak,
1240 // trailing white space and/or syntax processing to be done.
1241#ifdef FEAT_LINEBREAK
1242 extra_check = wp->w_p_lbr;
1243#endif
1244#ifdef FEAT_SYN_HL
1245 if (syntax_present(wp) && !wp->w_s->b_syn_error
1246# ifdef SYN_TIME_LIMIT
1247 && !wp->w_s->b_syn_slow
1248# endif
1249 )
1250 {
1251 // Prepare for syntax highlighting in this line. When there is an
1252 // error, stop syntax highlighting.
1253 save_did_emsg = did_emsg;
1254 did_emsg = FALSE;
1255 syntax_start(wp, lnum);
1256 if (did_emsg)
1257 wp->w_s->b_syn_error = TRUE;
1258 else
1259 {
1260 did_emsg = save_did_emsg;
1261#ifdef SYN_TIME_LIMIT
1262 if (!wp->w_s->b_syn_slow)
1263#endif
1264 {
1265 has_syntax = TRUE;
1266 extra_check = TRUE;
1267 }
1268 }
1269 }
1270
1271 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001272 wlv.color_cols = wp->w_p_cc_cols;
1273 if (wlv.color_cols != NULL)
1274 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275#endif
1276
1277#ifdef FEAT_TERMINAL
1278 if (term_show_buffer(wp->w_buffer))
1279 {
1280 extra_check = TRUE;
1281 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001282 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001283 }
1284#endif
1285
1286#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001287 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288 {
1289 // Prepare for spell checking.
1290 has_spell = TRUE;
1291 extra_check = TRUE;
1292
1293 // Get the start of the next line, so that words that wrap to the
1294 // next line are found too: "et<line-break>al.".
1295 // Trick: skip a few chars for C/shell/Vim comments
1296 nextline[SPWORDLEN] = NUL;
1297 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1298 {
1299 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1300 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1301 }
1302
1303 // When a word wrapped from the previous line the start of the
1304 // current line is valid.
1305 if (lnum == checked_lnum)
1306 cur_checked_col = checked_col;
1307 checked_lnum = 0;
1308
1309 // When there was a sentence end in the previous line may require a
1310 // word starting with capital in this line. In line 1 always check
1311 // the first word.
1312 if (lnum != capcol_lnum)
1313 cap_col = -1;
1314 if (lnum == 1)
1315 cap_col = 0;
1316 capcol_lnum = 0;
1317 }
1318#endif
1319
1320 // handle Visual active in this window
1321 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1322 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001323 pos_T *top, *bot;
1324
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001325 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1326 {
1327 // Visual is after curwin->w_cursor
1328 top = &curwin->w_cursor;
1329 bot = &VIsual;
1330 }
1331 else
1332 {
1333 // Visual is before curwin->w_cursor
1334 top = &VIsual;
1335 bot = &curwin->w_cursor;
1336 }
1337 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1338 if (VIsual_mode == Ctrl_V)
1339 {
1340 // block mode
1341 if (lnum_in_visual_area)
1342 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001343 wlv.fromcol = wp->w_old_cursor_fcol;
1344 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 }
1346 }
1347 else
1348 {
1349 // non-block mode
1350 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001351 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 else if (lnum == top->lnum)
1353 {
1354 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001355 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 else
1357 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001358 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001360 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 }
1362 }
1363 if (VIsual_mode != 'V' && lnum == bot->lnum)
1364 {
1365 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1366 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001367 wlv.fromcol = -10;
1368 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 }
1370 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001371 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 else
1373 {
1374 pos = *bot;
1375 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001376 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1377 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001378 else
1379 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001380 getvvcol(wp, &pos, NULL, NULL,
1381 (colnr_T *)&wlv.tocol);
1382 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 }
1384 }
1385 }
1386 }
1387
1388 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001389 if (!highlight_match && lnum == curwin->w_cursor.lnum
1390 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001391#ifdef FEAT_GUI
1392 && !gui.in_use
1393#endif
1394 )
1395 noinvcur = TRUE;
1396
1397 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001398 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001399 {
1400 area_highlighting = TRUE;
1401 vi_attr = HL_ATTR(HLF_V);
1402#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1403 if ((clip_star.available && !clip_star.owned
1404 && clip_isautosel_star())
1405 || (clip_plus.available && !clip_plus.owned
1406 && clip_isautosel_plus()))
1407 vi_attr = HL_ATTR(HLF_VNC);
1408#endif
1409 }
1410 }
1411
1412 // handle 'incsearch' and ":s///c" highlighting
1413 else if (highlight_match
1414 && wp == curwin
1415 && lnum >= curwin->w_cursor.lnum
1416 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1417 {
1418 if (lnum == curwin->w_cursor.lnum)
1419 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001420 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001422 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1424 {
1425 pos.lnum = lnum;
1426 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001427 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 }
1429 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001430 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001432 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1433 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 area_highlighting = TRUE;
1435 vi_attr = HL_ATTR(HLF_I);
1436 }
1437 }
1438
1439#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001440 wlv.filler_lines = diff_check(wp, lnum);
1441 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001443 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444 {
1445 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001446 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001448 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001450 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 }
1452 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001453 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001454 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 area_highlighting = TRUE;
1456 }
1457 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001458 wlv.filler_lines = wp->w_topfill;
1459 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460#endif
1461
1462#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001463 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001464 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001465 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466#endif
1467
1468#ifdef LINE_ATTR
1469# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001470 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001472 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473# endif
1474# if defined(FEAT_QUICKFIX)
1475 // Highlight the current line in the quickfix window.
1476 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001477 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001479 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480 area_highlighting = TRUE;
1481#endif
1482
1483 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1484 ptr = line;
1485
1486#ifdef FEAT_SPELL
1487 if (has_spell && !number_only)
1488 {
1489 // For checking first word with a capital skip white space.
1490 if (cap_col == 0)
1491 cap_col = getwhitecols(line);
1492
1493 // To be able to spell-check over line boundaries copy the end of the
1494 // current line into nextline[]. Above the start of the next line was
1495 // copied to nextline[SPWORDLEN].
1496 if (nextline[SPWORDLEN] == NUL)
1497 {
1498 // No next line or it is empty.
1499 nextlinecol = MAXCOL;
1500 nextline_idx = 0;
1501 }
1502 else
1503 {
1504 v = (long)STRLEN(line);
1505 if (v < SPWORDLEN)
1506 {
1507 // Short line, use it completely and append the start of the
1508 // next line.
1509 nextlinecol = 0;
1510 mch_memmove(nextline, line, (size_t)v);
1511 STRMOVE(nextline + v, nextline + SPWORDLEN);
1512 nextline_idx = v + 1;
1513 }
1514 else
1515 {
1516 // Long line, use only the last SPWORDLEN bytes.
1517 nextlinecol = v - SPWORDLEN;
1518 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1519 nextline_idx = SPWORDLEN + 1;
1520 }
1521 }
1522 }
1523#endif
1524
1525 if (wp->w_p_list)
1526 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001527 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001528 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001529 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001530 || wp->w_lcs_chars.trail
1531 || wp->w_lcs_chars.lead
1532 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001534
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001536 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537 {
1538 trailcol = (colnr_T)STRLEN(ptr);
1539 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1540 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001541 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001543 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001544 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001545 {
1546 leadcol = 0;
1547 while (VIM_ISWHITE(ptr[leadcol]))
1548 ++leadcol;
1549 if (ptr[leadcol] == NUL)
1550 // in a line full of spaces all of them are treated as trailing
1551 leadcol = (colnr_T)0;
1552 else
1553 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001554 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001555 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556 }
1557
Bram Moolenaard7657e92022-09-20 18:59:30 +01001558 wlv.wcr_attr = get_wcr_attr(wp);
1559 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001561 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562 area_highlighting = TRUE;
1563 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001564
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001565 // When w_skipcol is non-zero and there is virtual text above the actual
1566 // text, then this much of the virtual text is skipped.
1567 int skipcol_in_text_prop_above = 0;
1568
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001569#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001571 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001572
1573 char_u *prop_start;
1574 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1575 if (text_prop_count > 0)
1576 {
1577 // Make a copy of the properties, so that they are properly
1578 // aligned.
1579 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1580 if (text_props != NULL)
1581 mch_memmove(text_props, prop_start,
1582 text_prop_count * sizeof(textprop_T));
1583
1584 // Allocate an array for the indexes.
1585 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1586 if (text_prop_idxs == NULL)
1587 VIM_CLEAR(text_props);
1588
1589 if (text_props != NULL)
1590 {
1591 area_highlighting = TRUE;
1592 extra_check = TRUE;
1593
1594 // When skipping virtual text the props need to be sorted. The
1595 // order is reversed!
1596 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1597 {
1598 for (int i = 0; i < text_prop_count; ++i)
1599 text_prop_idxs[i] = i;
1600 sort_text_props(wp->w_buffer, text_props,
1601 text_prop_idxs, text_prop_count);
1602 }
1603
1604 // Text props "above" move the line number down to where the text
1605 // is. Only count the ones that are visible, not those that are
1606 // skipped because of w_skipcol.
1607 int text_width = wp->w_width - win_col_off(wp);
1608 for (int i = text_prop_count - 1; i >= 0; --i)
1609 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1610 {
1611 if (lnum == wp->w_topline
1612 && wp->w_skipcol - skipcol_in_text_prop_above
1613 >= text_width)
1614 {
1615 // This virtual text above is skipped, remove it from
1616 // the array.
1617 skipcol_in_text_prop_above += text_width;
1618 for (int j = i + 1; j < text_prop_count; ++j)
1619 text_props[j - 1] = text_props[j];
1620 ++i;
1621 --text_prop_count;
1622 }
1623 else
1624 ++wlv.text_prop_above_count;
1625 }
1626 }
1627 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001628
1629 if (number_only)
1630 {
1631 // skip over rows only used for virtual text above
1632 wlv.row += wlv.text_prop_above_count;
1633 if (wlv.row > endrow)
1634 return wlv.row;
1635 wlv.screen_row += wlv.text_prop_above_count;
1636 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637#endif
1638
1639 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1640 // first character to be displayed.
1641 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001642 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001643 else
1644 v = wp->w_leftcol;
1645 if (v > 0 && !number_only)
1646 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001647 char_u *prev_ptr = ptr;
1648 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001649 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001651 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001652 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001653 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001654 charsize = win_lbr_chartabsize(&cts, NULL);
1655 cts.cts_vcol += charsize;
1656 prev_ptr = cts.cts_ptr;
1657 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001658 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001659 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001660 ptr = cts.cts_ptr;
1661 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662
1663 // When:
1664 // - 'cuc' is set, or
1665 // - 'colorcolumn' is set, or
1666 // - 'virtualedit' is set, or
1667 // - the visual mode is active,
1668 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001669 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001670#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001671 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672#endif
1673 virtual_active() ||
1674 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001675 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676
1677 // Handle a character that's not completely on the screen: Put ptr at
1678 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001679 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001681 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 ptr = prev_ptr;
1683 // If the character fits on the screen, don't need to skip it.
1684 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001685 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1686 && wlv.col == 0)
1687 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688 }
1689
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001690#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001691 // If there the text doesn't reach to the desired column, need to skip
1692 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001693 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1694 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001695 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001696#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001697
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001698 // Adjust for when the inverted text is before the screen,
1699 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001700 if (wlv.tocol <= wlv.vcol)
1701 wlv.fromcol = 0;
1702 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1703 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704
1705#ifdef FEAT_LINEBREAK
1706 // When w_skipcol is non-zero, first line needs 'showbreak'
1707 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001708 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709#endif
1710#ifdef FEAT_SPELL
1711 // When spell checking a word we need to figure out the start of the
1712 // word and if it's badly spelled or not.
1713 if (has_spell)
1714 {
1715 int len;
1716 colnr_T linecol = (colnr_T)(ptr - line);
1717 hlf_T spell_hlf = HLF_COUNT;
1718
1719 pos = wp->w_cursor;
1720 wp->w_cursor.lnum = lnum;
1721 wp->w_cursor.col = linecol;
1722 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1723
1724 // spell_move_to() may call ml_get() and make "line" invalid
1725 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1726 ptr = line + linecol;
1727
1728 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1729 {
1730 // no bad word found at line start, don't check until end of a
1731 // word
1732 spell_hlf = HLF_COUNT;
1733 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1734 }
1735 else
1736 {
1737 // bad word found, use attributes until end of word
1738 word_end = wp->w_cursor.col + len + 1;
1739
1740 // Turn index into actual attributes.
1741 if (spell_hlf != HLF_COUNT)
1742 spell_attr = highlight_attr[spell_hlf];
1743 }
1744 wp->w_cursor = pos;
1745
1746# ifdef FEAT_SYN_HL
1747 // Need to restart syntax highlighting for this line.
1748 if (has_syntax)
1749 syntax_start(wp, lnum);
1750# endif
1751 }
1752#endif
1753 }
1754
1755 // Correct highlighting for cursor that can't be disabled.
1756 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001757 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 {
1759 if (noinvcur)
1760 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001761 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762 {
1763 // highlighting starts at cursor, let it start just after the
1764 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001765 fromcol_prev = wlv.fromcol;
1766 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001768 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769 // restart highlighting after the cursor
1770 fromcol_prev = wp->w_virtcol;
1771 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001772 if (wlv.fromcol >= wlv.tocol)
1773 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 }
1775
1776#ifdef FEAT_SEARCH_EXTRA
1777 if (!number_only)
1778 {
1779 v = (long)(ptr - line);
1780 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1781 &line, &screen_search_hl,
1782 &search_attr);
1783 ptr = line + v; // "line" may have been updated
1784 }
1785#endif
1786
1787#ifdef FEAT_SYN_HL
1788 // Cursor line highlighting for 'cursorline' in the current window.
1789 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1790 {
1791 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001792 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001793 if (!(wp == curwin && VIsual_active)
1794 && wp->w_p_culopt_flags != CULOPT_NBR)
1795 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001796 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1798
zeertzjqb7acea12022-12-12 13:20:43 +00001799 // Only apply CursorLine highlight here when "screenline" is not
1800 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001801 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001802 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803 else
1804 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001805 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1807 }
1808 area_highlighting = TRUE;
1809 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 }
1811#endif
1812
Bram Moolenaar1306b362022-08-06 15:59:06 +01001813 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814
1815 // Repeat for the whole displayed line.
1816 for (;;)
1817 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001818 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001820 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821#endif
1822#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001823 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001825
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001827 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001828 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001829#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001830 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001831 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001832 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001833 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001834 }
1835#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001836 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001837 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001838 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001839 if (cmdwin_type != 0 && wp == curwin)
1840 {
1841 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001842 wlv.n_extra = 1;
1843 wlv.c_extra = cmdwin_type;
1844 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001845 wlv.char_attr =
1846 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001847 }
1848 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001850 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001851 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001852 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001853 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 }
1855#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001857 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001858 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001859 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001860 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001862 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 }
1864#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001865 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001867 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001868 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001869 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001870 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001872 // Check if 'breakindent' applies and show it.
1873 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1874 if (wlv.n_extra == 0)
1875 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001876#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001878 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001880 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001881 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 }
1883#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001884 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001885 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001886 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001887 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 }
1889 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001890
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001892 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001893 && wlv.vcol >= left_curline_col
1894 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001895 {
zeertzjqb7acea12022-12-12 13:20:43 +00001896 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001897 }
1898#endif
1899
1900 // When still displaying '$' of change command, stop at cursor.
1901 // When only displaying the (relative) line number and that's done,
1902 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001903 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001904 && lnum == wp->w_cursor.lnum
1905 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001906 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001908 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001909#endif
1910 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001911 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001912 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 // Pretend we have finished updating the window. Except when
1914 // 'cursorcolumn' is set.
1915#ifdef FEAT_SYN_HL
1916 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001917 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 else
1919#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001920 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001921 break;
1922 }
1923
Bram Moolenaar1306b362022-08-06 15:59:06 +01001924 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001925 {
1926 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001927 if (wlv.vcol == wlv.fromcol
1928 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1929 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 && (*mb_ptr2cells)(ptr) > 1)
1931 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001932 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001933 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001934 area_attr = vi_attr; // start highlighting
1935 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001936 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001937 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 area_attr = 0; // stop highlighting
1939
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001940#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 if (text_props != NULL)
1942 {
1943 int pi;
1944 int bcol = (int)(ptr - line);
1945
Bram Moolenaar1306b362022-08-06 15:59:06 +01001946 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001947# ifdef FEAT_LINEBREAK
1948 && !in_linebreak
1949# endif
1950 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951 --bcol; // still working on the previous char, e.g. Tab
1952
1953 // Check if any active property ends.
1954 for (pi = 0; pi < text_props_active; ++pi)
1955 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001956 int tpi = text_prop_idxs[pi];
1957 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001959 // An inline property ends when after the start column plus
1960 // length. An "above" property ends when used and n_extra
1961 // is zero.
1962 if ((tp->tp_col != MAXCOL
1963 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001964 {
1965 if (pi + 1 < text_props_active)
1966 mch_memmove(text_prop_idxs + pi,
1967 text_prop_idxs + pi + 1,
1968 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001969 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001970 --text_props_active;
1971 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001972# ifdef FEAT_LINEBREAK
1973 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001974 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001975 syntax_attr = 0;
1976# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001977 }
1978 }
1979
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001980# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001981 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001982 // not on the next char yet, don't start another prop
1983 --bcol;
1984# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001985 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001986
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001987 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001988 // With 'nowrap' and not in the first screen line only "below"
1989 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001991 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001992 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001993 && (wp->w_p_wrap
1994 || wlv.row == startrow
1995 || (text_props[text_prop_next].tp_flags
1996 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001997 || (bcol == 0
1998 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001999 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002000 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002001 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002002 if (text_props[text_prop_next].tp_col == MAXCOL
2003 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002004 + text_props[text_prop_next].tp_len)
2005 text_prop_idxs[text_props_active++] = text_prop_next;
2006 ++text_prop_next;
2007 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002008
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002009 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002010 {
2011 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002012 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002013 text_prop_flags = 0;
2014 text_prop_type = NULL;
2015 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002016 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002017 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002018 if (text_props_active > 0 && wlv.n_extra == 0
2019 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002020 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002021 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002022 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002023 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002024
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002025 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002026 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002027
2028 // Sort the properties on priority and/or starting last.
2029 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002030 sort_text_props(wp->w_buffer, text_props,
2031 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002032
2033 for (pi = 0; pi < text_props_active; ++pi)
2034 {
2035 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002036 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002037 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002038 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002039
Bram Moolenaarcd105412022-10-10 19:50:42 +01002040 // Only use a text property that can be displayed.
2041 // Skip "after" properties when wrap is off and at the
2042 // end of the window.
2043 if (pt != NULL
2044 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2045 && tp->tp_id != -MAXCOL
2046 && !(tp->tp_id < 0
2047 && !wp->w_p_wrap
2048 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2049 | TP_FLAG_ALIGN_ABOVE
2050 | TP_FLAG_ALIGN_BELOW)) == 0
2051 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002052 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002053 if (tp->tp_col == MAXCOL
2054 && *ptr == NUL
2055 && ((wp->w_p_list && lcs_eol_one > 0
2056 && (tp->tp_flags
2057 & TP_FLAG_ALIGN_ABOVE) == 0)
2058 || (ptr == line
2059 && !did_line
2060 && (tp->tp_flags
2061 & TP_FLAG_ALIGN_BELOW))))
2062 {
2063 // skip this prop, first display the '$' after
2064 // the line or display an empty line
2065 text_prop_follows = TRUE;
2066 if (used_tpi < 0)
2067 display_text_first = TRUE;
2068 continue;
2069 }
2070
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002071 if (pt->pt_hl_id > 0)
2072 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002073 text_prop_type = pt;
2074 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002075 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002076 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2077 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002078 text_prop_flags = pt->pt_flags;
2079 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002080 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002081 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002082 }
2083 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002084 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002085 && -text_prop_id
2086 <= wp->w_buffer->b_textprop_text.ga_len)
2087 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002088 textprop_T *tp = &text_props[used_tpi];
2089 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002090 ->b_textprop_text.ga_data)[
2091 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002092 int above = (tp->tp_flags
2093 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002094 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002095
2096 // reset the ID in the copy to avoid it being used
2097 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002098 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002099
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002100 if (p != NULL)
2101 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002102 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002103 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002104 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002105 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002106 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2107 int padding = tp->tp_col == MAXCOL
2108 && tp->tp_len > 1
2109 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002110
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002111 // Insert virtual text before the current
2112 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002113 wlv.p_extra = p;
2114 wlv.c_extra = NUL;
2115 wlv.c_final = NUL;
2116 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002117 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002118 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2119 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002120 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002121 // restore search_attr and area_attr when n_extra
2122 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002123 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002124 saved_area_attr = area_attr;
2125 search_attr = 0;
2126 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002127 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002128 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002129 if (*ptr == NUL)
2130 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002131 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002132#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002133 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002134 {
2135 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002136 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002137 wlv.need_showbreak = FALSE;
2138 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002139 }
2140#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002141 if ((right || above || below || !wrap
2142 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002143 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002144 char_u *prev_p_extra = wlv.p_extra;
2145 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002146
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002147 // Take care of padding, right-align and
2148 // truncation.
2149 // Shared with win_lbr_chartabsize(), must do
2150 // exactly the same.
2151 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002152 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002153 wlv.col,
2154 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002155 &n_attr, &wlv.n_attr_skip,
2156 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002157 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002158 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002159 // wlv.p_extra was allocated
2160 vim_free(p_extra_free2);
2161 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002162 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002163
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002164 if (above)
2165 wlv.vcol_off_tp = wlv.n_extra;
2166
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002167 if (lcs_eol_one < 0
2168 && wp->w_p_wrap
2169 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002170 + wlv.n_extra - 2 > wp->w_width)
2171 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002172 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002173
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002174 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002175 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002176 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002177 {
2178 draw_screen_line(wp, &wlv);
2179
2180 // When line got too long for screen break
2181 // here.
2182 if (wlv.row == endrow)
2183 {
2184 ++wlv.row;
2185 break;
2186 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002187 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002188 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002189 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002190 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002191 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002192
Bram Moolenaarcd105412022-10-10 19:50:42 +01002193 // If the text didn't reach until the first window
2194 // column we need to skip cells.
2195 if (skip_cells > 0)
2196 {
2197 if (wlv.n_extra > skip_cells)
2198 {
2199 wlv.n_extra -= skip_cells;
2200 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002201 wlv.n_attr_skip -= skip_cells;
2202 if (wlv.n_attr_skip < 0)
2203 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002204 skip_cells = 0;
2205 }
2206 else
2207 {
2208 // the whole text is left of the window, drop
2209 // it and advance to the next one
2210 skip_cells -= wlv.n_extra;
2211 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002212 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002213 bail_out = TRUE;
2214 }
2215 }
2216
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002217 // If another text prop follows the condition below at
2218 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002219 // If this is an "above" text prop and 'nowrap' the we
2220 // must wrap anyway.
2221 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002222 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002223 && (wp->w_p_wrap
2224 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002225 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002226
2227 if (bail_out)
2228 // starting a new line for "below"
2229 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002230 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002231 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002232 else if (text_prop_next < text_prop_count
2233 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002234 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2235 || (!wp->w_p_wrap
2236 && wlv.col == wp->w_width - 1
2237 && (text_props[text_prop_next].tp_flags
2238 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002239 // When at last-but-one character and a text property
2240 // follows after it, we may need to flush the line after
2241 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002242 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002243 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002244 }
2245#endif
2246
Bram Moolenaare38fc862022-08-11 17:24:50 +01002247#ifdef FEAT_SEARCH_EXTRA
2248 if (wlv.n_extra == 0)
2249 {
2250 // Check for start/end of 'hlsearch' and other matches.
2251 // After end, check for start/end of next match.
2252 // When another match, have to check for start again.
2253 v = (long)(ptr - line);
2254 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2255 &screen_search_hl, &has_match_conc,
2256 &match_conc, did_line_attr, lcs_eol_one,
2257 &on_last_col);
2258 ptr = line + v; // "line" may have been changed
2259 prev_ptr = ptr;
2260
2261 // Do not allow a conceal over EOL otherwise EOL will be missed
2262 // and bad things happen.
2263 if (*ptr == NUL)
2264 has_match_conc = 0;
2265 }
2266#endif
2267
2268#ifdef FEAT_DIFF
2269 if (wlv.diff_hlf != (hlf_T)0)
2270 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002271 // When there is extra text (e.g. virtual text) it gets the
2272 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002273 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2274 && wlv.n_extra == 0)
2275 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002276 if (wlv.diff_hlf == HLF_TXD
2277 && ((ptr - line > change_end && wlv.n_extra == 0)
2278 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002279 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002280 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002281 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2282 && wp->w_p_culopt_flags != CULOPT_NBR
2283 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2284 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002285 wlv.line_attr = hl_combine_attr(
2286 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002287 }
2288#endif
2289
Bram Moolenaara74fda62019-10-19 17:38:03 +02002290#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002291 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002292 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002293 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002294# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002295 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002296 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002297# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002298 // Get syntax attribute.
2299 if (has_syntax)
2300 {
2301 // Get the syntax attribute for the character. If there
2302 // is an error, disable syntax highlighting.
2303 save_did_emsg = did_emsg;
2304 did_emsg = FALSE;
2305
2306 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002307 if (v == prev_syntax_col)
2308 // at same column again
2309 syntax_attr = prev_syntax_attr;
2310 else
2311 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002312# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002313 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002314# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002315 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002316# ifdef FEAT_SPELL
2317 has_spell ? &can_spell :
2318# endif
2319 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002320 prev_syntax_col = v;
2321 prev_syntax_attr = syntax_attr;
2322 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002323
Bram Moolenaar34390282019-10-16 14:38:26 +02002324 if (did_emsg)
2325 {
2326 wp->w_s->b_syn_error = TRUE;
2327 has_syntax = FALSE;
2328 syntax_attr = 0;
2329 }
2330 else
2331 did_emsg = save_did_emsg;
2332# ifdef SYN_TIME_LIMIT
2333 if (wp->w_s->b_syn_slow)
2334 has_syntax = FALSE;
2335# endif
2336
2337 // Need to get the line again, a multi-line regexp may
2338 // have made it invalid.
2339 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2340 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002341 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002342# ifdef FEAT_CONCEAL
2343 // no concealing past the end of the line, it interferes
2344 // with line highlighting
2345 if (*ptr == NUL)
2346 syntax_flags = 0;
2347 else
2348 syntax_flags = get_syntax_info(&syntax_seqnr);
2349# endif
2350 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002351 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002352# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002353 // Combine text property highlight into syntax highlight.
2354 if (text_prop_type != NULL)
2355 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002356 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002357 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2358 else
2359 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002360 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002361 }
2362# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002363#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002364
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002365 // Decide which of the highlight attributes to use.
2366 attr_pri = TRUE;
2367#ifdef LINE_ATTR
2368 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002369 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002370 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002371 if (!highlight_match)
2372 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002373 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002374# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002375 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002376# endif
2377 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002378 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002379 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002380 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002381# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002382 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002383# endif
2384 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002385 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002386 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2387 || wlv.vcol < wlv.fromcol
2388 || vcol_prev < fromcol_prev
2389 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002391 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002392 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002393# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002394 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002395# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002396 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002397# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398 attr_pri = FALSE;
2399 }
2400#else
2401 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002402 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002403 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002404 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002405#endif
2406 else
2407 {
2408 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002409#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002410 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002411#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002412 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002413#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002415#ifdef FEAT_PROP_POPUP
2416 // override with text property highlight when "override" is TRUE
2417 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002418 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002419#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002420 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002421
2422 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002423 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002424 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002425 if (wlv.char_attr == 0)
2426 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002427 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002428 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002429 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002430
2431 // Get the next character to put on the screen.
2432
2433 // The "p_extra" points to the extra stuff that is inserted to
2434 // represent special characters (non-printable stuff) and other
2435 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002436 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2438 // "p_extra[n_extra]".
2439 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002440 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002441 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002442 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002443 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002444 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2445 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2447 if (enc_utf8 && utf_char2len(c) > 1)
2448 {
2449 mb_utf8 = TRUE;
2450 u8cc[0] = 0;
2451 c = 0xc0;
2452 }
2453 else
2454 mb_utf8 = FALSE;
2455 }
2456 else
2457 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002458 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 if (has_mbyte)
2460 {
2461 mb_c = c;
2462 if (enc_utf8)
2463 {
2464 // If the UTF-8 character is more than one byte:
2465 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002466 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002468 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002469 mb_l = 1;
2470 else if (mb_l > 1)
2471 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002472 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002473 mb_utf8 = TRUE;
2474 c = 0xc0;
2475 }
2476 }
2477 else
2478 {
2479 // if this is a DBCS character, put it in "mb_c"
2480 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002481 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002482 mb_l = 1;
2483 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002484 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002485 }
2486 if (mb_l == 0) // at the NUL at end-of-line
2487 mb_l = 1;
2488
2489 // If a double-width char doesn't fit display a '>' in the
2490 // last column.
2491 if ((
2492# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002493 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002494# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002495 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002496 && (*mb_char2cells)(mb_c) == 2)
2497 {
2498 c = '>';
2499 mb_c = c;
2500 mb_l = 1;
2501 mb_utf8 = FALSE;
2502 multi_attr = HL_ATTR(HLF_AT);
2503#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002504 if (wlv.cul_attr)
2505 multi_attr = hl_combine_attr(
2506 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002508 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002509
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 // put the pointer back to output the double-width
2511 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002512 ++wlv.n_extra;
2513 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002514 }
2515 else
2516 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002517 wlv.n_extra -= mb_l - 1;
2518 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 }
2520 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002521 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002523 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002524#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002525 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002526 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002527 // Only restore search_attr and area_attr after "n_extra" in
2528 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002529 if (wlv.saved_n_extra <= 0)
2530 {
2531 if (search_attr == 0)
2532 search_attr = saved_search_attr;
2533 if (area_attr == 0 && *ptr != NUL)
2534 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002535
2536 if (wlv.extra_for_textprop)
2537 // wlv.extra_attr should be used at this position but
2538 // not any further.
2539 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002540 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002541
2542 wlv.extra_for_textprop = FALSE;
2543 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002544 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002545#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 }
2547 else
2548 {
2549#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002550 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002552 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002553
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 // Get a character from the line itself.
2555 c = *ptr;
2556#ifdef FEAT_LINEBREAK
2557 c0 = *ptr;
2558#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002559#ifdef FEAT_PROP_POPUP
2560 if (c == NUL)
2561 // text is finished, may display a "below" virtual text
2562 did_line = TRUE;
2563#endif
2564
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565 if (has_mbyte)
2566 {
2567 mb_c = c;
2568 if (enc_utf8)
2569 {
2570 // If the UTF-8 character is more than one byte: Decode it
2571 // into "mb_c".
2572 mb_l = utfc_ptr2len(ptr);
2573 mb_utf8 = FALSE;
2574 if (mb_l > 1)
2575 {
2576 mb_c = utfc_ptr2char(ptr, u8cc);
2577 // Overlong encoded ASCII or ASCII with composing char
2578 // is displayed normally, except a NUL.
2579 if (mb_c < 0x80)
2580 {
2581 c = mb_c;
2582#ifdef FEAT_LINEBREAK
2583 c0 = mb_c;
2584#endif
2585 }
2586 mb_utf8 = TRUE;
2587
2588 // At start of the line we can have a composing char.
2589 // Draw it as a space with a composing char.
2590 if (utf_iscomposing(mb_c))
2591 {
2592 int i;
2593
2594 for (i = Screen_mco - 1; i > 0; --i)
2595 u8cc[i] = u8cc[i - 1];
2596 u8cc[0] = mb_c;
2597 mb_c = ' ';
2598 }
2599 }
2600
2601 if ((mb_l == 1 && c >= 0x80)
2602 || (mb_l >= 1 && mb_c == 0)
2603 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2604 {
2605 // Illegal UTF-8 byte: display as <xx>.
2606 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002607 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002608# ifdef FEAT_RIGHTLEFT
2609 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002610 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002611# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002612 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002613 c = *wlv.p_extra;
2614 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002616 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2617 wlv.c_extra = NUL;
2618 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619 if (area_attr == 0 && search_attr == 0)
2620 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002621 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002622 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002623 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002624 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625 }
2626 }
2627 else if (mb_l == 0) // at the NUL at end-of-line
2628 mb_l = 1;
2629#ifdef FEAT_ARABIC
2630 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2631 {
2632 // Do Arabic shaping.
2633 int pc, pc1, nc;
2634 int pcc[MAX_MCO];
2635
2636 // The idea of what is the previous and next
2637 // character depends on 'rightleft'.
2638 if (wp->w_p_rl)
2639 {
2640 pc = prev_c;
2641 pc1 = prev_c1;
2642 nc = utf_ptr2char(ptr + mb_l);
2643 prev_c1 = u8cc[0];
2644 }
2645 else
2646 {
2647 pc = utfc_ptr2char(ptr + mb_l, pcc);
2648 nc = prev_c;
2649 pc1 = pcc[0];
2650 }
2651 prev_c = mb_c;
2652
2653 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2654 }
2655 else
2656 prev_c = mb_c;
2657#endif
2658 }
2659 else // enc_dbcs
2660 {
2661 mb_l = MB_BYTE2LEN(c);
2662 if (mb_l == 0) // at the NUL at end-of-line
2663 mb_l = 1;
2664 else if (mb_l > 1)
2665 {
2666 // We assume a second byte below 32 is illegal.
2667 // Hopefully this is OK for all double-byte encodings!
2668 if (ptr[1] >= 32)
2669 mb_c = (c << 8) + ptr[1];
2670 else
2671 {
2672 if (ptr[1] == NUL)
2673 {
2674 // head byte at end of line
2675 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002676 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677 }
2678 else
2679 {
2680 // illegal tail byte
2681 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002682 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002683 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002684 wlv.p_extra = wlv.extra;
2685 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002686 wlv.c_extra = NUL;
2687 wlv.c_final = NUL;
2688 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689 if (area_attr == 0 && search_attr == 0)
2690 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002691 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002692 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002693 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002694 // save current attr
2695 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002696 }
2697 mb_c = c;
2698 }
2699 }
2700 }
2701 // If a double-width char doesn't fit display a '>' in the
2702 // last column; the character is displayed at the start of the
2703 // next line.
2704 if ((
2705# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002706 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002708 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709 && (*mb_char2cells)(mb_c) == 2)
2710 {
2711 c = '>';
2712 mb_c = c;
2713 mb_utf8 = FALSE;
2714 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002715 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002716 // Put pointer back so that the character will be
2717 // displayed at the start of the next line.
2718 --ptr;
2719#ifdef FEAT_CONCEAL
2720 did_decrement_ptr = TRUE;
2721#endif
2722 }
2723 else if (*ptr != NUL)
2724 ptr += mb_l - 1;
2725
2726 // If a double-width char doesn't fit at the left side display
2727 // a '<' in the first column. Don't do this for unprintable
2728 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002729 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002730 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002731 wlv.n_extra = 1;
2732 wlv.c_extra = MB_FILLER_CHAR;
2733 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 c = ' ';
2735 if (area_attr == 0 && search_attr == 0)
2736 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002737 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002738 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002739 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002740 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002741 }
2742 mb_c = c;
2743 mb_utf8 = FALSE;
2744 mb_l = 1;
2745 }
2746
2747 }
2748 ++ptr;
2749
2750 if (extra_check)
2751 {
2752#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 // Check spelling (unless at the end of the line).
2754 // Only do this when there is no syntax highlighting, the
2755 // @Spell cluster is not used or the current syntax item
2756 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002757 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002758 if (has_spell && v >= word_end && v > cur_checked_col)
2759 {
2760 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002761 // do not calculate cap_col at the end of the line or when
2762 // only white space is following
2763 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764# ifdef FEAT_SYN_HL
2765 !has_syntax ||
2766# endif
2767 can_spell))
2768 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002769 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 int len;
2771 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002772
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002773 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775
2776 // Use nextline[] if possible, it has the start of the
2777 // next line concatenated.
2778 if ((prev_ptr - line) - nextlinecol >= 0)
2779 p = nextline + (prev_ptr - line) - nextlinecol;
2780 else
2781 p = prev_ptr;
2782 cap_col -= (int)(prev_ptr - line);
2783 len = spell_check(wp, p, &spell_hlf, &cap_col,
2784 nochange);
2785 word_end = v + len;
2786
2787 // In Insert mode only highlight a word that
2788 // doesn't touch the cursor.
2789 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002790 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791 && wp->w_cursor.lnum == lnum
2792 && wp->w_cursor.col >=
2793 (colnr_T)(prev_ptr - line)
2794 && wp->w_cursor.col < (colnr_T)word_end)
2795 {
2796 spell_hlf = HLF_COUNT;
2797 spell_redraw_lnum = lnum;
2798 }
2799
2800 if (spell_hlf == HLF_COUNT && p != prev_ptr
2801 && (p - nextline) + len > nextline_idx)
2802 {
2803 // Remember that the good word continues at the
2804 // start of the next line.
2805 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002806 checked_col = (int)((p - nextline)
2807 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002808 }
2809
2810 // Turn index into actual attributes.
2811 if (spell_hlf != HLF_COUNT)
2812 spell_attr = highlight_attr[spell_hlf];
2813
2814 if (cap_col > 0)
2815 {
2816 if (p != prev_ptr
2817 && (p - nextline) + cap_col >= nextline_idx)
2818 {
2819 // Remember that the word in the next line
2820 // must start with a capital.
2821 capcol_lnum = lnum + 1;
2822 cap_col = (int)((p - nextline) + cap_col
2823 - nextline_idx);
2824 }
2825 else
2826 // Compute the actual column.
2827 cap_col += (int)(prev_ptr - line);
2828 }
2829 }
2830 }
2831 if (spell_attr != 0)
2832 {
2833 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002834 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2835 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002837 wlv.char_attr = hl_combine_attr(spell_attr,
2838 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002839 }
2840#endif
2841#ifdef FEAT_LINEBREAK
2842 // Found last space before word: check for line break.
2843 if (wp->w_p_lbr && c0 == c
2844 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2845 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002846 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2847 : 0;
2848 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002849 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002851 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002852# ifdef FEAT_PROP_POPUP
2853 // do not want virtual text counted here
2854 cts.cts_has_prop_with_text = FALSE;
2855# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002856 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002857 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002858
2859 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002860 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002861 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002862 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002863 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2864 if (wlv.n_extra < 0)
2865 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002866 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002867 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002868 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002869 // line break, but for TABs the highlighting should
2870 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002871 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002872
Bram Moolenaar1306b362022-08-06 15:59:06 +01002873 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002876 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 wp->w_buffer->b_p_vts_array) - 1;
2878# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002879 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002880 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881# endif
2882
Bram Moolenaar1306b362022-08-06 15:59:06 +01002883 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2884 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002885# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002887 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002888# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889 if (VIM_ISWHITE(c))
2890 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002891# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002892 if (c == TAB)
2893 // See "Tab alignment" below.
2894 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002895# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896 if (!wp->w_p_list)
2897 c = ' ';
2898 }
2899 }
2900#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002901 in_multispace = c == ' '
2902 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2903 if (!in_multispace)
2904 multispace_pos = 0;
2905
Bram Moolenaareed9d462021-02-15 20:38:25 +01002906 // 'list': Change char 160 to 'nbsp' and space to 'space'
2907 // setting in 'listchars'. But not when the character is
2908 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 if (wp->w_p_list
2910 && ((((c == 160 && mb_l == 1)
2911 || (mb_utf8
2912 && ((mb_c == 160 && mb_l == 2)
2913 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002914 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 || (c == ' '
2916 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002917 && (wp->w_lcs_chars.space
2918 || (in_multispace
2919 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002920 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921 && ptr - line <= trailcol)))
2922 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002923 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2924 {
2925 c = wp->w_lcs_chars.multispace[multispace_pos++];
2926 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2927 multispace_pos = 0;
2928 }
2929 else
2930 c = (c == ' ') ? wp->w_lcs_chars.space
2931 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002932 if (area_attr == 0 && search_attr == 0)
2933 {
2934 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002935 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002936 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002937 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 }
2939 mb_c = c;
2940 if (enc_utf8 && utf_char2len(c) > 1)
2941 {
2942 mb_utf8 = TRUE;
2943 u8cc[0] = 0;
2944 c = 0xc0;
2945 }
2946 else
2947 mb_utf8 = FALSE;
2948 }
2949
zeertzjq2e7cba32022-06-10 15:30:32 +01002950 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2951 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002952 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002953 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2954 && wp->w_lcs_chars.leadmultispace != NULL)
2955 {
2956 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002957 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2958 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002959 multispace_pos = 0;
2960 }
2961
2962 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2963 c = wp->w_lcs_chars.trail;
2964
2965 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2966 c = wp->w_lcs_chars.lead;
2967
zeertzjq2e7cba32022-06-10 15:30:32 +01002968 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002969 c = wp->w_lcs_chars.space;
2970
2971
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 if (!attr_pri)
2973 {
2974 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002975 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002976 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002977 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 }
2979 mb_c = c;
2980 if (enc_utf8 && utf_char2len(c) > 1)
2981 {
2982 mb_utf8 = TRUE;
2983 u8cc[0] = 0;
2984 c = 0xc0;
2985 }
2986 else
2987 mb_utf8 = FALSE;
2988 }
2989 }
2990
2991 // Handling of non-printable characters.
2992 if (!vim_isprintc(c))
2993 {
2994 // when getting a character from the file, we may have to
2995 // turn it into something else on the way to putting it
2996 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002997 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002999 int tab_len = 0;
3000 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003002 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003003
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 // only adjust the tab_len, when at the first column
3005 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003006 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003007 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008#endif
3009 // tab amount depends on current column
3010#ifdef FEAT_VARTABS
3011 tab_len = tabstop_padding(vcol_adjusted,
3012 wp->w_buffer->b_p_ts,
3013 wp->w_buffer->b_p_vts_array) - 1;
3014#else
3015 tab_len = (int)wp->w_buffer->b_p_ts
3016 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3017#endif
3018
3019#ifdef FEAT_LINEBREAK
3020 if (!wp->w_p_lbr || !wp->w_p_list)
3021#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003022 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003024 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003025 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026#ifdef FEAT_LINEBREAK
3027 else
3028 {
3029 char_u *p;
3030 int len;
3031 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003032 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003033
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003034# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003035 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003037 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003038
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003040 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003041 && old_boguscols > 0
3042 && wlv.n_extra > tab_len)
3043 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003044# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003045 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003047 // If wlv.n_extra > 0, it gives the number of chars
3048 // to use for a tab, else we need to calculate the
3049 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003050 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3051 len = tab_len * tab2_len;
3052 if (wp->w_lcs_chars.tab3)
3053 len += mb_char2len(wp->w_lcs_chars.tab3)
3054 - tab2_len;
3055 if (wlv.n_extra > 0)
3056 len += wlv.n_extra - tab_len;
3057 c = wp->w_lcs_chars.tab1;
3058 p = alloc(len + 1);
3059 if (p == NULL)
3060 wlv.n_extra = 0;
3061 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003063 vim_memset(p, ' ', len);
3064 p[len] = NUL;
3065 vim_free(wlv.p_extra_free);
3066 wlv.p_extra_free = p;
3067 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003068 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003069 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003070
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003071 if (*p == NUL)
3072 {
3073 tab_len = i;
3074 break;
3075 }
3076
3077 // if tab3 is given, use it for the last
3078 // char
3079 if (wp->w_lcs_chars.tab3
3080 && i == tab_len - 1)
3081 lcs = wp->w_lcs_chars.tab3;
3082 p += mb_char2bytes(lcs, p);
3083 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003084 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003085 }
3086 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003087# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003088 // n_extra will be increased by
3089 // FIX_FOX_BOGUSCOLS macro below, so need to
3090 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003091 if (wlv.vcol_off_co > 0)
3092 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003093# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003094 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003096 }
3097#endif
3098#ifdef FEAT_CONCEAL
3099 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003100 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101
3102 // Tab alignment should be identical regardless of
3103 // 'conceallevel' value. So tab compensates of all
3104 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003105 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003106 // line. Note that the tab can be longer than
3107 // 'tabstop' when there are concealed characters.
3108 FIX_FOR_BOGUSCOLS;
3109
3110 // Make sure, the highlighting for the tab char will be
3111 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003112 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003113 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003114 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003115 tab_len += vc_saved;
3116 }
3117#endif
3118 mb_utf8 = FALSE; // don't draw as UTF-8
3119 if (wp->w_p_list)
3120 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003121 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003122 ? wp->w_lcs_chars.tab3
3123 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003125 if (wp->w_p_lbr && wlv.p_extra != NULL
3126 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003127 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003128 else
3129#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003130 wlv.c_extra = wp->w_lcs_chars.tab2;
3131 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003133 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003134 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003135 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136 mb_c = c;
3137 if (enc_utf8 && utf_char2len(c) > 1)
3138 {
3139 mb_utf8 = TRUE;
3140 u8cc[0] = 0;
3141 c = 0xc0;
3142 }
3143 }
3144 else
3145 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003146 wlv.c_final = NUL;
3147 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003148 c = ' ';
3149 }
3150 }
3151 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003152 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003154 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3155 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003156 && VIsual_mode != Ctrl_V
3157 && (
3158# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003159 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003161 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 && !(noinvcur
3163 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003164 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 && lcs_eol_one > 0)
3166 {
3167 // Display a '$' after the line or highlight an extra
3168 // character if the line break is included.
3169#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3170 // For a diff line the highlighting continues after the
3171 // "$".
3172 if (
3173# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003174 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175# ifdef LINE_ATTR
3176 &&
3177# endif
3178# endif
3179# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003180 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181# endif
3182 )
3183#endif
3184 {
3185 // In virtualedit, visual selections may extend
3186 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003187 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003188 && wlv.tocol != MAXCOL
3189 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003190 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003191 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003192 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003193 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3194 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 else
3196 c = ' ';
3197 lcs_eol_one = -1;
3198 --ptr; // put it back at the NUL
3199 if (!attr_pri)
3200 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003201 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003202 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 n_attr = 1;
3204 }
3205 mb_c = c;
3206 if (enc_utf8 && utf_char2len(c) > 1)
3207 {
3208 mb_utf8 = TRUE;
3209 u8cc[0] = 0;
3210 c = 0xc0;
3211 }
3212 else
3213 mb_utf8 = FALSE; // don't draw as UTF-8
3214 }
3215 else if (c != NUL)
3216 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003217 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3218 if (wlv.n_extra == 0)
3219 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220#ifdef FEAT_RIGHTLEFT
3221 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003222 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003224 wlv.c_extra = NUL;
3225 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226#ifdef FEAT_LINEBREAK
3227 if (wp->w_p_lbr)
3228 {
3229 char_u *p;
3230
Bram Moolenaar1306b362022-08-06 15:59:06 +01003231 c = *wlv.p_extra;
3232 p = alloc(wlv.n_extra + 1);
3233 vim_memset(p, ' ', wlv.n_extra);
3234 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3235 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003236 vim_free(wlv.p_extra_free);
3237 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238 }
3239 else
3240#endif
3241 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003242 wlv.n_extra = byte2cells(c) - 1;
3243 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003244 }
3245 if (!attr_pri)
3246 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003247 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003248 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003249 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003250 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 }
3252 mb_utf8 = FALSE; // don't draw as UTF-8
3253 }
3254 else if (VIsual_active
3255 && (VIsual_mode == Ctrl_V
3256 || VIsual_mode == 'v')
3257 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003258 && wlv.tocol != MAXCOL
3259 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 && (
3261#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003262 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003264 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 {
3266 c = ' ';
3267 --ptr; // put it back at the NUL
3268 }
3269#if defined(LINE_ATTR)
3270 else if ((
3271# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003272 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003273# endif
3274# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003275 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003277 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 ) && (
3279# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003280 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003284 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285# endif
3286 < wp->w_width)))
3287 {
3288 // Highlight until the right side of the window
3289 c = ' ';
3290 --ptr; // put it back at the NUL
3291
3292 // Remember we do the char for line highlighting.
3293 ++did_line_attr;
3294
3295 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003296 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003298 || (wp->w_p_list &&
3299 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003300 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003301# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003302 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003304 wlv.diff_hlf = HLF_CHD;
3305 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003307 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003308 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3309 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003311 || (wlv.vcol >= left_curline_col
3312 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003313 wlv.char_attr = hl_combine_attr(
3314 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315 }
3316 }
3317# endif
3318# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003319 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003321 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003322 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3323 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003325 if (!wlv.cul_screenline
3326 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003327 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003328 wlv.char_attr = hl_combine_attr(
3329 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003331 else if (wlv.line_attr)
3332 wlv.char_attr = hl_combine_attr(
3333 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 }
3335# endif
3336 }
3337#endif
3338 }
3339
3340#ifdef FEAT_CONCEAL
3341 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003342 && (wp != curwin || lnum != wp->w_cursor.lnum
3343 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3345 && !(lnum_in_visual_area
3346 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3347 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003348 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003349 if (((prev_syntax_id != syntax_seqnr
3350 && (syntax_flags & HL_CONCEAL) != 0)
3351 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003352 && (syn_get_sub_char() != NUL
3353 || (has_match_conc && match_conc)
3354 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355 && wp->w_p_cole != 3)
3356 {
3357 // First time at this concealed item: display one
3358 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003359 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360 c = match_conc;
3361 else if (syn_get_sub_char() != NUL)
3362 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003363 else if (wp->w_lcs_chars.conceal != NUL)
3364 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365 else
3366 c = ' ';
3367
3368 prev_syntax_id = syntax_seqnr;
3369
Bram Moolenaar1306b362022-08-06 15:59:06 +01003370 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003371 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003372 wlv.vcol += wlv.n_extra;
3373 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374 {
3375# ifdef FEAT_RIGHTLEFT
3376 if (wp->w_p_rl)
3377 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003378 wlv.col -= wlv.n_extra;
3379 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 }
3381 else
3382# endif
3383 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003384 wlv.boguscols += wlv.n_extra;
3385 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 }
3387 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003388 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 n_attr = 0;
3390 }
3391 else if (n_skip == 0)
3392 {
3393 is_concealing = TRUE;
3394 n_skip = 1;
3395 }
3396 mb_c = c;
3397 if (enc_utf8 && utf_char2len(c) > 1)
3398 {
3399 mb_utf8 = TRUE;
3400 u8cc[0] = 0;
3401 c = 0xc0;
3402 }
3403 else
3404 mb_utf8 = FALSE; // don't draw as UTF-8
3405 }
3406 else
3407 {
3408 prev_syntax_id = 0;
3409 is_concealing = FALSE;
3410 }
3411
3412 if (n_skip > 0 && did_decrement_ptr)
3413 // not showing the '>', put pointer back to avoid getting stuck
3414 ++ptr;
3415
3416#endif // FEAT_CONCEAL
3417 }
3418
3419#ifdef FEAT_CONCEAL
3420 // In the cursor line and we may be concealing characters: correct
3421 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003422 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003423 && wp == curwin && lnum == wp->w_cursor.lnum
3424 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003427# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003429 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003431# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003432 wp->w_wcol = wlv.col - wlv.boguscols;
3433 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 did_wcol = TRUE;
3435 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003436# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003437 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003438# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439 }
3440#endif
3441
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003442 // Use "wlv.extra_attr", but don't override visual selection
3443 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003444 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3445 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003446 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003447 && (!attr_pri
3448#ifdef FEAT_PROP_POPUP
3449 || (text_prop_flags & PT_FLAG_OVERRIDE)
3450#endif
3451 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 {
3453#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003454 if (wlv.line_attr)
3455 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456 else
3457#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003458 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003459#ifdef FEAT_PROP_POPUP
3460 if (reset_extra_attr)
3461 {
3462 reset_extra_attr = FALSE;
3463 wlv.extra_attr = 0;
3464 }
3465#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 }
3467
3468#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3469 // XIM don't send preedit_start and preedit_end, but they send
3470 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3471 // im_is_preediting() here.
3472 if (p_imst == IM_ON_THE_SPOT
3473 && xic != NULL
3474 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003475 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 && !p_imdisable
3477 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003478 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003479 {
3480 colnr_T tcol;
3481
3482 if (preedit_end_col == MAXCOL)
3483 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3484 else
3485 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003486 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 {
3488 if (feedback_old_attr < 0)
3489 {
3490 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003491 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003493 wlv.char_attr = im_get_feedback_attr(feedback_col);
3494 if (wlv.char_attr < 0)
3495 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 feedback_col++;
3497 }
3498 else if (feedback_old_attr >= 0)
3499 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 feedback_old_attr = -1;
3502 feedback_col = 0;
3503 }
3504 }
3505#endif
3506 // Handle the case where we are in column 0 but not on the first
3507 // character of the line and the user wants us to show us a
3508 // special character (via 'listchars' option "precedes:<char>".
3509 if (lcs_prec_todo != NUL
3510 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003511 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3512 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003514 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003516 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517 && c != NUL)
3518 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003519 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 lcs_prec_todo = NUL;
3521 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3522 {
3523 // Double-width character being overwritten by the "precedes"
3524 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003525 wlv.c_extra = MB_FILLER_CHAR;
3526 wlv.c_final = NUL;
3527 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003529 wlv.extra_attr =
3530 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531 }
3532 mb_c = c;
3533 if (enc_utf8 && utf_char2len(c) > 1)
3534 {
3535 mb_utf8 = TRUE;
3536 u8cc[0] = 0;
3537 c = 0xc0;
3538 }
3539 else
3540 mb_utf8 = FALSE; // don't draw as UTF-8
3541 if (!attr_pri)
3542 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003543 saved_attr3 = wlv.char_attr; // save current attr
3544 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 n_attr3 = 1;
3546 }
3547 }
3548
3549 // At end of the text line or just after the last character.
3550 if ((c == NUL
3551#if defined(LINE_ATTR)
3552 || did_line_attr == 1
3553#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003554 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003555 {
3556#ifdef FEAT_SEARCH_EXTRA
3557 // flag to indicate whether prevcol equals startcol of search_hl or
3558 // one of the matches
3559 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3560 (long)(ptr - line) - (c == NUL));
3561#endif
3562 // Invert at least one char, used for Visual and empty line or
3563 // highlight match at end of line. If it's beyond the last
3564 // char on the screen, just overwrite that one (tricky!) Not
3565 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003566 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003567 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568 && (VIsual_mode != Ctrl_V
3569 || lnum == VIsual.lnum
3570 || lnum == curwin->w_cursor.lnum)
3571 && c == NUL)
3572#ifdef FEAT_SEARCH_EXTRA
3573 // highlight 'hlsearch' match at end of line
3574 || (prevcol_hl_flag
3575# ifdef FEAT_SYN_HL
3576 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3577 && !(wp == curwin && VIsual_active))
3578# endif
3579# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003580 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581# endif
3582# if defined(LINE_ATTR)
3583 && did_line_attr <= 1
3584# endif
3585 )
3586#endif
3587 ))
3588 {
3589 int n = 0;
3590
3591#ifdef FEAT_RIGHTLEFT
3592 if (wp->w_p_rl)
3593 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003594 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 n = 1;
3596 }
3597 else
3598#endif
3599 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 n = -1;
3602 }
3603 if (n != 0)
3604 {
3605 // At the window boundary, highlight the last character
3606 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003607 wlv.off += n;
3608 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 }
3610 else
3611 {
3612 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003615 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616 }
3617#ifdef FEAT_SEARCH_EXTRA
3618 if (area_attr == 0)
3619 {
3620 // Use attributes from match with highest priority among
3621 // 'search_hl' and the match list.
3622 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003623 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003624 }
3625#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003626 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003627 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628#ifdef FEAT_RIGHTLEFT
3629 if (wp->w_p_rl)
3630 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003631 --wlv.col;
3632 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 }
3634 else
3635#endif
3636 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003637 ++wlv.col;
3638 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003639 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003640 ++wlv.vcol;
3641 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 }
3643 }
3644
3645 // At end of the text line.
3646 if (c == NUL)
3647 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003648#ifdef FEAT_PROP_POPUP
3649 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003651 // Put the pointer back to the NUL.
3652 --ptr;
3653 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003655 else
3656#endif
3657 {
3658 draw_screen_line(wp, &wlv);
3659
3660 // Update w_cline_height and w_cline_folded if the cursor line
3661 // was updated (saves a call to plines() later).
3662 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3663 {
3664 curwin->w_cline_row = startrow;
3665 curwin->w_cline_height = wlv.row - startrow;
3666#ifdef FEAT_FOLDING
3667 curwin->w_cline_folded = FALSE;
3668#endif
3669 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3670 }
3671 break;
3672 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673 }
3674
3675 // Show "extends" character from 'listchars' if beyond the line end and
3676 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003677 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003678 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679 && wp->w_p_list
3680 && !wp->w_p_wrap
3681#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003682 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683#endif
3684 && (
3685#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003686 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003688 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003689 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003690 || lcs_eol_one > 0
3691 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003692 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003693 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003694 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003695 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696 mb_c = c;
3697 if (enc_utf8 && utf_char2len(c) > 1)
3698 {
3699 mb_utf8 = TRUE;
3700 u8cc[0] = 0;
3701 c = 0xc0;
3702 }
3703 else
3704 mb_utf8 = FALSE;
3705 }
3706
3707#ifdef FEAT_SYN_HL
3708 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003709 if (wlv.draw_color_col)
3710 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711
3712 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3713 // highlight the cursor position itself.
3714 // Also highlight the 'colorcolumn' if it is different than
3715 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003716 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3717 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003719 if (((wlv.draw_state == WL_LINE
3720 || wlv.draw_state == WL_BRI
3721 || wlv.draw_state == WL_SBR)
3722 && !lnum_in_visual_area
3723 && search_attr == 0
3724 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003725# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003726 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003727# endif
3728 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729 {
3730 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3731 && lnum != wp->w_cursor.lnum)
3732 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003733 vcol_save_attr = wlv.char_attr;
3734 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3735 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003737 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003739 vcol_save_attr = wlv.char_attr;
3740 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003741 }
3742 }
3743#endif
3744
3745 // Store character to be displayed.
3746 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003747 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003748 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749 {
3750 // Store the character.
3751#if defined(FEAT_RIGHTLEFT)
3752 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3753 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003754 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003755 --wlv.off;
3756 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 }
3758#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003759 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 if (enc_dbcs == DBCS_JPNU)
3761 {
3762 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003763 ScreenLines[wlv.off] = 0x8e;
3764 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003765 }
3766 else if (enc_utf8)
3767 {
3768 if (mb_utf8)
3769 {
3770 int i;
3771
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003772 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003774 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003775 for (i = 0; i < Screen_mco; ++i)
3776 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003777 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 if (u8cc[i] == 0)
3779 break;
3780 }
3781 }
3782 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003783 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784 }
3785 if (multi_attr)
3786 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003787 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788 multi_attr = 0;
3789 }
3790 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003791 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003793 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003794
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3796 {
3797 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003798 ++wlv.off;
3799 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800 if (enc_utf8)
3801 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003802 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803 else
3804 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003805 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003806 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003807#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003808 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003809#endif
3810 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003811 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003812 // When "wlv.tocol" is halfway a character, set it to the end
3813 // of the character, otherwise highlighting won't stop.
3814 if (wlv.tocol == wlv.vcol)
3815 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003816
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003817 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003818
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819#ifdef FEAT_RIGHTLEFT
3820 if (wp->w_p_rl)
3821 {
3822 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003823 --wlv.off;
3824 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825 }
3826#endif
3827 }
3828#ifdef FEAT_RIGHTLEFT
3829 if (wp->w_p_rl)
3830 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003831 --wlv.off;
3832 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833 }
3834 else
3835#endif
3836 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003837 ++wlv.off;
3838 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003839 }
3840 }
3841#ifdef FEAT_CONCEAL
3842 else if (wp->w_p_cole > 0 && is_concealing)
3843 {
3844 --n_skip;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003845 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003846 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003847 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003848 if (wp->w_p_wrap)
3849 {
3850 // Special voodoo required if 'wrap' is on.
3851 //
3852 // Advance the column indicator to force the line
3853 // drawing to wrap early. This will make the line
3854 // take up the same screen space when parts are concealed,
3855 // so that cursor line computations aren't messed up.
3856 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003857 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003858 // trailing junk to be written out of the screen line
3859 // we are building, 'boguscols' keeps track of the number
3860 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003861 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003863 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003864# ifdef FEAT_RIGHTLEFT
3865 if (wp->w_p_rl)
3866 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003867 wlv.col -= wlv.n_extra;
3868 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003869 }
3870 else
3871# endif
3872 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003873 wlv.col += wlv.n_extra;
3874 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003875 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003876 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003877 n_attr = 0;
3878 }
3879
3880
3881 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3882 {
3883 // Need to fill two screen columns.
3884# ifdef FEAT_RIGHTLEFT
3885 if (wp->w_p_rl)
3886 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003887 --wlv.boguscols;
3888 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889 }
3890 else
3891# endif
3892 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003893 ++wlv.boguscols;
3894 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003895 }
3896 }
3897
3898# ifdef FEAT_RIGHTLEFT
3899 if (wp->w_p_rl)
3900 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003901 --wlv.boguscols;
3902 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003903 }
3904 else
3905# endif
3906 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003907 ++wlv.boguscols;
3908 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003909 }
3910 }
3911 else
3912 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003913 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003915 wlv.vcol += wlv.n_extra;
3916 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003917 n_attr = 0;
3918 }
3919 }
3920
3921 }
3922#endif // FEAT_CONCEAL
3923 else
3924 --n_skip;
3925
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003926 // Only advance the "wlv.vcol" when after the 'number' or
3927 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003928 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003930 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003931#endif
3932 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003933 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003934
3935#ifdef FEAT_SYN_HL
3936 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003937 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003938#endif
3939
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003940 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003941 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3942 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943
3944 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003945 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003946 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003947 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003948 if (wlv.n_attr_skip > 0)
3949 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003950
3951 // At end of screen line and there is more to come: Display the line
3952 // so far. If there is no more to display it is caught above.
3953 if ((
3954#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003955 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003957 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003958 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003959 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003961 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003962#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003963#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003964 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003965#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003966 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003967 && wlv.p_extra != at_end_str)
3968 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3969 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003970 )
3971 {
3972#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003973 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003974 wlv_screen_line(wp, &wlv, FALSE);
3975 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003976 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003977 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003978#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003979 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003980#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003981 ++wlv.row;
3982 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003983
3984 // When not wrapping and finished diff lines, or when displayed
3985 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003986 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003987#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003988 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003989#endif
3990#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003991 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003992#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003993 ) || lcs_eol_one == -1)
3994#ifdef FEAT_PROP_POPUP
3995 && !text_prop_follows
3996#endif
3997 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003998 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003999#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004000 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004001 {
4002 // do not output more of the line, only the "below" prop
4003 ptr += STRLEN(ptr);
4004# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004005 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004006# endif
4007 }
4008#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004009
4010 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004011 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004012#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004013 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004014#endif
4015 )
4016 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004017 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4018 draw_vsep_win(wp, wlv.row);
4019 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004020 }
4021
4022 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004023 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004024 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004025 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004026 break;
4027 }
4028
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004029 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004030#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004031 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004032#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004033#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004034 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004035#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004036 && wp->w_width == Columns)
4037 {
4038 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004039 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004040
4041 // Special trick to make copy/paste of wrapped lines work with
4042 // xterm/screen: write an extra character beyond the end of
4043 // the line. This will work with all terminal types
4044 // (regardless of the xn,am settings).
4045 // Only do this on a fast tty.
4046 // Only do this if the cursor is on the current line
4047 // (something has been written in it).
4048 // Don't do this for the GUI.
4049 // Don't do this for double-width characters.
4050 // Don't do this for a window not at the right screen border.
4051 if (p_tf
4052#ifdef FEAT_GUI
4053 && !gui.in_use
4054#endif
4055 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004056 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4057 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004058 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004059 || (*mb_off2cells)(
4060 LineOffset[wlv.screen_row - 1]
4061 + (int)Columns - 2,
4062 LineOffset[wlv.screen_row]
4063 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004064 {
4065 // First make sure we are at the end of the screen line,
4066 // then output the same character again to let the
4067 // terminal know about the wrap. If the terminal doesn't
4068 // auto-wrap, we overwrite the character.
4069 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004070 screen_char(LineOffset[wlv.screen_row - 1]
4071 + (unsigned)Columns - 1,
4072 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004073
4074 // When there is a multi-byte character, just output a
4075 // space to keep it simple.
4076 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004077 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004078 out_char(' ');
4079 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004080 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004081 + (Columns - 1)]);
4082 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004083 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004084 screen_start(); // don't know where cursor is now
4085 }
4086 }
4087
Bram Moolenaar1306b362022-08-06 15:59:06 +01004088 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004089
Bram Moolenaareed9d462021-02-15 20:38:25 +01004090 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004091#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004092 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004093# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004094 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004095# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004096 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004097 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004098#endif
4099#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004100 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004101 // When the filler lines are actually below the last line of the
4102 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004103 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004104 break;
4105#endif
4106 }
4107
4108 } // for every character in the line
4109
4110#ifdef FEAT_SPELL
4111 // After an empty line check first word for capital.
4112 if (*skipwhite(line) == NUL)
4113 {
4114 capcol_lnum = lnum + 1;
4115 cap_col = 0;
4116 }
4117#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004118#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004119 vim_free(text_props);
4120 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004121 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004122#endif
4123
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004124 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004125 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004126}