blob: 2388193b97820f4b6fff2dd56b480882204b24d7 [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;
zeertzjq86dc4f82024-09-14 10:37:17 +020042 static int prev_width1;
43 static int prev_width2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020044 static int prev_left_col;
45 static int prev_right_col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020046
47 int cur_col_off = win_col_off(wp);
48 int width1;
49 int width2;
50
zeertzjq86dc4f82024-09-14 10:37:17 +020051 width1 = wp->w_width - cur_col_off;
52 width2 = width1 + win_col_off2(wp);
53
54 if (saved_w_virtcol == wp->w_virtcol && prev_wp == wp
55 && prev_width1 == width1 && prev_width2 == width2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020056 {
57 *right_col = prev_right_col;
58 *left_col = prev_left_col;
59 return;
60 }
61
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020062 *left_col = 0;
63 *right_col = width1;
64
zeertzjq59149f02024-09-14 10:40:29 +020065 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020066 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
67 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
68 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
69
70 // cache values
71 prev_left_col = *left_col;
72 prev_right_col = *right_col;
73 prev_wp = wp;
zeertzjq86dc4f82024-09-14 10:37:17 +020074 prev_width1 = width1;
75 prev_width2 = width2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020076 saved_w_virtcol = wp->w_virtcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020077}
78#endif
79
Bram Moolenaar45e4eea2022-12-01 18:38:02 +000080#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
81 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
82// using an attribute for the whole line
83# define LINE_ATTR
84#endif
85
Bram Moolenaar1306b362022-08-06 15:59:06 +010086// structure with variables passed between win_line() and other functions
87typedef struct {
88 int draw_state; // what to draw next
89
90 linenr_T lnum; // line number to be drawn
91
92 int startrow; // first row in the window to be drawn
93 int row; // row in the window, excl w_winrow
94 int screen_row; // row on the screen, incl w_winrow
95
96 long vcol; // virtual column, before wrapping
97 int col; // visual column on screen, after wrapping
98#ifdef FEAT_CONCEAL
99 int boguscols; // nonexistent columns added to "col" to force
100 // wrapping
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000103 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100104#ifdef FEAT_SYN_HL
105 int draw_color_col; // highlight colorcolumn
106 int *color_cols; // pointer to according columns array
107#endif
108 int eol_hl_off; // 1 if highlighted char after EOL
109
110 unsigned off; // offset in ScreenLines/ScreenAttrs
111
112 int win_attr; // background for the whole window, except
113 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100114 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100115#ifdef FEAT_SYN_HL
116 int cul_attr; // set when 'cursorline' active
117#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000118#ifdef LINE_ATTR
119 int line_attr; // for the whole line, includes 'cursorline'
120#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100121
122 int screen_line_flags; // flags for screen_line()
123
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100124 int fromcol; // start of inverting
125 int tocol; // end of inverting
126
127#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100128 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100129 int need_showbreak; // overlong line, skipping first x chars
130 int dont_use_showbreak; // do not use 'showbreak'
131#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100132#ifdef FEAT_PROP_POPUP
133 int text_prop_above_count;
134#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100135
Bram Moolenaar1306b362022-08-06 15:59:06 +0100136 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
137 int cul_screenline;
138
139 int char_attr; // attributes for the next character
140
141 int n_extra; // number of extra bytes
142 char_u *p_extra; // string of extra chars, plus NUL, only used
143 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100144 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000145 int extra_attr; // attributes for p_extra, should be combined
146 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000147 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100148 int c_extra; // extra chars, all the same
149 int c_final; // final char, mandatory if set
zeertzjq6e940d92023-08-17 23:21:40 +0200150 int extra_for_textprop; // n_extra set for textprop
151 int start_extra_for_textprop; // extra_for_textprop was just set
Bram Moolenaar1306b362022-08-06 15:59:06 +0100152
153 // saved "extra" items for when draw_state becomes WL_LINE (again)
154 int saved_n_extra;
155 char_u *saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100156 char_u *saved_p_extra_free;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000157 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000158 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000159 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160 int saved_c_extra;
161 int saved_c_final;
162 int saved_char_attr;
163
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100164 char_u extra[NUMBUFLEN + MB_MAXBYTES];
165 // "%ld " and 'fdc' must fit in here, as well
166 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100167
Bram Moolenaar1306b362022-08-06 15:59:06 +0100168#ifdef FEAT_DIFF
169 hlf_T diff_hlf; // type of diff highlighting
170#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100171 int filler_lines; // nr of filler lines to be drawn
172 int filler_todo; // nr of filler lines still to do + 1
173#ifdef FEAT_SIGNS
174 sign_attrs_T sattr;
175#endif
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200176#ifdef FEAT_LINEBREAK
177 // do consider wrapping in linebreak mode only after encountering
178 // a non whitespace char
179 int need_lbr;
180#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100181} winlinevars_T;
182
183// draw_state values for items that are drawn in sequence:
184#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100185#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100186#ifdef FEAT_FOLDING
187# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
188#else
189# define WL_FOLD WL_CMDLINE
190#endif
191#ifdef FEAT_SIGNS
192# define WL_SIGN (WL_FOLD + 1) // column for signs
193#else
194# define WL_SIGN WL_FOLD // column for signs
195#endif
196#define WL_NR (WL_SIGN + 1) // line number
197#ifdef FEAT_LINEBREAK
198# define WL_BRI (WL_NR + 1) // 'breakindent'
199#else
200# define WL_BRI WL_NR
201#endif
202#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
203# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
204#else
205# define WL_SBR WL_BRI
206#endif
207#define WL_LINE (WL_SBR + 1) // text in the line
208
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100209#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000211 * Return TRUE if CursorLineSign highlight is to be used.
212 */
213 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100214use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000215{
216 return wp->w_p_cul
217 && lnum == wp->w_cursor.lnum
218 && (wp->w_p_culopt_flags & CULOPT_NBR);
219}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100220#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000221
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100222
223#ifdef FEAT_FOLDING
224/*
225 * Setup for drawing the 'foldcolumn', if there is one.
226 */
227 static void
228handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
229{
230 int fdc = compute_foldcolumn(wp, 0);
231
232 if (fdc <= 0)
233 return;
234
235 // Allocate a buffer, "wlv->extra[]" may already be in use.
236 vim_free(wlv->p_extra_free);
237 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000238 if (wlv->p_extra_free == NULL)
239 return;
240
241 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
zeertzjq58e1e012023-06-04 18:46:28 +0100242 wp, FALSE, wlv->lnum);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000243 wlv->p_extra_free[wlv->n_extra] = NUL;
244 wlv->p_extra = wlv->p_extra_free;
245 wlv->c_extra = NUL;
246 wlv->c_final = NUL;
247 if (use_cursor_line_highlight(wp, wlv->lnum))
248 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
249 else
250 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100251}
252#endif
253
254#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000255/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 * Get information needed to display the sign in line "wlv->lnum" in window
257 * "wp".
258 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200259 * Otherwise the sign is going to be displayed in the sign column.
260 */
261 static void
262get_sign_display_info(
263 int nrcol,
264 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100265 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266{
267 int text_sign;
268# ifdef FEAT_SIGN_ICONS
269 int icon_sign;
270# endif
271
272 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100273 wlv->c_extra = ' ';
274 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100276 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200277 else
278 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100279 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000281 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100282 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100283 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200284 }
285
Bram Moolenaar1306b362022-08-06 15:59:06 +0100286 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100288 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200289#endif
290 )
291 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100292 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100294 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 if (gui.in_use && icon_sign != 0)
296 {
297 // Use the image in this position.
298 if (nrcol)
299 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100300 wlv->c_extra = NUL;
John Marriottf51ff962024-06-02 19:44:11 +0200301 wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra),
302 "%-*c ", number_width(wp), SIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100303 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200304 }
305 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100308 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
309 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200310 {
311 if (nrcol)
312 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100313 wlv->c_extra = NUL;
John Marriottf51ff962024-06-02 19:44:11 +0200314 wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra),
315 "%-*c ", number_width(wp), MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100316 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317 }
318 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200320 }
321# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100322 wlv->c_final = NUL;
323 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200324 }
325 else
326# endif
327 if (text_sign != 0)
328 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100329 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100330 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200331 {
332 if (nrcol)
333 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100334 int width = number_width(wp) - 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200335
John Marriottf51ff962024-06-02 19:44:11 +0200336 vim_memset(wlv->extra, ' ', width);
337 wlv->n_extra = width;
338 wlv->n_extra += vim_snprintf((char *)wlv->extra + width,
339 sizeof(wlv->extra) - width, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100340 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200341 }
John Marriottf51ff962024-06-02 19:44:11 +0200342 else
343 wlv->n_extra = (int)STRLEN(wlv->p_extra);
344
Bram Moolenaar1306b362022-08-06 15:59:06 +0100345 wlv->c_extra = NUL;
346 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200347 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000348
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100349 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100350 && wlv->sattr.sat_culhl > 0)
351 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000352 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100353 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200354 }
355 }
356}
357#endif
358
Bram Moolenaard7657e92022-09-20 18:59:30 +0100359/*
360 * Display the absolute or relative line number. After the first row fill with
361 * blanks when the 'n' flag isn't in 'cpo'.
362 */
363 static void
364handle_lnum_col(
365 win_T *wp,
366 winlinevars_T *wlv,
367 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100368 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100369{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100370 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100371 int lnum_row = wlv->startrow + wlv->filler_lines
372#ifdef FEAT_PROP_POPUP
373 + wlv->text_prop_above_count
374#endif
375 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100376
Bram Moolenaard7657e92022-09-20 18:59:30 +0100377 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100378 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100379 // there is no line number in a wrapped line when "n" is in
380 // 'cpoptions', but 'breakindent' assumes it anyway.
381 && !((has_cpo_n
382#ifdef FEAT_LINEBREAK
383 && !wp->w_p_bri
384#endif
385 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100386 {
387#ifdef FEAT_SIGNS
388 // If 'signcolumn' is set to 'number' and a sign is present
389 // in 'lnum', then display the sign instead of the line
390 // number.
glepnir1b186832025-05-10 14:59:08 +0200391 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present
392 && wlv->sattr.sat_text != NULL)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100393 get_sign_display_info(TRUE, wp, wlv);
394 else
395#endif
396 {
397 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100398 // When there are text properties above the line put the line number
399 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100400 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100401 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100402 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100403 {
404 long num;
405 char *fmt = "%*ld ";
406
407 if (wp->w_p_nu && !wp->w_p_rnu)
408 // 'number' + 'norelativenumber'
409 num = (long)wlv->lnum;
410 else
411 {
412 // 'relativenumber', don't use negative numbers
413 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
414 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
415 {
416 // 'number' + 'relativenumber'
417 num = wlv->lnum;
418 fmt = "%-*ld ";
419 }
420 }
421
John Marriottf51ff962024-06-02 19:44:11 +0200422 vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100423 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100424 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
425 ++wlv->p_extra)
426 *wlv->p_extra = '-';
427#ifdef FEAT_RIGHTLEFT
428 if (wp->w_p_rl) // reverse line numbers
429 {
430 char_u *p1, *p2;
431 int t;
432
433 // like rl_mirror(), but keep the space at the end
434 p2 = skipwhite(wlv->extra);
435 p2 = skiptowhite(p2) - 1;
436 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
437 {
438 t = *p1;
439 *p1 = *p2;
440 *p2 = t;
441 }
442 }
443#endif
444 wlv->p_extra = wlv->extra;
445 wlv->c_extra = NUL;
446 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100447 }
448 else
449 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100450 wlv->c_extra = ' ';
451 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100452 }
453 wlv->n_extra = number_width(wp) + 1;
454 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
455#ifdef FEAT_SYN_HL
456 // When 'cursorline' is set highlight the line number of
457 // the current line differently.
458 // When 'cursorlineopt' does not have "line" only
459 // highlight the line number itself.
460 // TODO: Can we use CursorLine instead of CursorLineNr
461 // when CursorLineNr isn't set?
462 if (wp->w_p_cul
463 && wlv->lnum == wp->w_cursor.lnum
464 && (wp->w_p_culopt_flags & CULOPT_NBR)
zeertzjq62f19542025-03-08 16:27:37 +0100465 && (wlv->row == lnum_row
466 || (wlv->row > lnum_row
Bram Moolenaard7657e92022-09-20 18:59:30 +0100467 && (wp->w_p_culopt_flags & CULOPT_LINE))))
468 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
469#endif
470 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
471 && HL_ATTR(HLF_LNA) != 0)
472 // Use LineNrAbove
473 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
474 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
475 && HL_ATTR(HLF_LNB) != 0)
476 // Use LineNrBelow
477 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
478 }
479#ifdef FEAT_SIGNS
480 if (num_attr)
481 wlv->char_attr = num_attr;
482#endif
483 }
484}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100485
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100486#ifdef FEAT_LINEBREAK
487 static void
488handle_breakindent(win_T *wp, winlinevars_T *wlv)
489{
490 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100491 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100492 // draw indent after showbreak value
493 wlv->draw_state = WL_BRI;
494 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
495 // After the showbreak, draw the breakindent
496 wlv->draw_state = WL_BRI - 1;
497
498 // draw 'breakindent': indent wrapped text accordingly
499 if (wlv->draw_state == WL_BRI - 1)
500 {
501 wlv->draw_state = WL_BRI;
502 // if wlv->need_showbreak is set, breakindent also applies
zeertzjq588f20d2023-12-05 15:47:09 +0100503 if (wp->w_p_bri && (wlv->row > wlv->startrow
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100504# ifdef FEAT_DIFF
zeertzjq588f20d2023-12-05 15:47:09 +0100505 + wlv->filler_lines
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100506# endif
zeertzjq588f20d2023-12-05 15:47:09 +0100507 || wlv->need_showbreak)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100508# ifdef FEAT_PROP_POPUP
509 && !wlv->dont_use_showbreak
510# endif
511 )
512 {
513 wlv->char_attr = 0;
514# ifdef FEAT_DIFF
515 if (wlv->diff_hlf != (hlf_T)0)
516 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
517# endif
518 wlv->p_extra = NULL;
519 wlv->c_extra = ' ';
520 wlv->c_final = NUL;
521 wlv->n_extra = get_breakindent_win(wp,
522 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
523 if (wlv->row == wlv->startrow)
524 {
525 wlv->n_extra -= win_col_off2(wp);
526 if (wlv->n_extra < 0)
527 wlv->n_extra = 0;
528 }
zeertzjq23627722023-12-27 19:08:53 +0100529
530 // Correct start of highlighted area for 'breakindent',
531 if (wlv->fromcol >= wlv->vcol
532 && wlv->fromcol < wlv->vcol + wlv->n_extra)
533 wlv->fromcol = wlv->vcol + wlv->n_extra;
534
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100535 // Correct end of highlighted area for 'breakindent',
536 // required when 'linebreak' is also set.
537 if (wlv->tocol == wlv->vcol)
538 wlv->tocol += wlv->n_extra;
539 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100540
541 if (wp->w_skipcol > 0 && wlv->startrow == 0 && wp->w_p_wrap
542 && wp->w_briopt_sbr)
543 wlv->need_showbreak = FALSE;
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100544 }
545}
546#endif
547
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100548#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
549 static void
550handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
551{
552# ifdef FEAT_DIFF
553 if (wlv->filler_todo > 0)
554 {
555 // Draw "deleted" diff line(s).
556 if (char2cells(wp->w_fill_chars.diff) > 1)
557 {
558 wlv->c_extra = '-';
559 wlv->c_final = NUL;
560 }
561 else
562 {
563 wlv->c_extra = wp->w_fill_chars.diff;
564 wlv->c_final = NUL;
565 }
566# ifdef FEAT_RIGHTLEFT
567 if (wp->w_p_rl)
568 wlv->n_extra = wlv->col + 1;
569 else
570# endif
571 wlv->n_extra = wp->w_width - wlv->col;
572 wlv->char_attr = HL_ATTR(HLF_DED);
573 }
574# endif
575
576# ifdef FEAT_LINEBREAK
577 char_u *sbr = get_showbreak_value(wp);
578 if (*sbr != NUL && wlv->need_showbreak)
579 {
580 // Draw 'showbreak' at the start of each broken line.
581 wlv->p_extra = sbr;
582 wlv->c_extra = NUL;
583 wlv->c_final = NUL;
584 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100585 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100586
587 // Correct start of highlighted area for 'showbreak'.
588 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
589 wlv->fromcol = wlv->vcol_sbr;
590
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100591 // Correct end of highlighted area for 'showbreak',
592 // required when 'linebreak' is also set.
593 if (wlv->tocol == wlv->vcol)
zeertzjqdf23d7f2024-02-09 18:14:12 +0100594 wlv->tocol = wlv->vcol_sbr;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100595 // combine 'showbreak' with 'wincolor'
596 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
597# ifdef FEAT_SYN_HL
598 // combine 'showbreak' with 'cursorline'
599 if (wlv->cul_attr != 0)
600 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
601# endif
602 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100603
604 if (wp->w_skipcol == 0 || wlv->startrow > 0 || !wp->w_p_wrap
605 || !wp->w_briopt_sbr)
606 wlv->need_showbreak = FALSE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100607# endif
608}
609#endif
610
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100611#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100612/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100613 * Return the cell size of virtual text after truncation.
614 */
615 static int
616textprop_size_after_trunc(
617 win_T *wp,
618 int flags, // TP_FLAG_ALIGN_*
619 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100620 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100621 char_u *text,
622 int *n_used_ptr)
623{
624 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100625 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100626 int strsize = 0;
John Marriottf51ff962024-06-02 19:44:11 +0200627 char_u *p;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100628
John Marriottf51ff962024-06-02 19:44:11 +0200629 // if the remaining size is too small and 'wrap' is set we wrap anyway and
Bram Moolenaar7e017462022-10-11 21:02:09 +0100630 // use the next line
631 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100632 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100633 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100634 space -= padding;
John Marriottf51ff962024-06-02 19:44:11 +0200635
636 for (p = text; *p != NUL; p += (*mb_ptr2len)(p))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100637 {
John Marriottf51ff962024-06-02 19:44:11 +0200638 int clen = ptr2cells(p);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100639
640 if (strsize + clen > space)
641 break;
642 strsize += clen;
643 }
John Marriottf51ff962024-06-02 19:44:11 +0200644 *n_used_ptr = (int)(p - text);
645
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100646 return strsize;
647}
648
649/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100650 * Take care of padding, right-align and truncation of virtual text after a
651 * line.
652 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
653 * padding, right-align and truncation. Otherwise only the size is computed.
654 * When "n_attr" is NULL returns the number of screen cells used.
655 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100656 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100657 int
658text_prop_position(
659 win_T *wp,
660 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000661 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100662 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100663 int *n_extra, // nr of bytes for virtual text
664 char_u **p_extra, // virtual text
665 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000666 int *n_attr_skip, // cells to skip attr, NULL if not used
667 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200668{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100669 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100670 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100671 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000672 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000674 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100675 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100676 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100677 int before = room; // spaces before the text
678 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100679 int n_used = *n_extra;
680 char_u *l = NULL;
681 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100682 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100683 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200684
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100685 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100686 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100687 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100688
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100689 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100690 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100691 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100692 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100693 if (after < 0)
694 {
695 // text "above" has too much padding to fit
696 padding += after;
697 after = 0;
698 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100699 }
700 else
701 {
702 // Right-align: fill with before
703 if (right)
704 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000705
706 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000707 if (below && vcol == 0 && col_with_padding == col_off
708 && wp->w_width - col_off == before)
709 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000710
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100711 if (before < 0
712 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000713 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
714 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100715 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100716 if (right && (wrap
717 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100718 {
719 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100720 before = wp->w_width - col_off - strsize + room;
721 if (before < 0)
722 before = 0;
723 else
724 n_used = *n_extra;
725 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000726 else if (below && before > vcol && do_skip)
727 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100728 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100729 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100731 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100732
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100733 // With 'nowrap' add one to show the "extends" character if needed (it
734 // doesn't show if the text just fits).
735 if (!wp->w_p_wrap
736 && n_used < *n_extra
737 && wp->w_lcs_chars.ext != NUL
738 && wp->w_p_list)
739 ++n_used;
740
741 // add 1 for NUL, 2 for when '…' is used
742 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200743 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100744 if (n_attr == NULL || l != NULL)
745 {
746 int off = 0;
747
748 if (n_attr != NULL)
749 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100750 vim_memset(l, ' ', before);
751 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100752 if (padding > 0)
753 {
754 vim_memset(l + off, ' ', padding);
755 off += padding;
756 }
757 vim_strncpy(l + off, *p_extra, n_used);
758 off += n_used;
759 }
760 else
761 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100762 off = before + after + padding + n_used;
763 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100764 }
765 if (n_attr != NULL)
766 {
767 if (n_used < *n_extra && wp->w_p_wrap)
768 {
769 char_u *lp = l + off - 1;
770
771 if (has_mbyte)
772 {
h-east4c42c7e2023-04-17 21:44:57 +0100773 char_u buf[MB_MAXBYTES + 1];
774 char_u *cp = buf;
775
776 // change the last character to '…', converted to the
777 // current 'encoding'
778 STRCPY(buf, "…");
779 if (!enc_utf8)
780 {
781 vimconv_T vc;
782
783 vc.vc_type = CONV_NONE;
784 convert_setup(&vc, (char_u *)"utf-8", p_enc);
785 if (vc.vc_type != CONV_NONE)
786 {
787 cp = string_convert(&vc, buf, NULL);
788 if (cp == NULL)
789 {
790 // when conversion fails use '>'
791 cp = buf;
792 STRCPY(buf, ">");
793 }
794 convert_setup(&vc, NULL, NULL);
795 }
796 }
797
798 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100799 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100800 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100801 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100802 if (cp != buf)
803 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100804 }
805 else
806 // change last character to '>'
807 *lp = '>';
808 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100809 else if (after > 0)
810 {
811 vim_memset(l + off, ' ', after);
812 l[off + after] = NUL;
813 }
814
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100815 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100816 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100817 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000818 // n_attr_skip will not be decremented before draw_state is
819 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200820 *n_attr_skip = before + (padding > 0 ? padding : 0);
zeertzjq9352c282024-03-14 18:16:56 +0100821 *n_attr -= *n_attr_skip;
822 if (above)
823 *n_attr -= after;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100824 }
825 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100826 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100827
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100828 if (n_attr == NULL)
829 return cells;
830 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200831}
832#endif
833
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100834/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100835 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100836 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
837 * when 'showbreak' is not set.
zeertzjqd0c1b772024-03-16 15:03:33 +0100838 * When "clear_end" is TRUE clear until the end of the screen line.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100839 */
840 static void
zeertzjqd0c1b772024-03-16 15:03:33 +0100841wlv_screen_line(win_T *wp, winlinevars_T *wlv, int clear_end)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100842{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100843 if (wlv->row == 0 && wp->w_skipcol > 0
844#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100845 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100846 && *get_showbreak_value(wp) == NUL
847#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100848 // do not overwrite the 'listchars' "precedes" text with "<<<"
849 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100850 {
851 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100852 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100853 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100854
Bram Moolenaareb4de622022-10-15 13:42:17 +0100855 if (wp->w_p_nu && wp->w_p_rnu)
856 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100857 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100858 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
859 {
860 ++off;
861 ++skip;
862 }
863
864 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100865 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100866 if ((*mb_off2cells)(off, max_off) > 1)
867 // When the first half of a double-width character is
868 // overwritten, change the second half to a space.
869 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100870 ScreenLines[off] = '<';
871 if (enc_utf8)
872 ScreenLinesUC[off] = 0;
873 ScreenAttrs[off] = HL_ATTR(HLF_AT);
874 ++off;
875 }
876 }
877
Hirohito Higashi3b9b95d2025-06-01 20:22:55 +0200878 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
zeertzjqd0c1b772024-03-16 15:03:33 +0100879 clear_end ? wp->w_width : -wp->w_width,
880 wlv->vcol - 1, wlv->screen_line_flags);
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100881}
882
883/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100884 * Called when finished with the line: draw the screen line and handle any
885 * highlighting until the right of the window.
886 */
887 static void
888draw_screen_line(win_T *wp, winlinevars_T *wlv)
889{
890#ifdef FEAT_SYN_HL
891 long v;
zeertzjqf6272552024-03-17 10:01:47 +0100892 int wcol;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100893
894 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
895 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100896 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100897 else
898 v = wp->w_leftcol;
899
zeertzjqf6272552024-03-17 10:01:47 +0100900 wcol =
901# ifdef FEAT_RIGHTLEFT
902 wp->w_p_rl ? wp->w_width - wlv->col - 1 :
903# endif
904 wlv->col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100905 // check if line ends before left margin
zeertzjqf6272552024-03-17 10:01:47 +0100906 if (wlv->vcol < v + wcol - win_col_off(wp))
907 wlv->vcol = v + wcol - win_col_off(wp);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100908# ifdef FEAT_CONCEAL
909 // Get rid of the boguscols now, we want to draw until the right
910 // edge for 'cursorcolumn'.
911 wlv->col -= wlv->boguscols;
912 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000913# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100914# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000915# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100916# endif
917
918 if (wlv->draw_color_col)
919 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
920
921 if (((wp->w_p_cuc
922 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
923 && (int)wp->w_virtcol <
924 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
925 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000926 || wlv->draw_color_col
927# ifdef LINE_ATTR
928 || wlv->line_attr != 0
929# endif
zeertzjqf6272552024-03-17 10:01:47 +0100930 || wlv->win_attr != 0))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100931 {
932 int rightmost_vcol = 0;
933 int i;
934
935 if (wp->w_p_cuc)
936 rightmost_vcol = wp->w_virtcol;
937 if (wlv->draw_color_col)
938 // determine rightmost colorcolumn to possibly draw
939 for (i = 0; wlv->color_cols[i] >= 0; ++i)
940 if (rightmost_vcol < wlv->color_cols[i])
941 rightmost_vcol = wlv->color_cols[i];
942
zeertzjqf6272552024-03-17 10:01:47 +0100943 while (
944# ifdef FEAT_RIGHTLEFT
945 wp->w_p_rl ? (wlv->col >= 0) :
946# endif
947 (wlv->col < wp->w_width))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100948 {
949 ScreenLines[wlv->off] = ' ';
950 if (enc_utf8)
951 ScreenLinesUC[wlv->off] = 0;
zeertzjqf6272552024-03-17 10:01:47 +0100952
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100953 if (wlv->draw_color_col)
954 wlv->draw_color_col = advance_color_col(
955 VCOL_HLC, &wlv->color_cols);
956
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000957 int attr = wlv->win_attr;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000958# ifdef LINE_ATTR
zeertzjq9352c282024-03-14 18:16:56 +0100959 if (wlv->line_attr != 0)
960 attr = hl_combine_attr(attr, wlv->line_attr);
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000961# endif
zeertzjq9352c282024-03-14 18:16:56 +0100962 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
963 && wlv->lnum != wp->w_cursor.lnum)
964 attr = hl_combine_attr(attr, HL_ATTR(HLF_CUC));
965 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
966 attr = hl_combine_attr(attr, HL_ATTR(HLF_MC));
zeertzjqf6272552024-03-17 10:01:47 +0100967 ScreenAttrs[wlv->off] = attr;
968 ScreenCols[wlv->off] = wlv->vcol;
969# ifdef FEAT_RIGHTLEFT
970 if (wp->w_p_rl)
971 {
972 --wlv->off;
973 --wlv->col;
974 }
975 else
976# endif
977 {
978 ++wlv->off;
979 ++wlv->col;
980 }
zeertzjqdeb22042024-03-17 19:44:30 +0100981 ++wlv->vcol;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100982
zeertzjqdeb22042024-03-17 19:44:30 +0100983 if (VCOL_HLC > rightmost_vcol
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000984# ifdef LINE_ATTR
985 && wlv->line_attr == 0
986# endif
987 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100988 break;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100989 }
990 }
991#endif
992
zeertzjqd0c1b772024-03-16 15:03:33 +0100993 // Set increasing virtual columns in ScreenCols[] to set correct curswant
994 // (or "coladd" for 'virtualedit') when clicking after end of line.
995 wlv->screen_line_flags |= SLF_INC_VCOL;
996 wlv_screen_line(wp, wlv, TRUE);
997 wlv->screen_line_flags &= ~SLF_INC_VCOL;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100998 ++wlv->row;
999 ++wlv->screen_row;
1000}
1001#undef VCOL_HLC
1002
1003/*
1004 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001005 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001006 */
1007 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +01001008win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001009{
1010 wlv->col = 0;
1011 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001012#ifdef FEAT_LINEBREAK
1013 wlv->need_lbr = FALSE;
1014#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001015
1016#ifdef FEAT_RIGHTLEFT
1017 if (wp->w_p_rl)
1018 {
1019 // Rightleft window: process the text in the normal direction, but put
1020 // it in current_ScreenLine[] from right to left. Start at the
1021 // rightmost column of the window.
1022 wlv->col = wp->w_width - 1;
1023 wlv->off += wlv->col;
1024 wlv->screen_line_flags |= SLF_RIGHTLEFT;
1025 }
1026#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001027 if (save_extra)
1028 {
1029 // reset the drawing state for the start of a wrapped line
1030 wlv->draw_state = WL_START;
1031 wlv->saved_n_extra = wlv->n_extra;
1032 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001033 vim_free(wlv->saved_p_extra_free);
1034 wlv->saved_p_extra_free = wlv->p_extra_free;
1035 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001036 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001037 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001038 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001039 wlv->saved_c_extra = wlv->c_extra;
1040 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001041#ifdef FEAT_LINEBREAK
1042 wlv->need_lbr = TRUE;
1043#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001044#ifdef FEAT_SYN_HL
1045 if (!(wlv->cul_screenline
1046# ifdef FEAT_DIFF
1047 && wlv->diff_hlf == (hlf_T)0
1048# endif
1049 ))
1050 wlv->saved_char_attr = wlv->char_attr;
1051 else
1052#endif
1053 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001054
1055 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001056 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001057 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001058 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001059}
1060
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001061/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001062 * Called when wlv->draw_state is set to WL_LINE.
1063 */
1064 static void
1065win_line_continue(winlinevars_T *wlv)
1066{
1067 if (wlv->saved_n_extra > 0)
1068 {
1069 // Continue item from end of wrapped line.
1070 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001071 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001072 wlv->c_extra = wlv->saved_c_extra;
1073 wlv->c_final = wlv->saved_c_final;
1074 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001075 vim_free(wlv->p_extra_free);
1076 wlv->p_extra_free = wlv->saved_p_extra_free;
1077 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001078 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001079 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001080 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001081 wlv->char_attr = wlv->saved_char_attr;
1082 }
1083 else
1084 wlv->char_attr = wlv->win_attr;
1085}
1086
zeertzjqb7acea12022-12-12 13:20:43 +00001087#ifdef FEAT_SYN_HL
1088 static void
1089apply_cursorline_highlight(
1090 winlinevars_T *wlv,
1091 int sign_present UNUSED)
1092{
1093 wlv->cul_attr = HL_ATTR(HLF_CUL);
1094# ifdef FEAT_SIGNS
1095 // Combine the 'cursorline' and sign highlighting, depending on
1096 // the sign priority.
1097 if (sign_present && wlv->sattr.sat_linehl > 0)
1098 {
1099 if (wlv->sattr.sat_priority >= 100)
1100 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1101 else
1102 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1103 }
1104 else
1105# endif
1106# if defined(FEAT_QUICKFIX)
1107 // let the line attribute overrule 'cursorline', otherwise
1108 // it disappears when both have background set;
1109 // 'cursorline' can use underline or bold to make it show
1110 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1111# else
1112 wlv->line_attr = wlv->cul_attr;
1113# endif
1114}
1115#endif
1116
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001117/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001118 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119 * Start at row "startrow", stop when "endrow" is reached.
zeertzjqebfd8562024-02-06 10:59:03 +01001120 * When only updating the number column, "number_only" is set to the height of
1121 * the line, otherwise it is set to 0.
Luuk van Baal30805a12023-05-27 22:22:10 +01001122 * "spv" is used to store information for spell checking, kept between
1123 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124 * wp->w_virtcol needs to be valid.
1125 *
1126 * Return the number of last row the line occupies.
1127 */
1128 int
1129win_line(
1130 win_T *wp,
1131 linenr_T lnum,
1132 int startrow,
1133 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001134 int number_only,
1135 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001136{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001137 winlinevars_T wlv; // variables passed between functions
1138
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001140 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141 char_u *line; // current line
1142 char_u *ptr; // current position in "line"
glepnir6a38aff2024-12-16 21:56:16 +01001143 int in_curline = wp == curwin && lnum == curwin->w_cursor.lnum;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001144
Bram Moolenaar1306b362022-08-06 15:59:06 +01001145#ifdef FEAT_PROP_POPUP
1146 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1147#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001148#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001149 int in_linebreak = FALSE; // n_extra set for showing linebreak
1150#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01001151 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001152 int lcs_prec_todo = wp->w_lcs_chars.prec;
1153 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001155 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001156 int saved_attr2 = 0; // char_attr saved for n_attr
1157 int n_attr3 = 0; // chars with overruling special attr
1158 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001159
zeertzjqb557f482023-08-22 22:07:34 +02001160 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1161 // w_skipcol or concealing
1162 int skipped_cells = 0; // nr of skipped cells for virtual text
1163 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001164 int fromcol_prev = -2; // start of inverting after cursor
1165 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166 int lnum_in_visual_area = FALSE;
1167 pos_T pos;
1168 long v;
1169
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001170 int attr_pri = FALSE; // char_attr has priority
1171 int area_highlighting = FALSE; // Visual or incsearch highlighting
1172 // in this line
1173 int vi_attr = 0; // attributes for Visual and incsearch
1174 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001175 int area_attr = 0; // attributes desired by highlighting
zeertzjqf25d8f92024-12-18 21:12:25 +01001176 int search_attr = 0; // attributes desired by 'hlsearch' or
1177 // ComplMatchIns
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178#ifdef FEAT_SYN_HL
1179 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1180 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001181 int prev_syntax_col = -1; // column of prev_syntax_attr
1182 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001183 int has_syntax = FALSE; // this buffer has syntax highl.
1184 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001185#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001186#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001187 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001189 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001190 int text_prop_next = 0; // next text property to use
1191 textprop_T *text_props = NULL;
1192 int *text_prop_idxs = NULL;
1193 int text_props_active = 0;
1194 proptype_T *text_prop_type = NULL;
1195 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001196 int text_prop_attr_comb = 0; // text_prop_attr combined with
1197 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001198 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001199 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001200 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001201 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001202 int saved_search_attr = 0; // search_attr to be used when n_extra
1203 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001204 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001205 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001206#endif
1207#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001208 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209# define SPWORDLEN 150
1210 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1211 int nextlinecol = 0; // column where nextline[] starts
1212 int nextline_idx = 0; // index in nextline[] where next line
1213 // starts
1214 int spell_attr = 0; // attributes desired by spelling
1215 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216 int cur_checked_col = 0; // checked column for current line
1217#endif
zeertzjqf25d8f92024-12-18 21:12:25 +01001218 int extra_check = FALSE; // has extra highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219 int multi_attr = 0; // attributes desired by multibyte
1220 int mb_l = 1; // multi-byte byte length
1221 int mb_c = 0; // decoded multi-byte character
1222 int mb_utf8 = FALSE; // screen char is UTF-8 char
1223 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225 int change_start = MAXCOL; // first col of changed area
1226 int change_end = -1; // last col of changed area
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001227 diffline_T line_changes;
1228 int change_index = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229#endif
1230 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001231 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001232 int in_multispace = FALSE; // in multiple consecutive spaces
1233 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001234#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001235 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001238 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239#ifdef FEAT_ARABIC
1240 int prev_c = 0; // previous Arabic character
1241 int prev_c1 = 0; // first composing char for prev_c
1242#endif
1243#if defined(LINE_ATTR)
1244 int did_line_attr = 0;
1245#endif
1246#ifdef FEAT_TERMINAL
1247 int get_term_attr = FALSE;
1248#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249
Martin Tournoijba43e762022-10-13 22:12:15 +01001250#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 // margin columns for the screen line, needed for when 'cursorlineopt'
1252 // contains "screenline"
1253 int left_curline_col = 0;
1254 int right_curline_col = 0;
1255#endif
1256
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001257#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1258 int feedback_col = 0;
1259 int feedback_old_attr = -1;
1260#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001261
1262#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1263 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001264#endif
1265#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001266 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267#endif
1268#ifdef FEAT_CONCEAL
1269 int syntax_flags = 0;
1270 int syntax_seqnr = 0;
1271 int prev_syntax_id = 0;
1272 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1273 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 int did_wcol = FALSE;
1275 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001276# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277# define FIX_FOR_BOGUSCOLS \
1278 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001279 wlv.n_extra += wlv.vcol_off_co; \
1280 wlv.vcol -= wlv.vcol_off_co; \
1281 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001282 wlv.col -= wlv.boguscols; \
1283 old_boguscols = wlv.boguscols; \
1284 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285 }
1286#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001287# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288#endif
1289
1290 if (startrow > endrow) // past the end already!
1291 return startrow;
1292
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001293 CLEAR_FIELD(wlv);
1294
1295 wlv.lnum = lnum;
1296 wlv.startrow = startrow;
1297 wlv.row = startrow;
1298 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001299 wlv.fromcol = -10;
1300 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001301#ifdef FEAT_LINEBREAK
1302 wlv.vcol_sbr = -1;
1303#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001304
zeertzjqebfd8562024-02-06 10:59:03 +01001305 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306 {
1307 // To speed up the loop below, set extra_check when there is linebreak,
1308 // trailing white space and/or syntax processing to be done.
1309#ifdef FEAT_LINEBREAK
1310 extra_check = wp->w_p_lbr;
1311#endif
1312#ifdef FEAT_SYN_HL
1313 if (syntax_present(wp) && !wp->w_s->b_syn_error
1314# ifdef SYN_TIME_LIMIT
1315 && !wp->w_s->b_syn_slow
1316# endif
1317 )
1318 {
1319 // Prepare for syntax highlighting in this line. When there is an
1320 // error, stop syntax highlighting.
1321 save_did_emsg = did_emsg;
1322 did_emsg = FALSE;
1323 syntax_start(wp, lnum);
1324 if (did_emsg)
1325 wp->w_s->b_syn_error = TRUE;
1326 else
1327 {
1328 did_emsg = save_did_emsg;
1329#ifdef SYN_TIME_LIMIT
1330 if (!wp->w_s->b_syn_slow)
1331#endif
1332 {
1333 has_syntax = TRUE;
1334 extra_check = TRUE;
1335 }
1336 }
1337 }
1338
1339 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001340 wlv.color_cols = wp->w_p_cc_cols;
1341 if (wlv.color_cols != NULL)
1342 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343#endif
1344
1345#ifdef FEAT_TERMINAL
1346 if (term_show_buffer(wp->w_buffer))
1347 {
1348 extra_check = TRUE;
1349 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001350 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 }
1352#endif
1353
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 // handle Visual active in this window
1355 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1356 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001357 pos_T *top, *bot;
1358
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1360 {
1361 // Visual is after curwin->w_cursor
1362 top = &curwin->w_cursor;
1363 bot = &VIsual;
1364 }
1365 else
1366 {
1367 // Visual is before curwin->w_cursor
1368 top = &VIsual;
1369 bot = &curwin->w_cursor;
1370 }
1371 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1372 if (VIsual_mode == Ctrl_V)
1373 {
1374 // block mode
1375 if (lnum_in_visual_area)
1376 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001377 wlv.fromcol = wp->w_old_cursor_fcol;
1378 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001379 }
1380 }
1381 else
1382 {
1383 // non-block mode
1384 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001385 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386 else if (lnum == top->lnum)
1387 {
1388 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001389 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001390 else
1391 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001392 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001393 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001394 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001395 }
1396 }
1397 if (VIsual_mode != 'V' && lnum == bot->lnum)
1398 {
1399 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1400 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001401 wlv.fromcol = -10;
1402 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001403 }
1404 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001405 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 else
1407 {
1408 pos = *bot;
1409 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001410 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1411 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001412 else
1413 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001414 getvvcol(wp, &pos, NULL, NULL,
1415 (colnr_T *)&wlv.tocol);
1416 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 }
1418 }
1419 }
1420 }
1421
1422 // Check if the character under the cursor should not be inverted
glepnir6a38aff2024-12-16 21:56:16 +01001423 if (!highlight_match && in_curline
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424#ifdef FEAT_GUI
1425 && !gui.in_use
1426#endif
1427 )
1428 noinvcur = TRUE;
1429
1430 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001431 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432 {
1433 area_highlighting = TRUE;
1434 vi_attr = HL_ATTR(HLF_V);
1435#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1436 if ((clip_star.available && !clip_star.owned
1437 && clip_isautosel_star())
1438 || (clip_plus.available && !clip_plus.owned
1439 && clip_isautosel_plus()))
1440 vi_attr = HL_ATTR(HLF_VNC);
1441#endif
1442 }
1443 }
1444
1445 // handle 'incsearch' and ":s///c" highlighting
1446 else if (highlight_match
1447 && wp == curwin
1448 && lnum >= curwin->w_cursor.lnum
1449 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1450 {
1451 if (lnum == curwin->w_cursor.lnum)
1452 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001453 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001455 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1457 {
1458 pos.lnum = lnum;
1459 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001460 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461 }
1462 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001463 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001465 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1466 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467 area_highlighting = TRUE;
1468 vi_attr = HL_ATTR(HLF_I);
1469 }
1470 }
1471
1472#ifdef FEAT_DIFF
Jonathon7c7a4e62025-01-12 09:58:00 +01001473
1474 int linestatus = 0;
1475 wlv.filler_lines = diff_check_with_linestatus(wp, lnum, &linestatus);
1476
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001477 CLEAR_FIELD(line_changes);
1478
Jonathon7c7a4e62025-01-12 09:58:00 +01001479 if (wlv.filler_lines < 0 || linestatus < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480 {
Jonathon7c7a4e62025-01-12 09:58:00 +01001481 if (wlv.filler_lines == -1 || linestatus == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482 {
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001483 if (diff_find_change(wp, lnum, &line_changes))
1484 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001485 wlv.diff_hlf = HLF_ADD; // added line
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001486 }
1487 else if (line_changes.num_changes > 0)
1488 {
1489 int added = diff_change_parse(
1490 &line_changes, &line_changes.changes[0],
1491 &change_start, &change_end);
1492 if (change_start == 0)
1493 {
1494 if (added)
1495 wlv.diff_hlf = HLF_TXA; // added text on changed line
1496 else
1497 wlv.diff_hlf = HLF_TXD; // changed text on changed line
1498 }
1499 else
1500 wlv.diff_hlf = HLF_CHD; // unchanged text on changed line
1501 change_index = 0;
1502 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001503 else
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001504 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001505 wlv.diff_hlf = HLF_CHD; // changed line
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001506 change_index = 0;
1507 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508 }
1509 else
Jonathon7c7a4e62025-01-12 09:58:00 +01001510 wlv.diff_hlf = HLF_ADD;
1511
1512 if (linestatus == 0)
1513 wlv.filler_lines = 0;
1514
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515 area_highlighting = TRUE;
1516 }
Jonathon7c7a4e62025-01-12 09:58:00 +01001517
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001519 wlv.filler_lines = wp->w_topfill;
Jonathon7c7a4e62025-01-12 09:58:00 +01001520
Bram Moolenaard7657e92022-09-20 18:59:30 +01001521 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522#endif
1523
1524#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001525 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001526 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001527 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528#endif
1529
1530#ifdef LINE_ATTR
1531# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001532 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001534 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535# endif
1536# if defined(FEAT_QUICKFIX)
1537 // Highlight the current line in the quickfix window.
1538 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001539 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001541 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 area_highlighting = TRUE;
1543#endif
1544
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545#ifdef FEAT_SPELL
zeertzjqebfd8562024-02-06 10:59:03 +01001546 if (spv->spv_has_spell && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001547 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001548 // Prepare for spell checking.
1549 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001550
Luuk van Baal30805a12023-05-27 22:22:10 +01001551 // When a word wrapped from the previous line the start of the
1552 // current line is valid.
1553 if (lnum == spv->spv_checked_lnum)
1554 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001555 // Previous line was not spell checked, check for capital. This happens
1556 // for the first line in an updated region or after a closed fold.
1557 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1558 spv->spv_cap_col = 0;
1559 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001560 spv->spv_cap_col = -1;
1561 spv->spv_checked_lnum = 0;
1562
Luuk van Baal30805a12023-05-27 22:22:10 +01001563 // Get the start of the next line, so that words that wrap to the
1564 // next line are found too: "et<line-break>al.".
1565 // Trick: skip a few chars for C/shell/Vim comments
1566 nextline[SPWORDLEN] = NUL;
1567 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001568 {
1569 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1570 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1571 }
1572 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1573
1574 // If current line is empty, check first word in next line for capital.
1575 ptr = skipwhite(line);
1576 if (*ptr == NUL)
1577 {
1578 spv->spv_cap_col = 0;
1579 spv->spv_capcol_lnum = lnum + 1;
1580 }
1581 // For checking first word with a capital skip white space.
1582 else if (spv->spv_cap_col == 0)
1583 spv->spv_cap_col = ptr - line;
1584
Luuk van Baal30805a12023-05-27 22:22:10 +01001585 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001586 if (nextline[SPWORDLEN] == NUL)
1587 {
1588 // No next line or it is empty.
1589 nextlinecol = MAXCOL;
1590 nextline_idx = 0;
1591 }
1592 else
1593 {
zeertzjq94b7c322024-03-12 21:50:32 +01001594 v = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 if (v < SPWORDLEN)
1596 {
1597 // Short line, use it completely and append the start of the
1598 // next line.
1599 nextlinecol = 0;
1600 mch_memmove(nextline, line, (size_t)v);
1601 STRMOVE(nextline + v, nextline + SPWORDLEN);
1602 nextline_idx = v + 1;
1603 }
1604 else
1605 {
1606 // Long line, use only the last SPWORDLEN bytes.
1607 nextlinecol = v - SPWORDLEN;
1608 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1609 nextline_idx = SPWORDLEN + 1;
1610 }
1611 }
1612 }
1613#endif
1614
Luuk van Baale84c7732023-05-31 18:57:36 +01001615 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1616 ptr = line;
1617
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001618 if (wp->w_p_list)
1619 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001620 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001621 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001622 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001623 || wp->w_lcs_chars.trail
1624 || wp->w_lcs_chars.lead
1625 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001627
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001628 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001629 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 {
zeertzjq94b7c322024-03-12 21:50:32 +01001631 trailcol = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001632 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1633 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001634 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001636 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001637 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001638 {
1639 leadcol = 0;
1640 while (VIM_ISWHITE(ptr[leadcol]))
1641 ++leadcol;
1642 if (ptr[leadcol] == NUL)
1643 // in a line full of spaces all of them are treated as trailing
1644 leadcol = (colnr_T)0;
1645 else
1646 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001647 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001648 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001649 }
1650
Bram Moolenaard7657e92022-09-20 18:59:30 +01001651 wlv.wcr_attr = get_wcr_attr(wp);
1652 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001653 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001654 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655 area_highlighting = TRUE;
1656 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001657
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001658 // When w_skipcol is non-zero and there is virtual text above the actual
1659 // text, then this much of the virtual text is skipped.
1660 int skipcol_in_text_prop_above = 0;
1661
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001662#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001663 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001664 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001665
1666 char_u *prop_start;
1667 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1668 if (text_prop_count > 0)
1669 {
1670 // Make a copy of the properties, so that they are properly
1671 // aligned.
1672 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1673 if (text_props != NULL)
1674 mch_memmove(text_props, prop_start,
1675 text_prop_count * sizeof(textprop_T));
1676
1677 // Allocate an array for the indexes.
1678 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1679 if (text_prop_idxs == NULL)
1680 VIM_CLEAR(text_props);
1681
1682 if (text_props != NULL)
1683 {
1684 area_highlighting = TRUE;
1685 extra_check = TRUE;
1686
zeertzjq4e26a9a2023-12-03 17:50:47 +01001687 /* Find the last text property that inserts text. */
1688 for (int i = 0; i < text_prop_count; ++i)
1689 if (text_props[i].tp_id < 0)
1690 last_textprop_text_idx = i;
1691
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001692 // Text props "above" move the line number down to where the text
1693 // is. Only count the ones that are visible, not those that are
1694 // skipped because of w_skipcol.
1695 int text_width = wp->w_width - win_col_off(wp);
1696 for (int i = text_prop_count - 1; i >= 0; --i)
1697 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1698 {
1699 if (lnum == wp->w_topline
1700 && wp->w_skipcol - skipcol_in_text_prop_above
1701 >= text_width)
1702 {
1703 // This virtual text above is skipped, remove it from
1704 // the array.
1705 skipcol_in_text_prop_above += text_width;
1706 for (int j = i + 1; j < text_prop_count; ++j)
1707 text_props[j - 1] = text_props[j];
1708 ++i;
1709 --text_prop_count;
1710 }
1711 else
1712 ++wlv.text_prop_above_count;
1713 }
1714 }
1715 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001716
zeertzjqebfd8562024-02-06 10:59:03 +01001717 if (number_only > 0)
Bram Moolenaara572b932023-02-19 14:34:37 +00001718 {
1719 // skip over rows only used for virtual text above
1720 wlv.row += wlv.text_prop_above_count;
zeertzjq918b92b2024-03-20 19:49:20 +01001721 if (wlv.row >= endrow)
1722 {
1723 vim_free(text_props);
1724 vim_free(text_prop_idxs);
Bram Moolenaara572b932023-02-19 14:34:37 +00001725 return wlv.row;
zeertzjq918b92b2024-03-20 19:49:20 +01001726 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001727 wlv.screen_row += wlv.text_prop_above_count;
1728 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729#endif
1730
zeertzjqce53e3e2023-09-01 18:49:30 +02001731#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1732 colnr_T vcol_first_char = 0;
zeertzjqebfd8562024-02-06 10:59:03 +01001733 if (wp->w_p_lbr && number_only == 0)
zeertzjqce53e3e2023-09-01 18:49:30 +02001734 {
1735 chartabsize_T cts;
1736 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1737 (void)win_lbr_chartabsize(&cts, NULL);
1738 vcol_first_char = cts.cts_first_char;
1739 clear_chartabsize_arg(&cts);
1740 }
1741#endif
1742
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1744 // first character to be displayed.
1745 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001746 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 else
1748 v = wp->w_leftcol;
zeertzjqebfd8562024-02-06 10:59:03 +01001749 if (v > 0 && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001751 char_u *prev_ptr = ptr;
1752 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001753 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001754 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001756 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001757 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001758 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 {
zeertzjqb557f482023-08-22 22:07:34 +02001760 head = 0;
1761 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001762 cts.cts_vcol += charsize;
1763 prev_ptr = cts.cts_ptr;
1764 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001765 if (wp->w_p_list)
1766 {
1767 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1768 || (prev_ptr > line && prev_ptr[-1] == ' '));
1769 if (!in_multispace)
1770 multispace_pos = 0;
1771 else if (cts.cts_ptr >= line + leadcol
1772 && wp->w_lcs_chars.multispace != NULL)
1773 {
1774 ++multispace_pos;
1775 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1776 multispace_pos = 0;
1777 }
1778 else if (cts.cts_ptr < line + leadcol
1779 && wp->w_lcs_chars.leadmultispace != NULL)
1780 {
1781 ++multispace_pos;
1782 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1783 multispace_pos = 0;
1784 }
1785 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001787 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001788 ptr = cts.cts_ptr;
1789 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001790
1791 // When:
1792 // - 'cuc' is set, or
1793 // - 'colorcolumn' is set, or
1794 // - 'virtualedit' is set, or
1795 // - the visual mode is active,
1796 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001797 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001799 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001800#endif
1801 virtual_active() ||
1802 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001803 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804
1805 // Handle a character that's not completely on the screen: Put ptr at
1806 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001807 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001809 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811 }
zeertzjqb557f482023-08-22 22:07:34 +02001812 if (v > wlv.vcol)
1813 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001814
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 // Adjust for when the inverted text is before the screen,
1816 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001817 if (wlv.tocol <= wlv.vcol)
1818 wlv.fromcol = 0;
1819 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1820 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821
1822#ifdef FEAT_LINEBREAK
1823 // When w_skipcol is non-zero, first line needs 'showbreak'
1824 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001825 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826#endif
1827#ifdef FEAT_SPELL
1828 // When spell checking a word we need to figure out the start of the
1829 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001830 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 {
1832 int len;
1833 colnr_T linecol = (colnr_T)(ptr - line);
1834 hlf_T spell_hlf = HLF_COUNT;
1835
1836 pos = wp->w_cursor;
1837 wp->w_cursor.lnum = lnum;
1838 wp->w_cursor.col = linecol;
Christ van Willegen - van Noort8e4c4c72024-05-17 18:49:27 +02001839 len = spell_move_to(wp, FORWARD, SMT_ALL, TRUE, &spell_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840
1841 // spell_move_to() may call ml_get() and make "line" invalid
1842 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1843 ptr = line + linecol;
1844
John Marriottf51ff962024-06-02 19:44:11 +02001845 if (len == 0 || (int)wp->w_cursor.col > linecol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001846 {
1847 // no bad word found at line start, don't check until end of a
1848 // word
1849 spell_hlf = HLF_COUNT;
1850 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1851 }
1852 else
1853 {
1854 // bad word found, use attributes until end of word
1855 word_end = wp->w_cursor.col + len + 1;
1856
1857 // Turn index into actual attributes.
1858 if (spell_hlf != HLF_COUNT)
1859 spell_attr = highlight_attr[spell_hlf];
1860 }
1861 wp->w_cursor = pos;
1862
1863# ifdef FEAT_SYN_HL
1864 // Need to restart syntax highlighting for this line.
1865 if (has_syntax)
1866 syntax_start(wp, lnum);
1867# endif
1868 }
1869#endif
1870 }
1871
1872 // Correct highlighting for cursor that can't be disabled.
1873 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001874 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 {
1876 if (noinvcur)
1877 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001878 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879 {
1880 // highlighting starts at cursor, let it start just after the
1881 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001882 fromcol_prev = wlv.fromcol;
1883 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001885 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886 // restart highlighting after the cursor
1887 fromcol_prev = wp->w_virtcol;
1888 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001889 if (wlv.fromcol >= wlv.tocol)
1890 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 }
1892
1893#ifdef FEAT_SEARCH_EXTRA
zeertzjqebfd8562024-02-06 10:59:03 +01001894 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001895 {
1896 v = (long)(ptr - line);
1897 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1898 &line, &screen_search_hl,
1899 &search_attr);
1900 ptr = line + v; // "line" may have been updated
1901 }
1902#endif
1903
glepnir76bdb822025-02-08 19:04:51 +01001904 if ((State & MODE_INSERT) && ins_compl_win_active(wp)
1905 && (in_curline || ins_compl_lnum_in_range(lnum)))
zeertzjqf25d8f92024-12-18 21:12:25 +01001906 area_highlighting = TRUE;
1907
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908#ifdef FEAT_SYN_HL
1909 // Cursor line highlighting for 'cursorline' in the current window.
1910 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1911 {
1912 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001913 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 if (!(wp == curwin && VIsual_active)
1915 && wp->w_p_culopt_flags != CULOPT_NBR)
1916 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001917 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1919
zeertzjqb7acea12022-12-12 13:20:43 +00001920 // Only apply CursorLine highlight here when "screenline" is not
1921 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001922 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001923 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924 else
1925 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001926 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001927 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1928 }
1929 area_highlighting = TRUE;
1930 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931 }
1932#endif
1933
Bram Moolenaar1306b362022-08-06 15:59:06 +01001934 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935
1936 // Repeat for the whole displayed line.
1937 for (;;)
1938 {
1939#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001940 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941#endif
1942#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001943 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001945
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001946 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001947 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001948 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001949#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001950 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001951 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001952 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001953 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001954 }
1955#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001956 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001957 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001958 wlv.draw_state = WL_CMDLINE;
Sean Dewar988f7432023-08-16 14:17:36 +01001959 if (wp == cmdwin_win)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001960 {
1961 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001962 wlv.n_extra = 1;
1963 wlv.c_extra = cmdwin_type;
1964 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001965 wlv.char_attr =
1966 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001967 }
1968 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001969#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001970 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001971 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001972 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001973 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974 }
1975#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001976#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001977 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001978 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001979 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001980 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001982 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001983 }
1984#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001985 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001986 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001987 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001988 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001989 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990 }
zeertzjqebfd8562024-02-06 10:59:03 +01001991
1992 // When only displaying the (relative) line number and that's done,
1993 // stop here.
1994 if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0)
1995 {
zeertzjqd0c1b772024-03-16 15:03:33 +01001996 wlv_screen_line(wp, &wlv, FALSE);
zeertzjqebfd8562024-02-06 10:59:03 +01001997 // Need to update more screen lines if:
1998 // - LineNrAbove or LineNrBelow is used, or
1999 // - still drawing filler lines.
2000 if ((wlv.row + 1 - wlv.startrow < number_only
2001 && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0))
2002#ifdef FEAT_DIFF
2003 || wlv.filler_todo > 0
2004#endif
2005 )
2006 {
2007 ++wlv.row;
2008 ++wlv.screen_row;
2009 if (wlv.row == endrow)
2010 break;
2011#ifdef FEAT_DIFF
2012 --wlv.filler_todo;
2013 if (wlv.filler_todo == 0 && wp->w_botfill)
2014 break;
2015#endif
2016 win_line_start(wp, &wlv, TRUE);
2017 continue;
2018 }
2019 else
2020 break;
2021 }
2022
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002023#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002024 // Check if 'breakindent' applies and show it.
2025 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
2026 if (wlv.n_extra == 0)
2027 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002030 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002031 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002032 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002033 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002034 }
2035#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002036 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002037 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002038 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002039 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002040 }
2041 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002042
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002043#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002044 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002045 && wlv.vcol >= left_curline_col
2046 && wlv.vcol < right_curline_col)
zeertzjqb7acea12022-12-12 13:20:43 +00002047 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002048#endif
2049
2050 // When still displaying '$' of change command, stop at cursor.
zeertzjqf4ccada2024-12-17 20:50:19 +01002051 if (dollar_vcol >= 0 && in_curline && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002052 {
zeertzjqd0c1b772024-03-16 15:03:33 +01002053 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002054 // Pretend we have finished updating the window. Except when
2055 // 'cursorcolumn' is set.
2056#ifdef FEAT_SYN_HL
2057 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002058 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002059 else
2060#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002061 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002062 break;
2063 }
2064
Bram Moolenaar1306b362022-08-06 15:59:06 +01002065 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002066 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002067#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002068 if (text_props != NULL)
2069 {
2070 int pi;
2071 int bcol = (int)(ptr - line);
2072
Bram Moolenaar1306b362022-08-06 15:59:06 +01002073 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002074# ifdef FEAT_LINEBREAK
2075 && !in_linebreak
2076# endif
2077 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002078 --bcol; // still working on the previous char, e.g. Tab
2079
2080 // Check if any active property ends.
2081 for (pi = 0; pi < text_props_active; ++pi)
2082 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002083 int tpi = text_prop_idxs[pi];
2084 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002085
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002086 // An inline property ends when after the start column plus
2087 // length. An "above" property ends when used and n_extra
2088 // is zero.
2089 if ((tp->tp_col != MAXCOL
2090 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002091 {
2092 if (pi + 1 < text_props_active)
2093 mch_memmove(text_prop_idxs + pi,
2094 text_prop_idxs + pi + 1,
2095 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002096 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002097 --text_props_active;
2098 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002099# ifdef FEAT_LINEBREAK
2100 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002101 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002102 syntax_attr = 0;
2103# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002104 }
2105 }
2106
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002107# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002108 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002109 // not on the next char yet, don't start another prop
2110 --bcol;
2111# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002112 // Add any text property that starts in this column.
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002113 while (text_prop_next < text_prop_count)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002114 {
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002115 int active;
2116 textprop_T *tp = &text_props[text_prop_next];
2117 if (tp->tp_col == MAXCOL)
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002118 {
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002119 if (bcol == 0 && (tp->tp_flags & TP_FLAG_ALIGN_ABOVE))
2120 active = TRUE;
2121 else if (*ptr != NUL)
2122 break;
2123 else
2124 {
2125 // With 'nowrap' and not in the first screen line only "below"
2126 // text prop can show.
2127 active = wp->w_p_wrap
2128 || wlv.row == startrow
2129 || (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
2130 }
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002131 }
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002132 else
2133 {
2134 if (bcol < tp->tp_col - 1)
2135 break;
2136 active = bcol <= tp->tp_col - 1 + tp->tp_len;
2137 }
2138
2139 if (active)
2140 text_prop_idxs[text_props_active++] = text_prop_next;
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002141 ++text_prop_next;
2142 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002143
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002144 if (wlv.n_extra == 0 ||
2145 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002146 && !(text_prop_type != NULL &&
2147 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002148 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002149 {
2150 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002151 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002152 text_prop_flags = 0;
2153 text_prop_type = NULL;
2154 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002155 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002156 }
Dylan Thacker-Smithc8b47f22024-03-26 18:05:01 +01002157 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002158 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002159 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002160 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002161 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002162
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002163 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002164 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002165
2166 // Sort the properties on priority and/or starting last.
2167 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002168 sort_text_props(wp->w_buffer, text_props,
2169 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002170
2171 for (pi = 0; pi < text_props_active; ++pi)
2172 {
2173 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002174 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002176 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177
Bram Moolenaarcd105412022-10-10 19:50:42 +01002178 // Only use a text property that can be displayed.
2179 // Skip "after" properties when wrap is off and at the
2180 // end of the window.
2181 if (pt != NULL
2182 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2183 && tp->tp_id != -MAXCOL
2184 && !(tp->tp_id < 0
2185 && !wp->w_p_wrap
2186 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2187 | TP_FLAG_ALIGN_ABOVE
2188 | TP_FLAG_ALIGN_BELOW)) == 0
2189 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002190 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002191 if (tp->tp_col == MAXCOL
2192 && *ptr == NUL
2193 && ((wp->w_p_list && lcs_eol_one > 0
2194 && (tp->tp_flags
2195 & TP_FLAG_ALIGN_ABOVE) == 0)
2196 || (ptr == line
2197 && !did_line
2198 && (tp->tp_flags
2199 & TP_FLAG_ALIGN_BELOW))))
2200 {
2201 // skip this prop, first display the '$' after
2202 // the line or display an empty line
2203 text_prop_follows = TRUE;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002204 continue;
2205 }
2206
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002207 if (pt->pt_hl_id > 0)
2208 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209 text_prop_type = pt;
2210 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002211 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002212 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2213 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002214 text_prop_flags = pt->pt_flags;
2215 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002216 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 }
2218 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002219 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002220 && -text_prop_id
2221 <= wp->w_buffer->b_textprop_text.ga_len)
2222 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002223 textprop_T *tp = &text_props[used_tpi];
2224 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002225 ->b_textprop_text.ga_data)[
2226 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002227 int above = (tp->tp_flags
2228 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002229 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002230
2231 // reset the ID in the copy to avoid it being used
2232 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002233 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002234
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002235 if (p != NULL)
2236 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002237 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002238 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002239 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002240 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002241 int wrap = tp->tp_col < MAXCOL
2242 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002243 int padding = tp->tp_col == MAXCOL
2244 && tp->tp_len > 1
2245 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002246
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002247 // Insert virtual text before the current
2248 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002249 wlv.p_extra = p;
2250 wlv.c_extra = NUL;
2251 wlv.c_final = NUL;
2252 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002253 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002254 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002255 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2256 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002257 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002258 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002259 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002260 if (*ptr == NUL)
2261 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002262 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002263# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002264 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002265 {
2266 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002267 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002268 wlv.need_showbreak = FALSE;
2269 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002270 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002271# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002272 if ((right || above || below || !wrap
2273 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002274 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002275 char_u *prev_p_extra = wlv.p_extra;
2276 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002277
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002278 // Take care of padding, right-align and
2279 // truncation.
2280 // Shared with win_lbr_chartabsize(), must do
2281 // exactly the same.
2282 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002283 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002284# ifdef FEAT_RIGHTLEFT
2285 wp->w_p_rl
2286 ? wp->w_width - wlv.col - 1
2287 :
2288# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002289 wlv.col,
2290 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002291 &n_attr, &wlv.n_attr_skip,
2292 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002293 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002294 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002295 // wlv.p_extra was allocated
2296 vim_free(p_extra_free2);
2297 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002298 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002299
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002300 if (above)
Matthias2c9f49b2025-03-16 19:27:51 +01002301 wlv.vcol_off_tp += vim_strsize(wlv.p_extra);
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002302
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002303 if (lcs_eol_one < 0
2304 && wp->w_p_wrap
2305 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002306 + wlv.n_extra - 2 > wp->w_width)
2307 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002308 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002309
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002310 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002311 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002312 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002313 {
2314 draw_screen_line(wp, &wlv);
2315
2316 // When line got too long for screen break
2317 // here.
2318 if (wlv.row == endrow)
2319 {
2320 ++wlv.row;
2321 break;
2322 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002323 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002324 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002325 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002326 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002327 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002328
Bram Moolenaarcd105412022-10-10 19:50:42 +01002329 // If the text didn't reach until the first window
2330 // column we need to skip cells.
2331 if (skip_cells > 0)
2332 {
2333 if (wlv.n_extra > skip_cells)
2334 {
2335 wlv.n_extra -= skip_cells;
2336 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002337 wlv.n_attr_skip -= skip_cells;
2338 if (wlv.n_attr_skip < 0)
2339 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002340 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002341 skip_cells = 0;
2342 }
2343 else
2344 {
2345 // the whole text is left of the window, drop
2346 // it and advance to the next one
2347 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002348 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002349 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002350 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002351 bail_out = TRUE;
2352 }
2353 }
2354
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002355 // If another text prop follows the condition below at
2356 // the last window column must know.
Dylan Thacker-Smith83925be2024-02-21 21:03:10 +01002357 // If this is an "above" text prop and 'nowrap' then we
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002358 // must wrap anyway.
2359 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002360 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002361 && (wp->w_p_wrap
2362 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002363 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002364
2365 if (bail_out)
2366 // starting a new line for "below"
2367 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002368 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002370 else if (text_prop_next < text_prop_count
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002371 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01002372 || (!wp->w_p_wrap && wlv.col == wp->w_width - 1)))
2373 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01002374 // When at last-but-one character and a text property
2375 // follows after it, we may need to flush the line after
2376 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002377 // Or when not wrapping and at the rightmost column.
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002378
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01002379 int only_below_follows = !wp->w_p_wrap && wlv.col == wp->w_width - 1;
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002380 // TODO: Store "after"/"right"/"below" text properties in order
2381 // in the buffer so only `text_props[text_prop_count - 1]`
2382 // needs to be checked for following "below" virtual text
2383 for (int i = text_prop_next; i < text_prop_count; ++i)
2384 {
2385 if (text_props[i].tp_col == MAXCOL
2386 && (!only_below_follows
2387 || (text_props[i].tp_flags & TP_FLAG_ALIGN_BELOW)))
2388 {
2389 text_prop_follows = TRUE;
2390 break;
2391 }
2392 }
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01002393 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002394 }
zeertzjq6e940d92023-08-17 23:21:40 +02002395
2396 if (wlv.start_extra_for_textprop)
2397 {
2398 wlv.start_extra_for_textprop = FALSE;
2399 // restore search_attr and area_attr when n_extra
2400 // is down to zero
2401 saved_search_attr = search_attr;
2402 saved_area_attr = area_attr;
2403 search_attr = 0;
2404 area_attr = 0;
2405 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002406#endif
2407
zeertzjq6e940d92023-08-17 23:21:40 +02002408 int *area_attr_p =
2409#ifdef FEAT_PROP_POPUP
2410 wlv.extra_for_textprop ? &saved_area_attr :
2411#endif
2412 &area_attr;
2413
2414 // handle Visual or match highlighting in this line
2415 if (wlv.vcol == wlv.fromcol
2416 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2417 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2418 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2419 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2420 || ((int)vcol_prev == fromcol_prev
2421 && vcol_prev < wlv.vcol // not at margin
2422 && wlv.vcol < wlv.tocol))
2423 *area_attr_p = vi_attr; // start highlighting
2424 else if (*area_attr_p != 0
2425 && (wlv.vcol == wlv.tocol
2426 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2427 *area_attr_p = 0; // stop highlighting
2428
Bram Moolenaare38fc862022-08-11 17:24:50 +01002429 if (wlv.n_extra == 0)
2430 {
zeertzjqf25d8f92024-12-18 21:12:25 +01002431#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002432 // Check for start/end of 'hlsearch' and other matches.
2433 // After end, check for start/end of next match.
2434 // When another match, have to check for start again.
2435 v = (long)(ptr - line);
2436 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2437 &screen_search_hl, &has_match_conc,
2438 &match_conc, did_line_attr, lcs_eol_one,
2439 &on_last_col);
2440 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002441
2442 // Do not allow a conceal over EOL otherwise EOL will be missed
2443 // and bad things happen.
2444 if (*ptr == NUL)
2445 has_match_conc = 0;
zeertzjqf25d8f92024-12-18 21:12:25 +01002446#else
2447 search_attr = 0;
zeertzjqe500ae82023-08-17 22:35:26 +02002448#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002449
zeertzjqf25d8f92024-12-18 21:12:25 +01002450 // Check if ComplMatchIns highlight is needed.
glepnir76bdb822025-02-08 19:04:51 +01002451 if ((State & MODE_INSERT) && ins_compl_win_active(wp)
2452 && (in_curline || ins_compl_lnum_in_range(lnum)))
zeertzjqf25d8f92024-12-18 21:12:25 +01002453 {
2454 int ins_match_attr =
glepnir76bdb822025-02-08 19:04:51 +01002455 ins_compl_col_range_attr(lnum, (int)(ptr - line));
zeertzjqf25d8f92024-12-18 21:12:25 +01002456 if (ins_match_attr > 0)
2457 search_attr =
2458 hl_combine_attr(search_attr, ins_match_attr);
2459 }
2460 }
2461
Bram Moolenaare38fc862022-08-11 17:24:50 +01002462#ifdef FEAT_DIFF
2463 if (wlv.diff_hlf != (hlf_T)0)
2464 {
Yee Cheng Chin9943d472025-03-26 19:41:02 +01002465 if (line_changes.num_changes > 0
2466 && change_index >= 0
2467 && change_index < line_changes.num_changes - 1)
2468 {
2469 if (ptr - line >= line_changes.changes[change_index+1].dc_start[line_changes.bufidx])
2470 change_index += 1;
2471 }
2472 int added = FALSE;
2473 if (line_changes.num_changes > 0 && change_index >= 0 && change_index < line_changes.num_changes)
2474 {
2475 added = diff_change_parse(&line_changes,
2476 &line_changes.changes[change_index],
2477 &change_start,
2478 &change_end);
2479 }
Bram Moolenaard097af72022-12-17 11:33:00 +00002480 // When there is extra text (e.g. virtual text) it gets the
2481 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002482 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2483 && wlv.n_extra == 0)
Yee Cheng Chin9943d472025-03-26 19:41:02 +01002484 wlv.diff_hlf = added ? HLF_TXA : HLF_TXD; // added/changed text
2485 if ((wlv.diff_hlf == HLF_TXD || wlv.diff_hlf == HLF_TXA)
2486 && ((ptr - line >= change_end && wlv.n_extra == 0)
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002487 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002488 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002489 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002490 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2491 && wp->w_p_culopt_flags != CULOPT_NBR
2492 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2493 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002494 wlv.line_attr = hl_combine_attr(
2495 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002496 }
2497#endif
2498
Bram Moolenaara74fda62019-10-19 17:38:03 +02002499#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002500 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002501 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002502 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002503# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002504 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002505 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002506# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002507 // Get syntax attribute.
2508 if (has_syntax)
2509 {
2510 // Get the syntax attribute for the character. If there
2511 // is an error, disable syntax highlighting.
2512 save_did_emsg = did_emsg;
2513 did_emsg = FALSE;
2514
2515 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002516 if (v == prev_syntax_col)
2517 // at same column again
2518 syntax_attr = prev_syntax_attr;
2519 else
2520 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002521# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002522 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002523# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002524 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002525# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002526 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002527# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002528 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002529 prev_syntax_col = v;
2530 prev_syntax_attr = syntax_attr;
2531 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002532
Bram Moolenaar34390282019-10-16 14:38:26 +02002533 if (did_emsg)
2534 {
2535 wp->w_s->b_syn_error = TRUE;
2536 has_syntax = FALSE;
2537 syntax_attr = 0;
2538 }
2539 else
2540 did_emsg = save_did_emsg;
2541# ifdef SYN_TIME_LIMIT
2542 if (wp->w_s->b_syn_slow)
2543 has_syntax = FALSE;
2544# endif
2545
2546 // Need to get the line again, a multi-line regexp may
2547 // have made it invalid.
2548 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2549 ptr = line + v;
2550# ifdef FEAT_CONCEAL
2551 // no concealing past the end of the line, it interferes
2552 // with line highlighting
2553 if (*ptr == NUL)
2554 syntax_flags = 0;
2555 else
2556 syntax_flags = get_syntax_info(&syntax_seqnr);
2557# endif
2558 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002559 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002560# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002561 // Combine text property highlight into syntax highlight.
2562 if (text_prop_type != NULL)
2563 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002564 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002565 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2566 else
2567 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002568 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002569 }
2570# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002571#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002572
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 // Decide which of the highlight attributes to use.
2574 attr_pri = TRUE;
2575#ifdef LINE_ATTR
2576 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002577 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002578 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002579 if (!highlight_match)
2580 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002581 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002582# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002583 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002584# endif
2585 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002587 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002588 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002589# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002590 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002591# endif
2592 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002593 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002594 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2595 || wlv.vcol < wlv.fromcol
2596 || vcol_prev < fromcol_prev
2597 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002599 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002601# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002602 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002603# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002604 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002605# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002606 attr_pri = FALSE;
2607 }
2608#else
2609 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002610 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002611 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002612 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002613#endif
2614 else
2615 {
2616 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002617#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002618 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002619#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002620 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002621#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002622 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002623#ifdef FEAT_PROP_POPUP
2624 // override with text property highlight when "override" is TRUE
2625 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002626 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002627#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002629
2630 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002631 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002632 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002633 if (wlv.char_attr == 0)
2634 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002635 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002636 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002637 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638
2639 // Get the next character to put on the screen.
2640
2641 // The "p_extra" points to the extra stuff that is inserted to
2642 // represent special characters (non-printable stuff) and other
2643 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002644 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002645 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2646 // "p_extra[n_extra]".
2647 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002648 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002649 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002650 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002652 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2653 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2655 if (enc_utf8 && utf_char2len(c) > 1)
2656 {
2657 mb_utf8 = TRUE;
2658 u8cc[0] = 0;
2659 c = 0xc0;
2660 }
2661 else
2662 mb_utf8 = FALSE;
2663 }
2664 else
2665 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002666 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002667 if (has_mbyte)
2668 {
2669 mb_c = c;
2670 if (enc_utf8)
2671 {
2672 // If the UTF-8 character is more than one byte:
2673 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002674 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002676 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677 mb_l = 1;
2678 else if (mb_l > 1)
2679 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002680 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002681 mb_utf8 = TRUE;
2682 c = 0xc0;
2683 }
2684 }
2685 else
2686 {
2687 // if this is a DBCS character, put it in "mb_c"
2688 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002689 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 mb_l = 1;
2691 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002692 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693 }
2694 if (mb_l == 0) // at the NUL at end-of-line
2695 mb_l = 1;
2696
2697 // If a double-width char doesn't fit display a '>' in the
2698 // last column.
2699 if ((
2700# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002701 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002703 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002704 && (*mb_char2cells)(mb_c) == 2)
2705 {
2706 c = '>';
2707 mb_c = c;
2708 mb_l = 1;
2709 mb_utf8 = FALSE;
2710 multi_attr = HL_ATTR(HLF_AT);
2711#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002712 if (wlv.cul_attr)
2713 multi_attr = hl_combine_attr(
2714 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002715#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002716 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002717
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002718 // put the pointer back to output the double-width
2719 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002720 ++wlv.n_extra;
2721 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002722 }
2723 else
2724 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002725 wlv.n_extra -= mb_l - 1;
2726 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002727 }
2728 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002729 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002730 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002731 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002732#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002733 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002734 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002735 // Only restore search_attr and area_attr after "n_extra" in
2736 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002737 if (wlv.saved_n_extra <= 0)
2738 {
2739 if (search_attr == 0)
2740 search_attr = saved_search_attr;
2741 if (area_attr == 0 && *ptr != NUL)
2742 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002743
2744 if (wlv.extra_for_textprop)
2745 // wlv.extra_attr should be used at this position but
2746 // not any further.
2747 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002748 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002749
2750 wlv.extra_for_textprop = FALSE;
2751 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002752 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002753#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754 }
2755 else
2756 {
2757#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002758 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002760 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002761
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762 // Get a character from the line itself.
2763 c = *ptr;
2764#ifdef FEAT_LINEBREAK
2765 c0 = *ptr;
2766#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002767 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002768 {
2769#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002770 // text is finished, may display a "below" virtual text
2771 did_line = TRUE;
2772#endif
zeertzjqb557f482023-08-22 22:07:34 +02002773 // no more cells to skip
2774 skip_cells = 0;
Christian Brabandta899b272025-06-28 18:40:15 +02002775#ifdef FEAT_TERMINAL
2776 if (term_show_buffer(wp->w_buffer)
Christian Brabandt66b72f42025-06-29 22:22:05 +02002777 && wlv.vcol == 0
Christian Brabandta899b272025-06-28 18:40:15 +02002778 && wlv.win_attr == term_get_attr(wp, lnum, -1))
2779 // reset highlighting attribute
2780 wlv.win_attr = 0;
2781#endif
zeertzjqb557f482023-08-22 22:07:34 +02002782 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002783
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 if (has_mbyte)
2785 {
2786 mb_c = c;
2787 if (enc_utf8)
2788 {
2789 // If the UTF-8 character is more than one byte: Decode it
2790 // into "mb_c".
2791 mb_l = utfc_ptr2len(ptr);
2792 mb_utf8 = FALSE;
2793 if (mb_l > 1)
2794 {
2795 mb_c = utfc_ptr2char(ptr, u8cc);
2796 // Overlong encoded ASCII or ASCII with composing char
2797 // is displayed normally, except a NUL.
2798 if (mb_c < 0x80)
2799 {
2800 c = mb_c;
2801#ifdef FEAT_LINEBREAK
2802 c0 = mb_c;
2803#endif
2804 }
2805 mb_utf8 = TRUE;
2806
2807 // At start of the line we can have a composing char.
2808 // Draw it as a space with a composing char.
2809 if (utf_iscomposing(mb_c))
2810 {
2811 int i;
2812
2813 for (i = Screen_mco - 1; i > 0; --i)
2814 u8cc[i] = u8cc[i - 1];
2815 u8cc[0] = mb_c;
2816 mb_c = ' ';
2817 }
2818 }
2819
2820 if ((mb_l == 1 && c >= 0x80)
2821 || (mb_l >= 1 && mb_c == 0)
2822 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2823 {
2824 // Illegal UTF-8 byte: display as <xx>.
2825 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002826 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002827# ifdef FEAT_RIGHTLEFT
2828 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002829 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002831 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002832 c = *wlv.p_extra;
2833 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002835 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2836 wlv.c_extra = NUL;
2837 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838 if (area_attr == 0 && search_attr == 0)
2839 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002840 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002841 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002842 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002843 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002844 }
2845 }
2846 else if (mb_l == 0) // at the NUL at end-of-line
2847 mb_l = 1;
2848#ifdef FEAT_ARABIC
2849 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2850 {
2851 // Do Arabic shaping.
2852 int pc, pc1, nc;
2853 int pcc[MAX_MCO];
2854
2855 // The idea of what is the previous and next
2856 // character depends on 'rightleft'.
2857 if (wp->w_p_rl)
2858 {
2859 pc = prev_c;
2860 pc1 = prev_c1;
2861 nc = utf_ptr2char(ptr + mb_l);
2862 prev_c1 = u8cc[0];
2863 }
2864 else
2865 {
2866 pc = utfc_ptr2char(ptr + mb_l, pcc);
2867 nc = prev_c;
2868 pc1 = pcc[0];
2869 }
2870 prev_c = mb_c;
2871
2872 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2873 }
2874 else
2875 prev_c = mb_c;
2876#endif
2877 }
2878 else // enc_dbcs
2879 {
2880 mb_l = MB_BYTE2LEN(c);
2881 if (mb_l == 0) // at the NUL at end-of-line
2882 mb_l = 1;
2883 else if (mb_l > 1)
2884 {
2885 // We assume a second byte below 32 is illegal.
2886 // Hopefully this is OK for all double-byte encodings!
2887 if (ptr[1] >= 32)
2888 mb_c = (c << 8) + ptr[1];
2889 else
2890 {
2891 if (ptr[1] == NUL)
2892 {
2893 // head byte at end of line
2894 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002895 transchar_nonprint(wp->w_buffer, wlv.extra, c);
John Marriottf51ff962024-06-02 19:44:11 +02002896 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897 }
2898 else
2899 {
2900 // illegal tail byte
2901 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002902 STRCPY(wlv.extra, "XX");
John Marriottf51ff962024-06-02 19:44:11 +02002903 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002904 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002905 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002906 wlv.c_extra = NUL;
2907 wlv.c_final = NUL;
2908 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 if (area_attr == 0 && search_attr == 0)
2910 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002911 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002912 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002913 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002914 // save current attr
2915 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916 }
2917 mb_c = c;
2918 }
2919 }
2920 }
2921 // If a double-width char doesn't fit display a '>' in the
2922 // last column; the character is displayed at the start of the
2923 // next line.
2924 if ((
2925# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002926 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002927# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002928 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 && (*mb_char2cells)(mb_c) == 2)
2930 {
2931 c = '>';
2932 mb_c = c;
2933 mb_utf8 = FALSE;
2934 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002935 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936 // Put pointer back so that the character will be
2937 // displayed at the start of the next line.
2938 --ptr;
2939#ifdef FEAT_CONCEAL
2940 did_decrement_ptr = TRUE;
2941#endif
2942 }
2943 else if (*ptr != NUL)
2944 ptr += mb_l - 1;
2945
2946 // If a double-width char doesn't fit at the left side display
2947 // a '<' in the first column. Don't do this for unprintable
2948 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002949 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002950 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002951 wlv.n_extra = 1;
2952 wlv.c_extra = MB_FILLER_CHAR;
2953 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954 c = ' ';
2955 if (area_attr == 0 && search_attr == 0)
2956 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002957 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002958 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002959 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 }
2962 mb_c = c;
2963 mb_utf8 = FALSE;
2964 mb_l = 1;
2965 }
2966
2967 }
2968 ++ptr;
2969
2970 if (extra_check)
2971 {
2972#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002973 // Check spelling (unless at the end of the line).
2974 // Only do this when there is no syntax highlighting, the
2975 // @Spell cluster is not used or the current syntax item
2976 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002977 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002978 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 {
2980 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002981 // do not calculate cap_col at the end of the line or when
2982 // only white space is following
2983 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984# ifdef FEAT_SYN_HL
2985 !has_syntax ||
2986# endif
2987 can_spell))
2988 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002989 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002990 int len;
2991 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002992
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995
2996 // Use nextline[] if possible, it has the start of the
2997 // next line concatenated.
2998 if ((prev_ptr - line) - nextlinecol >= 0)
2999 p = nextline + (prev_ptr - line) - nextlinecol;
3000 else
3001 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01003002 spv->spv_cap_col -= (int)(prev_ptr - line);
3003 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
3004 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003005 word_end = v + len;
3006
3007 // In Insert mode only highlight a word that
3008 // doesn't touch the cursor.
3009 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01003010 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003011 && wp->w_cursor.lnum == lnum
3012 && wp->w_cursor.col >=
3013 (colnr_T)(prev_ptr - line)
3014 && wp->w_cursor.col < (colnr_T)word_end)
3015 {
3016 spell_hlf = HLF_COUNT;
3017 spell_redraw_lnum = lnum;
3018 }
3019
3020 if (spell_hlf == HLF_COUNT && p != prev_ptr
3021 && (p - nextline) + len > nextline_idx)
3022 {
3023 // Remember that the good word continues at the
3024 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01003025 spv->spv_checked_lnum = lnum + 1;
3026 spv->spv_checked_col = (p - nextline) + len
3027 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003028 }
3029
3030 // Turn index into actual attributes.
3031 if (spell_hlf != HLF_COUNT)
3032 spell_attr = highlight_attr[spell_hlf];
3033
Luuk van Baal30805a12023-05-27 22:22:10 +01003034 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035 {
3036 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01003037 && (p - nextline) + spv->spv_cap_col
3038 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039 {
3040 // Remember that the word in the next line
3041 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01003042 spv->spv_capcol_lnum = lnum + 1;
3043 spv->spv_cap_col = ((p - nextline)
3044 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 }
3046 else
3047 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01003048 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049 }
3050 }
3051 }
3052 if (spell_attr != 0)
3053 {
3054 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003055 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3056 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 wlv.char_attr = hl_combine_attr(spell_attr,
3059 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 }
3061#endif
3062#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02003063 // we don't want linebreak to apply for lines that start with
3064 // leading spaces, followed by long letters (since it would add
3065 // a break at the beginning of a line and this might be unexpected)
3066 //
3067 // So only allow to linebreak, once we have found chars not in
3068 // 'breakat' in the line.
3069 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
3070 !VIM_ISBREAK((int)*ptr))
3071 wlv.need_lbr = TRUE;
3072#endif
3073#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02003075 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003076 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
3077 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02003078 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
3079 : 0;
3080 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01003081 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003082
zeertzjqce53e3e2023-09-01 18:49:30 +02003083 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
3084# ifdef FEAT_PROP_POPUP
3085 - vcol_first_char,
3086# endif
3087 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003088# ifdef FEAT_PROP_POPUP
3089 // do not want virtual text counted here
3090 cts.cts_has_prop_with_text = FALSE;
3091# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003092 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003093 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02003094
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003095 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003096 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003097 // line break, but for TABs the highlighting should
3098 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003099 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02003100
Bram Moolenaar1306b362022-08-06 15:59:06 +01003101 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01003103 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003104 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 wp->w_buffer->b_p_vts_array) - 1;
3106# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003107 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003108 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003109# endif
3110
Bram Moolenaar1306b362022-08-06 15:59:06 +01003111 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
3112 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003113# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01003114 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00003115 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00003116# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003117 if (VIM_ISWHITE(c))
3118 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003119# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003120 if (c == TAB)
3121 // See "Tab alignment" below.
3122 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003123# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124 if (!wp->w_p_list)
3125 c = ' ';
3126 }
3127 }
3128#endif
zeertzjqabc80812023-09-24 23:32:18 +02003129 if (wp->w_p_list)
3130 {
3131 in_multispace = c == ' ' && (*ptr == ' '
3132 || (prev_ptr > line && prev_ptr[-1] == ' '));
3133 if (!in_multispace)
3134 multispace_pos = 0;
3135 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003136
Bram Moolenaareed9d462021-02-15 20:38:25 +01003137 // 'list': Change char 160 to 'nbsp' and space to 'space'
3138 // setting in 'listchars'. But not when the character is
3139 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 if (wp->w_p_list
3141 && ((((c == 160 && mb_l == 1)
3142 || (mb_utf8
3143 && ((mb_c == 160 && mb_l == 2)
3144 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003145 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 || (c == ' '
3147 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003148 && (wp->w_lcs_chars.space
3149 || (in_multispace
3150 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003151 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152 && ptr - line <= trailcol)))
3153 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003154 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3155 {
3156 c = wp->w_lcs_chars.multispace[multispace_pos++];
3157 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3158 multispace_pos = 0;
3159 }
3160 else
3161 c = (c == ' ') ? wp->w_lcs_chars.space
3162 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163 if (area_attr == 0 && search_attr == 0)
3164 {
3165 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003166 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003167 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003168 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 }
3170 mb_c = c;
3171 if (enc_utf8 && utf_char2len(c) > 1)
3172 {
3173 mb_utf8 = TRUE;
3174 u8cc[0] = 0;
3175 c = 0xc0;
3176 }
3177 else
3178 mb_utf8 = FALSE;
3179 }
3180
zeertzjq2e7cba32022-06-10 15:30:32 +01003181 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3182 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003184 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3185 && wp->w_lcs_chars.leadmultispace != NULL)
3186 {
3187 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003188 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3189 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003190 multispace_pos = 0;
3191 }
3192
3193 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3194 c = wp->w_lcs_chars.trail;
3195
3196 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3197 c = wp->w_lcs_chars.lead;
3198
zeertzjq2e7cba32022-06-10 15:30:32 +01003199 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003200 c = wp->w_lcs_chars.space;
3201
3202
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 if (!attr_pri)
3204 {
3205 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003206 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003207 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003208 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 }
3210 mb_c = c;
3211 if (enc_utf8 && utf_char2len(c) > 1)
3212 {
3213 mb_utf8 = TRUE;
3214 u8cc[0] = 0;
3215 c = 0xc0;
3216 }
3217 else
3218 mb_utf8 = FALSE;
3219 }
3220 }
3221
3222 // Handling of non-printable characters.
3223 if (!vim_isprintc(c))
3224 {
3225 // when getting a character from the file, we may have to
3226 // turn it into something else on the way to putting it
3227 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003228 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003230 int tab_len = 0;
3231 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003233 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003234
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235 // only adjust the tab_len, when at the first column
3236 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003237 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003238 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239#endif
3240 // tab amount depends on current column
3241#ifdef FEAT_VARTABS
3242 tab_len = tabstop_padding(vcol_adjusted,
3243 wp->w_buffer->b_p_ts,
3244 wp->w_buffer->b_p_vts_array) - 1;
3245#else
3246 tab_len = (int)wp->w_buffer->b_p_ts
3247 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3248#endif
3249
3250#ifdef FEAT_LINEBREAK
3251 if (!wp->w_p_lbr || !wp->w_p_list)
3252#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003253 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003255 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003256 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257#ifdef FEAT_LINEBREAK
3258 else
3259 {
3260 char_u *p;
3261 int len;
3262 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003263 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003265# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003266 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003268 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003269
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003271 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003272 && old_boguscols > 0
3273 && wlv.n_extra > tab_len)
3274 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003275# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003276 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003277 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003278 // If wlv.n_extra > 0, it gives the number of chars
3279 // to use for a tab, else we need to calculate the
3280 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003281 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3282 len = tab_len * tab2_len;
3283 if (wp->w_lcs_chars.tab3)
3284 len += mb_char2len(wp->w_lcs_chars.tab3)
3285 - tab2_len;
3286 if (wlv.n_extra > 0)
3287 len += wlv.n_extra - tab_len;
3288 c = wp->w_lcs_chars.tab1;
3289 p = alloc(len + 1);
3290 if (p == NULL)
3291 wlv.n_extra = 0;
3292 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003294 vim_memset(p, ' ', len);
3295 p[len] = NUL;
3296 vim_free(wlv.p_extra_free);
3297 wlv.p_extra_free = p;
3298 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003299 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003300 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003301
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003302 if (*p == NUL)
3303 {
3304 tab_len = i;
3305 break;
3306 }
3307
3308 // if tab3 is given, use it for the last
3309 // char
3310 if (wp->w_lcs_chars.tab3
3311 && i == tab_len - 1)
3312 lcs = wp->w_lcs_chars.tab3;
3313 p += mb_char2bytes(lcs, p);
3314 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003316 }
3317 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003318# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003319 // n_extra will be increased by
3320 // FIX_FOX_BOGUSCOLS macro below, so need to
3321 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003322 if (wlv.vcol_off_co > 0)
3323 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003324# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003325 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327 }
3328#endif
3329#ifdef FEAT_CONCEAL
3330 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003331 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332
3333 // Tab alignment should be identical regardless of
3334 // 'conceallevel' value. So tab compensates of all
3335 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003336 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 // line. Note that the tab can be longer than
3338 // 'tabstop' when there are concealed characters.
3339 FIX_FOR_BOGUSCOLS;
3340
3341 // Make sure, the highlighting for the tab char will be
3342 // correctly set further below (effectively reverts the
zeertzjq010e1532024-03-14 18:22:17 +01003343 // FIX_FOR_BOGUSCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003344 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003345 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003346 tab_len += vc_saved;
3347 }
3348#endif
3349 mb_utf8 = FALSE; // don't draw as UTF-8
3350 if (wp->w_p_list)
3351 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003352 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003353 ? wp->w_lcs_chars.tab3
3354 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003356 if (wp->w_p_lbr && wlv.p_extra != NULL
3357 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003358 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 else
3360#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003361 wlv.c_extra = wp->w_lcs_chars.tab2;
3362 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003364 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003365 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003366 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367 mb_c = c;
3368 if (enc_utf8 && utf_char2len(c) > 1)
3369 {
3370 mb_utf8 = TRUE;
3371 u8cc[0] = 0;
3372 c = 0xc0;
3373 }
3374 }
3375 else
3376 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003377 wlv.c_final = NUL;
3378 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379 c = ' ';
3380 }
3381 }
3382 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003383 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003385 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3386 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387 && VIsual_mode != Ctrl_V
3388 && (
3389# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003390 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003392 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 && !(noinvcur
3394 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003395 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 && lcs_eol_one > 0)
3397 {
3398 // Display a '$' after the line or highlight an extra
3399 // character if the line break is included.
3400#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3401 // For a diff line the highlighting continues after the
3402 // "$".
3403 if (
3404# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003405 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406# ifdef LINE_ATTR
3407 &&
3408# endif
3409# endif
3410# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003411 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412# endif
3413 )
3414#endif
3415 {
3416 // In virtualedit, visual selections may extend
3417 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003418 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003419 && wlv.tocol != MAXCOL
3420 && wlv.vcol < wlv.tocol))
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01003421 wlv.p_extra = (char_u *)"";
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003422 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003423 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003424 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3425 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 else
3427 c = ' ';
3428 lcs_eol_one = -1;
3429 --ptr; // put it back at the NUL
3430 if (!attr_pri)
3431 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003432 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003433 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 n_attr = 1;
3435 }
3436 mb_c = c;
3437 if (enc_utf8 && utf_char2len(c) > 1)
3438 {
3439 mb_utf8 = TRUE;
3440 u8cc[0] = 0;
3441 c = 0xc0;
3442 }
3443 else
3444 mb_utf8 = FALSE; // don't draw as UTF-8
3445 }
3446 else if (c != NUL)
3447 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003448 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3449 if (wlv.n_extra == 0)
3450 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451#ifdef FEAT_RIGHTLEFT
3452 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003453 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003455 wlv.c_extra = NUL;
3456 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457#ifdef FEAT_LINEBREAK
3458 if (wp->w_p_lbr)
3459 {
3460 char_u *p;
3461
Bram Moolenaar1306b362022-08-06 15:59:06 +01003462 c = *wlv.p_extra;
3463 p = alloc(wlv.n_extra + 1);
John Marriottf51ff962024-06-02 19:44:11 +02003464 if (p == NULL)
3465 wlv.n_extra = 0;
3466 else
3467 {
3468 vim_memset(p, ' ', wlv.n_extra);
3469 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3470 p[wlv.n_extra] = NUL;
3471 vim_free(wlv.p_extra_free);
3472 wlv.p_extra_free = wlv.p_extra = p;
3473 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474 }
3475 else
3476#endif
3477 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003478 wlv.n_extra = byte2cells(c) - 1;
3479 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 }
3481 if (!attr_pri)
3482 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003483 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003484 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003485 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003486#ifdef FEAT_PROP_POPUP
3487 if (text_prop_type != NULL &&
3488 text_prop_flags & PT_FLAG_OVERRIDE)
3489 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3490#endif
3491
Bram Moolenaar1306b362022-08-06 15:59:06 +01003492 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 }
3494 mb_utf8 = FALSE; // don't draw as UTF-8
3495 }
3496 else if (VIsual_active
3497 && (VIsual_mode == Ctrl_V
3498 || VIsual_mode == 'v')
3499 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003500 && wlv.tocol != MAXCOL
3501 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 && (
3503#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003504 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003506 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 {
3508 c = ' ';
3509 --ptr; // put it back at the NUL
3510 }
3511#if defined(LINE_ATTR)
3512 else if ((
3513# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003514 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515# endif
3516# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003517 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003519 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 ) && (
3521# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003522 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003524 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003526 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527# endif
3528 < wp->w_width)))
3529 {
3530 // Highlight until the right side of the window
3531 c = ' ';
3532 --ptr; // put it back at the NUL
3533
3534 // Remember we do the char for line highlighting.
3535 ++did_line_attr;
3536
3537 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003538 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003540 || (wp->w_p_list &&
3541 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003542 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003543#ifdef FEAT_SIGNS
3544 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003545 // but not when cursorline is active
3546 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3547 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003548 wlv.char_attr = wlv.sattr.sat_linehl;
3549#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550# ifdef FEAT_DIFF
Yee Cheng Chin9943d472025-03-26 19:41:02 +01003551 if (wlv.diff_hlf == HLF_TXD || wlv.diff_hlf == HLF_TXA)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 wlv.diff_hlf = HLF_CHD;
3554 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003555 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003556 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003557 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3558 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003559 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 || (wlv.vcol >= left_curline_col
3561 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003562 wlv.char_attr = hl_combine_attr(
3563 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 }
3565 }
3566# endif
3567# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003568 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003570 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003571 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3572 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003573 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003574 if (!wlv.cul_screenline
3575 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003576 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003577 wlv.char_attr = hl_combine_attr(
3578 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003580 else if (wlv.line_attr)
3581 wlv.char_attr = hl_combine_attr(
3582 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 }
3584# endif
3585 }
3586#endif
3587 }
3588
3589#ifdef FEAT_CONCEAL
3590 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003591 && (wp != curwin || lnum != wp->w_cursor.lnum
3592 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3594 && !(lnum_in_visual_area
3595 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3596 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003597 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003598 if (((prev_syntax_id != syntax_seqnr
3599 && (syntax_flags & HL_CONCEAL) != 0)
3600 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003601 && (syn_get_sub_char() != NUL
3602 || (has_match_conc && match_conc)
3603 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 && wp->w_p_cole != 3)
3605 {
3606 // First time at this concealed item: display one
3607 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003608 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 c = match_conc;
3610 else if (syn_get_sub_char() != NUL)
3611 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003612 else if (wp->w_lcs_chars.conceal != NUL)
3613 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 else
3615 c = ' ';
3616
zeertzjq010e1532024-03-14 18:22:17 +01003617 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3618 // When the first char to be concealed is double-width,
3619 // need to advance one more virtual column.
3620 wlv.n_extra++;
3621
3622 mb_c = c;
3623 if (enc_utf8 && utf_char2len(c) > 1)
3624 {
3625 mb_utf8 = TRUE;
3626 u8cc[0] = 0;
3627 c = 0xc0;
3628 }
3629 else
3630 mb_utf8 = FALSE; // don't draw as UTF-8
3631
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632 prev_syntax_id = syntax_seqnr;
3633
Bram Moolenaar1306b362022-08-06 15:59:06 +01003634 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003635 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003636 wlv.vcol += wlv.n_extra;
3637 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 {
3639# ifdef FEAT_RIGHTLEFT
3640 if (wp->w_p_rl)
3641 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003642 wlv.col -= wlv.n_extra;
3643 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003644 }
3645 else
3646# endif
3647 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003648 wlv.boguscols += wlv.n_extra;
3649 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 }
3651 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003652 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653 n_attr = 0;
3654 }
zeertzjqb557f482023-08-22 22:07:34 +02003655 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 {
3657 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003658 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660 }
3661 else
3662 {
3663 prev_syntax_id = 0;
3664 is_concealing = FALSE;
3665 }
3666
zeertzjqb557f482023-08-22 22:07:34 +02003667 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668 // not showing the '>', put pointer back to avoid getting stuck
3669 ++ptr;
3670
3671#endif // FEAT_CONCEAL
3672 }
3673
3674#ifdef FEAT_CONCEAL
3675 // In the cursor line and we may be concealing characters: correct
3676 // the cursor column when we reach its position.
zeertzjq253ff4d2024-03-13 20:38:26 +01003677 // With 'virtualedit' we may never reach cursor position, but we still
3678 // need to correct the cursor column, so do that at end of line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003679 if (!did_wcol && wlv.draw_state == WL_LINE
zeertzjqf4ccada2024-12-17 20:50:19 +01003680 && in_curline && conceal_cursor_line(wp)
zeertzjq253ff4d2024-03-13 20:38:26 +01003681 && (wlv.vcol + skip_cells >= wp->w_virtcol || c == NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003683# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003685 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003687# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003688 wp->w_wcol = wlv.col - wlv.boguscols;
zeertzjq253ff4d2024-03-13 20:38:26 +01003689 if (wlv.vcol + skip_cells < wp->w_virtcol)
3690 // Cursor beyond end of the line with 'virtualedit'.
3691 wp->w_wcol += wp->w_virtcol - wlv.vcol - skip_cells;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003692 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003693 did_wcol = TRUE;
3694 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003695# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003696 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003697# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003698 }
3699#endif
3700
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003701 // Use "wlv.extra_attr", but don't override visual selection
3702 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003703 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3704 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003705 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003706 && (!attr_pri
3707#ifdef FEAT_PROP_POPUP
3708 || (text_prop_flags & PT_FLAG_OVERRIDE)
3709#endif
3710 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 {
3712#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003713 if (wlv.line_attr)
3714 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 else
3716#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003717 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003718#ifdef FEAT_PROP_POPUP
3719 if (reset_extra_attr)
3720 {
3721 reset_extra_attr = FALSE;
3722 wlv.extra_attr = 0;
3723 }
3724#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003725 }
3726
3727#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3728 // XIM don't send preedit_start and preedit_end, but they send
3729 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3730 // im_is_preediting() here.
3731 if (p_imst == IM_ON_THE_SPOT
3732 && xic != NULL
3733 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003734 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735 && !p_imdisable
3736 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003737 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738 {
3739 colnr_T tcol;
3740
3741 if (preedit_end_col == MAXCOL)
3742 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3743 else
3744 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003745 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 {
3747 if (feedback_old_attr < 0)
3748 {
3749 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003750 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003752 wlv.char_attr = im_get_feedback_attr(feedback_col);
3753 if (wlv.char_attr < 0)
3754 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 feedback_col++;
3756 }
3757 else if (feedback_old_attr >= 0)
3758 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003759 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 feedback_old_attr = -1;
3761 feedback_col = 0;
3762 }
3763 }
3764#endif
3765 // Handle the case where we are in column 0 but not on the first
3766 // character of the line and the user wants us to show us a
zeertzjq08a83a02025-02-20 22:04:09 +01003767 // special character (via 'listchars' option "precedes:<char>").
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768 if (lcs_prec_todo != NUL
3769 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003770 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3771 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003773 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003774#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003775 && wlv.draw_state > WL_NR
zeertzjq13f100e2025-02-21 19:49:44 +01003776 && skip_cells <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 && c != NUL)
3778 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003779 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 lcs_prec_todo = NUL;
3781 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3782 {
3783 // Double-width character being overwritten by the "precedes"
3784 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003785 wlv.c_extra = MB_FILLER_CHAR;
3786 wlv.c_final = NUL;
3787 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003789 wlv.extra_attr =
3790 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791 }
3792 mb_c = c;
3793 if (enc_utf8 && utf_char2len(c) > 1)
3794 {
3795 mb_utf8 = TRUE;
3796 u8cc[0] = 0;
3797 c = 0xc0;
3798 }
3799 else
3800 mb_utf8 = FALSE; // don't draw as UTF-8
3801 if (!attr_pri)
3802 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003803 saved_attr3 = wlv.char_attr; // save current attr
3804 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805 n_attr3 = 1;
3806 }
3807 }
3808
3809 // At end of the text line or just after the last character.
3810 if ((c == NUL
3811#if defined(LINE_ATTR)
3812 || did_line_attr == 1
3813#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003814 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815 {
3816#ifdef FEAT_SEARCH_EXTRA
3817 // flag to indicate whether prevcol equals startcol of search_hl or
3818 // one of the matches
3819 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3820 (long)(ptr - line) - (c == NUL));
3821#endif
3822 // Invert at least one char, used for Visual and empty line or
3823 // highlight match at end of line. If it's beyond the last
3824 // char on the screen, just overwrite that one (tricky!) Not
3825 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003826 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003827 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828 && (VIsual_mode != Ctrl_V
3829 || lnum == VIsual.lnum
3830 || lnum == curwin->w_cursor.lnum)
3831 && c == NUL)
3832#ifdef FEAT_SEARCH_EXTRA
3833 // highlight 'hlsearch' match at end of line
3834 || (prevcol_hl_flag
3835# ifdef FEAT_SYN_HL
3836 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3837 && !(wp == curwin && VIsual_active))
3838# endif
3839# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003840 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003841# endif
3842# if defined(LINE_ATTR)
3843 && did_line_attr <= 1
3844# endif
3845 )
3846#endif
3847 ))
3848 {
3849 int n = 0;
3850
3851#ifdef FEAT_RIGHTLEFT
3852 if (wp->w_p_rl)
3853 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003854 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003855 n = 1;
3856 }
3857 else
3858#endif
3859 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003860 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861 n = -1;
3862 }
3863 if (n != 0)
3864 {
3865 // At the window boundary, highlight the last character
3866 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003867 wlv.off += n;
3868 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003869 }
3870 else
3871 {
3872 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003873 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003874 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003875 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876 }
3877#ifdef FEAT_SEARCH_EXTRA
3878 if (area_attr == 0)
3879 {
3880 // Use attributes from match with highest priority among
3881 // 'search_hl' and the match list.
3882 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003883 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003884 }
3885#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003886 ScreenAttrs[wlv.off] = wlv.char_attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01003887 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003888#ifdef FEAT_RIGHTLEFT
3889 if (wp->w_p_rl)
3890 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003891 --wlv.col;
3892 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003893 }
3894 else
3895#endif
3896 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003897 ++wlv.col;
3898 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003899 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003900 ++wlv.vcol;
3901 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003902 }
3903 }
3904
3905 // At end of the text line.
3906 if (c == NUL)
3907 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003908#ifdef FEAT_PROP_POPUP
3909 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003910 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003911 // Put the pointer back to the NUL.
3912 --ptr;
3913 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003915 else
3916#endif
3917 {
3918 draw_screen_line(wp, &wlv);
3919
3920 // Update w_cline_height and w_cline_folded if the cursor line
3921 // was updated (saves a call to plines() later).
zeertzjqf4ccada2024-12-17 20:50:19 +01003922 if (in_curline)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003923 {
3924 curwin->w_cline_row = startrow;
3925 curwin->w_cline_height = wlv.row - startrow;
3926#ifdef FEAT_FOLDING
3927 curwin->w_cline_folded = FALSE;
3928#endif
3929 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3930 }
3931 break;
3932 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003933 }
3934
3935 // Show "extends" character from 'listchars' if beyond the line end and
3936 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003937 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003938 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003939 && wp->w_p_list
3940 && !wp->w_p_wrap
3941#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003942 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943#endif
3944 && (
3945#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003946 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003947#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003948 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003949 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003950 || lcs_eol_one > 0
3951 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003952 || *wlv.p_extra != NUL))
3953#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003954 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003955#endif
3956 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003957 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003958 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003959 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960 mb_c = c;
3961 if (enc_utf8 && utf_char2len(c) > 1)
3962 {
3963 mb_utf8 = TRUE;
3964 u8cc[0] = 0;
3965 c = 0xc0;
3966 }
3967 else
3968 mb_utf8 = FALSE;
3969 }
3970
3971#ifdef FEAT_SYN_HL
3972 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003973 if (wlv.draw_color_col)
3974 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003975
3976 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3977 // highlight the cursor position itself.
3978 // Also highlight the 'colorcolumn' if it is different than
3979 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003980 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3981 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003982 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003983 if (((wlv.draw_state == WL_LINE
3984 || wlv.draw_state == WL_BRI
3985 || wlv.draw_state == WL_SBR)
3986 && !lnum_in_visual_area
3987 && search_attr == 0
3988 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003989# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003990 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003991# endif
3992 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993 {
3994 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3995 && lnum != wp->w_cursor.lnum)
3996 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003997 vcol_save_attr = wlv.char_attr;
3998 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3999 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004000 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004001 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004002 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004003 vcol_save_attr = wlv.char_attr;
4004 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004005 }
4006 }
4007#endif
4008
zeertzjq8fc6a1d2023-08-20 18:12:54 +02004009 if (wlv.draw_state == WL_LINE)
4010 vcol_prev = wlv.vcol;
4011
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004012 // Store character to be displayed.
4013 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02004014 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004015 {
4016 // Store the character.
4017#if defined(FEAT_RIGHTLEFT)
4018 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
4019 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00004020 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004021 --wlv.off;
4022 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004023 }
4024#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004025 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004026 if (enc_dbcs == DBCS_JPNU)
4027 {
4028 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004029 ScreenLines[wlv.off] = 0x8e;
4030 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004031 }
4032 else if (enc_utf8)
4033 {
4034 if (mb_utf8)
4035 {
4036 int i;
4037
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004038 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004039 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004040 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004041 for (i = 0; i < Screen_mco; ++i)
4042 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004043 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004044 if (u8cc[i] == 0)
4045 break;
4046 }
4047 }
4048 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004049 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004050 }
4051 if (multi_attr)
4052 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004053 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004054 multi_attr = 0;
4055 }
4056 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01004057 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004058
zeertzjqdb54e982023-09-21 16:33:09 +02004059 if (wlv.draw_state > WL_NR
4060#ifdef FEAT_DIFF
4061 && wlv.filler_todo <= 0
4062#endif
4063 )
4064 ScreenCols[wlv.off] = wlv.vcol;
4065 else
4066 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01004067
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004068 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4069 {
4070 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004071 ++wlv.off;
4072 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004073 if (enc_utf8)
4074 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004075 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004076 else
4077 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004078 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02004079
Bram Moolenaar1306b362022-08-06 15:59:06 +01004080 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004081#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004082 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004083#endif
4084 )
zeertzjqdb54e982023-09-21 16:33:09 +02004085 ScreenCols[wlv.off] = ++wlv.vcol;
4086 else
4087 ScreenCols[wlv.off] = -1;
4088
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004089 // When "wlv.tocol" is halfway a character, set it to the end
4090 // of the character, otherwise highlighting won't stop.
4091 if (wlv.tocol == wlv.vcol)
4092 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01004093
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004094#ifdef FEAT_RIGHTLEFT
4095 if (wp->w_p_rl)
4096 {
4097 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004098 --wlv.off;
4099 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004100 }
4101#endif
4102 }
4103#ifdef FEAT_RIGHTLEFT
4104 if (wp->w_p_rl)
4105 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004106 --wlv.off;
4107 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004108 }
4109 else
4110#endif
4111 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004112 ++wlv.off;
4113 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004114 }
4115 }
4116#ifdef FEAT_CONCEAL
4117 else if (wp->w_p_cole > 0 && is_concealing)
4118 {
zeertzjq010e1532024-03-14 18:22:17 +01004119 int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1;
4120
zeertzjqb557f482023-08-22 22:07:34 +02004121 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004122 ++wlv.vcol_off_co;
zeertzjq010e1532024-03-14 18:22:17 +01004123 if (concealed_wide)
4124 {
4125 // When a double-width char is concealed,
4126 // need to advance one more virtual column.
4127 ++wlv.vcol;
4128 ++wlv.vcol_off_co;
4129 }
4130
Bram Moolenaar1306b362022-08-06 15:59:06 +01004131 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004132 wlv.vcol_off_co += wlv.n_extra;
zeertzjq010e1532024-03-14 18:22:17 +01004133
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004134 if (wp->w_p_wrap)
4135 {
4136 // Special voodoo required if 'wrap' is on.
4137 //
4138 // Advance the column indicator to force the line
4139 // drawing to wrap early. This will make the line
4140 // take up the same screen space when parts are concealed,
4141 // so that cursor line computations aren't messed up.
4142 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004143 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004144 // trailing junk to be written out of the screen line
4145 // we are building, 'boguscols' keeps track of the number
4146 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004147 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004148 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004149 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004150# ifdef FEAT_RIGHTLEFT
4151 if (wp->w_p_rl)
4152 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004153 wlv.col -= wlv.n_extra;
4154 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004155 }
4156 else
4157# endif
4158 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004159 wlv.col += wlv.n_extra;
4160 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004161 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004162 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004163 n_attr = 0;
4164 }
4165
zeertzjq010e1532024-03-14 18:22:17 +01004166 if (concealed_wide)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004167 {
4168 // Need to fill two screen columns.
4169# ifdef FEAT_RIGHTLEFT
4170 if (wp->w_p_rl)
4171 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004172 --wlv.boguscols;
4173 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004174 }
4175 else
4176# endif
4177 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004178 ++wlv.boguscols;
4179 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004180 }
4181 }
4182
4183# ifdef FEAT_RIGHTLEFT
4184 if (wp->w_p_rl)
4185 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004186 --wlv.boguscols;
4187 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004188 }
4189 else
4190# endif
4191 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004192 ++wlv.boguscols;
4193 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004194 }
4195 }
4196 else
4197 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004198 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004199 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004200 wlv.vcol += wlv.n_extra;
4201 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004202 n_attr = 0;
4203 }
4204 }
4205
4206 }
4207#endif // FEAT_CONCEAL
4208 else
zeertzjqb557f482023-08-22 22:07:34 +02004209 --skip_cells;
4210
4211 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4212 {
4213 wlv.vcol += skipped_cells;
4214 skipped_cells = 0;
4215 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004216
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004217 // Only advance the "wlv.vcol" when after the 'number' or
4218 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004219 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004220#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004221 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004222#endif
4223 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004224 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004225
4226#ifdef FEAT_SYN_HL
4227 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004228 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004229#endif
4230
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004231 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004232 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4233 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004234
4235 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004236 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004237 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004238 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004239 if (wlv.n_attr_skip > 0)
4240 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004241
4242 // At end of screen line and there is more to come: Display the line
4243 // so far. If there is no more to display it is caught above.
4244 if ((
4245#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004246 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004247#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004248 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004249 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004250 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004251#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004252 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004253#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004254#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004255 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004256 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004257#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004258 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004259 && lcs_eol_one != -1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004260 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4261 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004262 )
4263 {
4264#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004265 wlv.col -= wlv.boguscols;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004266 // Apply 'cursorline' and 'wincolor' highlight.
4267 if (wlv.boguscols != 0 && (
4268# ifdef LINE_ATTR
4269 wlv.line_attr != 0 ||
4270# endif
4271 wlv.win_attr != 0
4272 )
4273 )
4274 {
4275 int attr = wlv.win_attr;
4276# ifdef LINE_ATTR
4277 if (wlv.line_attr != 0)
4278 attr = hl_combine_attr(attr, wlv.line_attr);
4279# endif
4280 while ((
4281# ifdef FEAT_RIGHTLEFT
4282 wp->w_p_rl ? wlv.col >= 0 :
4283# endif
4284 wlv.col < wp->w_width))
4285 {
4286 ScreenLines[wlv.off] = ' ';
4287 if (enc_utf8)
4288 ScreenLinesUC[wlv.off] = 0;
4289 ScreenAttrs[wlv.off] = attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01004290 ScreenCols[wlv.off] = wlv.vcol - 1;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004291# ifdef FEAT_RIGHTLEFT
4292 if (wp->w_p_rl)
4293 {
4294 wlv.off--;
4295 wlv.col--;
4296 wlv.boguscols++;
4297 }
4298 else
4299# endif
4300 {
4301 wlv.off++;
4302 wlv.col++;
4303 wlv.boguscols--;
4304 }
4305 }
4306 }
zeertzjqd0c1b772024-03-16 15:03:33 +01004307 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar75008662022-10-04 22:40:56 +01004308 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004309 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004310 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004311#else
zeertzjqd0c1b772024-03-16 15:03:33 +01004312 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004313#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004314 ++wlv.row;
4315 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004316
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004317 // When not wrapping and finished diff lines, break here.
4318 if (!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004319#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004320 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004321#endif
4322#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004323 && !text_prop_above
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004324 && !text_prop_follows
Bram Moolenaar877151b2022-10-11 15:29:50 +01004325#endif
4326 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004327 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004328#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004329 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004330 {
4331 // do not output more of the line, only the "below" prop
John Marriottf51ff962024-06-02 19:44:11 +02004332 ptr = line + (size_t)ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004333# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004334 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004335# endif
4336 }
4337#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004338
4339 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004340 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004341#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004342 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004343#endif
4344 )
4345 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004346 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4347 draw_vsep_win(wp, wlv.row);
4348 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004349 }
4350
4351 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004352 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004353 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004354 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004355 break;
4356 }
4357
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004358 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004359#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004360 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004361#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004362#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004363 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004364#endif
Hirohito Higashi3b9b95d2025-06-01 20:22:55 +02004365 && wp->w_width == Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004366 {
4367 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004368 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004369
4370 // Special trick to make copy/paste of wrapped lines work with
4371 // xterm/screen: write an extra character beyond the end of
4372 // the line. This will work with all terminal types
4373 // (regardless of the xn,am settings).
4374 // Only do this on a fast tty.
4375 // Only do this if the cursor is on the current line
4376 // (something has been written in it).
4377 // Don't do this for the GUI.
4378 // Don't do this for double-width characters.
4379 // Don't do this for a window not at the right screen border.
4380 if (p_tf
4381#ifdef FEAT_GUI
4382 && !gui.in_use
4383#endif
4384 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004385 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4386 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004387 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004388 || (*mb_off2cells)(
4389 LineOffset[wlv.screen_row - 1]
Hirohito Higashi3b9b95d2025-06-01 20:22:55 +02004390 + (int)topframe->fr_width - 2,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004391 LineOffset[wlv.screen_row]
4392 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004393 {
4394 // First make sure we are at the end of the screen line,
4395 // then output the same character again to let the
4396 // terminal know about the wrap. If the terminal doesn't
4397 // auto-wrap, we overwrite the character.
4398 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004399 screen_char(LineOffset[wlv.screen_row - 1]
Hirohito Higashi3b9b95d2025-06-01 20:22:55 +02004400 + (unsigned)topframe->fr_width - 1,
4401 wlv.screen_row - 1, (int)(topframe->fr_width - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004402
4403 // When there is a multi-byte character, just output a
4404 // space to keep it simple.
4405 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Hirohito Higashi3b9b95d2025-06-01 20:22:55 +02004406 wlv.screen_row - 1] + (topframe->fr_width - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004407 out_char(' ');
4408 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004409 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Hirohito Higashi3b9b95d2025-06-01 20:22:55 +02004410 + (topframe->fr_width - 1)]);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004411 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004412 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004413 screen_start(); // don't know where cursor is now
4414 }
4415 }
4416
Bram Moolenaar1306b362022-08-06 15:59:06 +01004417 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004418
Bram Moolenaareed9d462021-02-15 20:38:25 +01004419 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004420#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004421 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004422# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004423 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004424# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004425 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004426 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004427#endif
4428#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004429 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004430 // When the filler lines are actually below the last line of the
4431 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004432 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004433 break;
4434#endif
4435 }
4436
4437 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004438#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004439 vim_free(text_props);
4440 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004441 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004442#endif
4443
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004444 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004445 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004446 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004447}