blob: a14dd906225fbd6dd2f3586c2a909df6cc34c4c0 [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.
391 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
392 get_sign_display_info(TRUE, wp, wlv);
393 else
394#endif
395 {
396 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100397 // When there are text properties above the line put the line number
398 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100399 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100400 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100401 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100402 {
403 long num;
404 char *fmt = "%*ld ";
405
406 if (wp->w_p_nu && !wp->w_p_rnu)
407 // 'number' + 'norelativenumber'
408 num = (long)wlv->lnum;
409 else
410 {
411 // 'relativenumber', don't use negative numbers
412 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
413 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
414 {
415 // 'number' + 'relativenumber'
416 num = wlv->lnum;
417 fmt = "%-*ld ";
418 }
419 }
420
John Marriottf51ff962024-06-02 19:44:11 +0200421 vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100422 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100423 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
424 ++wlv->p_extra)
425 *wlv->p_extra = '-';
426#ifdef FEAT_RIGHTLEFT
427 if (wp->w_p_rl) // reverse line numbers
428 {
429 char_u *p1, *p2;
430 int t;
431
432 // like rl_mirror(), but keep the space at the end
433 p2 = skipwhite(wlv->extra);
434 p2 = skiptowhite(p2) - 1;
435 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
436 {
437 t = *p1;
438 *p1 = *p2;
439 *p2 = t;
440 }
441 }
442#endif
443 wlv->p_extra = wlv->extra;
444 wlv->c_extra = NUL;
445 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100446 }
447 else
448 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100449 wlv->c_extra = ' ';
450 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100451 }
452 wlv->n_extra = number_width(wp) + 1;
453 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
454#ifdef FEAT_SYN_HL
455 // When 'cursorline' is set highlight the line number of
456 // the current line differently.
457 // When 'cursorlineopt' does not have "line" only
458 // highlight the line number itself.
459 // TODO: Can we use CursorLine instead of CursorLineNr
460 // when CursorLineNr isn't set?
461 if (wp->w_p_cul
462 && wlv->lnum == wp->w_cursor.lnum
463 && (wp->w_p_culopt_flags & CULOPT_NBR)
zeertzjq62f19542025-03-08 16:27:37 +0100464 && (wlv->row == lnum_row
465 || (wlv->row > lnum_row
Bram Moolenaard7657e92022-09-20 18:59:30 +0100466 && (wp->w_p_culopt_flags & CULOPT_LINE))))
467 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
468#endif
469 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
470 && HL_ATTR(HLF_LNA) != 0)
471 // Use LineNrAbove
472 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
473 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
474 && HL_ATTR(HLF_LNB) != 0)
475 // Use LineNrBelow
476 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
477 }
478#ifdef FEAT_SIGNS
479 if (num_attr)
480 wlv->char_attr = num_attr;
481#endif
482 }
483}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100484
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100485#ifdef FEAT_LINEBREAK
486 static void
487handle_breakindent(win_T *wp, winlinevars_T *wlv)
488{
489 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100490 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100491 // draw indent after showbreak value
492 wlv->draw_state = WL_BRI;
493 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
494 // After the showbreak, draw the breakindent
495 wlv->draw_state = WL_BRI - 1;
496
497 // draw 'breakindent': indent wrapped text accordingly
498 if (wlv->draw_state == WL_BRI - 1)
499 {
500 wlv->draw_state = WL_BRI;
501 // if wlv->need_showbreak is set, breakindent also applies
zeertzjq588f20d2023-12-05 15:47:09 +0100502 if (wp->w_p_bri && (wlv->row > wlv->startrow
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100503# ifdef FEAT_DIFF
zeertzjq588f20d2023-12-05 15:47:09 +0100504 + wlv->filler_lines
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100505# endif
zeertzjq588f20d2023-12-05 15:47:09 +0100506 || wlv->need_showbreak)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100507# ifdef FEAT_PROP_POPUP
508 && !wlv->dont_use_showbreak
509# endif
510 )
511 {
512 wlv->char_attr = 0;
513# ifdef FEAT_DIFF
514 if (wlv->diff_hlf != (hlf_T)0)
515 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
516# endif
517 wlv->p_extra = NULL;
518 wlv->c_extra = ' ';
519 wlv->c_final = NUL;
520 wlv->n_extra = get_breakindent_win(wp,
521 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
522 if (wlv->row == wlv->startrow)
523 {
524 wlv->n_extra -= win_col_off2(wp);
525 if (wlv->n_extra < 0)
526 wlv->n_extra = 0;
527 }
zeertzjq23627722023-12-27 19:08:53 +0100528
529 // Correct start of highlighted area for 'breakindent',
530 if (wlv->fromcol >= wlv->vcol
531 && wlv->fromcol < wlv->vcol + wlv->n_extra)
532 wlv->fromcol = wlv->vcol + wlv->n_extra;
533
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100534 // Correct end of highlighted area for 'breakindent',
535 // required when 'linebreak' is also set.
536 if (wlv->tocol == wlv->vcol)
537 wlv->tocol += wlv->n_extra;
538 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100539
540 if (wp->w_skipcol > 0 && wlv->startrow == 0 && wp->w_p_wrap
541 && wp->w_briopt_sbr)
542 wlv->need_showbreak = FALSE;
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100543 }
544}
545#endif
546
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100547#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
548 static void
549handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
550{
551# ifdef FEAT_DIFF
552 if (wlv->filler_todo > 0)
553 {
554 // Draw "deleted" diff line(s).
555 if (char2cells(wp->w_fill_chars.diff) > 1)
556 {
557 wlv->c_extra = '-';
558 wlv->c_final = NUL;
559 }
560 else
561 {
562 wlv->c_extra = wp->w_fill_chars.diff;
563 wlv->c_final = NUL;
564 }
565# ifdef FEAT_RIGHTLEFT
566 if (wp->w_p_rl)
567 wlv->n_extra = wlv->col + 1;
568 else
569# endif
570 wlv->n_extra = wp->w_width - wlv->col;
571 wlv->char_attr = HL_ATTR(HLF_DED);
572 }
573# endif
574
575# ifdef FEAT_LINEBREAK
576 char_u *sbr = get_showbreak_value(wp);
577 if (*sbr != NUL && wlv->need_showbreak)
578 {
579 // Draw 'showbreak' at the start of each broken line.
580 wlv->p_extra = sbr;
581 wlv->c_extra = NUL;
582 wlv->c_final = NUL;
583 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100584 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100585
586 // Correct start of highlighted area for 'showbreak'.
587 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
588 wlv->fromcol = wlv->vcol_sbr;
589
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100590 // Correct end of highlighted area for 'showbreak',
591 // required when 'linebreak' is also set.
592 if (wlv->tocol == wlv->vcol)
zeertzjqdf23d7f2024-02-09 18:14:12 +0100593 wlv->tocol = wlv->vcol_sbr;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100594 // combine 'showbreak' with 'wincolor'
595 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
596# ifdef FEAT_SYN_HL
597 // combine 'showbreak' with 'cursorline'
598 if (wlv->cul_attr != 0)
599 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
600# endif
601 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100602
603 if (wp->w_skipcol == 0 || wlv->startrow > 0 || !wp->w_p_wrap
604 || !wp->w_briopt_sbr)
605 wlv->need_showbreak = FALSE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100606# endif
607}
608#endif
609
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100610#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100611/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100612 * Return the cell size of virtual text after truncation.
613 */
614 static int
615textprop_size_after_trunc(
616 win_T *wp,
617 int flags, // TP_FLAG_ALIGN_*
618 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100619 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100620 char_u *text,
621 int *n_used_ptr)
622{
623 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100624 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100625 int strsize = 0;
John Marriottf51ff962024-06-02 19:44:11 +0200626 char_u *p;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100627
John Marriottf51ff962024-06-02 19:44:11 +0200628 // if the remaining size is too small and 'wrap' is set we wrap anyway and
Bram Moolenaar7e017462022-10-11 21:02:09 +0100629 // use the next line
630 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100632 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100633 space -= padding;
John Marriottf51ff962024-06-02 19:44:11 +0200634
635 for (p = text; *p != NUL; p += (*mb_ptr2len)(p))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100636 {
John Marriottf51ff962024-06-02 19:44:11 +0200637 int clen = ptr2cells(p);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100638
639 if (strsize + clen > space)
640 break;
641 strsize += clen;
642 }
John Marriottf51ff962024-06-02 19:44:11 +0200643 *n_used_ptr = (int)(p - text);
644
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100645 return strsize;
646}
647
648/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100649 * Take care of padding, right-align and truncation of virtual text after a
650 * line.
651 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
652 * padding, right-align and truncation. Otherwise only the size is computed.
653 * When "n_attr" is NULL returns the number of screen cells used.
654 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100655 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100656 int
657text_prop_position(
658 win_T *wp,
659 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000660 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100661 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100662 int *n_extra, // nr of bytes for virtual text
663 char_u **p_extra, // virtual text
664 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000665 int *n_attr_skip, // cells to skip attr, NULL if not used
666 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200667{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100669 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100670 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000671 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100672 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000673 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100674 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100675 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100676 int before = room; // spaces before the text
677 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100678 int n_used = *n_extra;
679 char_u *l = NULL;
680 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100681 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100682 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200683
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100684 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100685 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100686 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100687
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100688 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100689 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100690 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100691 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100692 if (after < 0)
693 {
694 // text "above" has too much padding to fit
695 padding += after;
696 after = 0;
697 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100698 }
699 else
700 {
701 // Right-align: fill with before
702 if (right)
703 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000704
705 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000706 if (below && vcol == 0 && col_with_padding == col_off
707 && wp->w_width - col_off == before)
708 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000709
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100710 if (before < 0
711 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000712 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
713 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100714 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100715 if (right && (wrap
716 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100717 {
718 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100719 before = wp->w_width - col_off - strsize + room;
720 if (before < 0)
721 before = 0;
722 else
723 n_used = *n_extra;
724 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000725 else if (below && before > vcol && do_skip)
726 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100728 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100729 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100731
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100732 // With 'nowrap' add one to show the "extends" character if needed (it
733 // doesn't show if the text just fits).
734 if (!wp->w_p_wrap
735 && n_used < *n_extra
736 && wp->w_lcs_chars.ext != NUL
737 && wp->w_p_list)
738 ++n_used;
739
740 // add 1 for NUL, 2 for when '…' is used
741 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200742 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100743 if (n_attr == NULL || l != NULL)
744 {
745 int off = 0;
746
747 if (n_attr != NULL)
748 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100749 vim_memset(l, ' ', before);
750 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100751 if (padding > 0)
752 {
753 vim_memset(l + off, ' ', padding);
754 off += padding;
755 }
756 vim_strncpy(l + off, *p_extra, n_used);
757 off += n_used;
758 }
759 else
760 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100761 off = before + after + padding + n_used;
762 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100763 }
764 if (n_attr != NULL)
765 {
766 if (n_used < *n_extra && wp->w_p_wrap)
767 {
768 char_u *lp = l + off - 1;
769
770 if (has_mbyte)
771 {
h-east4c42c7e2023-04-17 21:44:57 +0100772 char_u buf[MB_MAXBYTES + 1];
773 char_u *cp = buf;
774
775 // change the last character to '…', converted to the
776 // current 'encoding'
777 STRCPY(buf, "…");
778 if (!enc_utf8)
779 {
780 vimconv_T vc;
781
782 vc.vc_type = CONV_NONE;
783 convert_setup(&vc, (char_u *)"utf-8", p_enc);
784 if (vc.vc_type != CONV_NONE)
785 {
786 cp = string_convert(&vc, buf, NULL);
787 if (cp == NULL)
788 {
789 // when conversion fails use '>'
790 cp = buf;
791 STRCPY(buf, ">");
792 }
793 convert_setup(&vc, NULL, NULL);
794 }
795 }
796
797 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100798 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100799 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100800 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100801 if (cp != buf)
802 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100803 }
804 else
805 // change last character to '>'
806 *lp = '>';
807 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100808 else if (after > 0)
809 {
810 vim_memset(l + off, ' ', after);
811 l[off + after] = NUL;
812 }
813
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100814 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100815 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100816 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000817 // n_attr_skip will not be decremented before draw_state is
818 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200819 *n_attr_skip = before + (padding > 0 ? padding : 0);
zeertzjq9352c282024-03-14 18:16:56 +0100820 *n_attr -= *n_attr_skip;
821 if (above)
822 *n_attr -= after;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100823 }
824 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100825 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100826
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100827 if (n_attr == NULL)
828 return cells;
829 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200830}
831#endif
832
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100833/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100834 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100835 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
836 * when 'showbreak' is not set.
zeertzjqd0c1b772024-03-16 15:03:33 +0100837 * When "clear_end" is TRUE clear until the end of the screen line.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100838 */
839 static void
zeertzjqd0c1b772024-03-16 15:03:33 +0100840wlv_screen_line(win_T *wp, winlinevars_T *wlv, int clear_end)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100841{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100842 if (wlv->row == 0 && wp->w_skipcol > 0
843#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100844 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100845 && *get_showbreak_value(wp) == NUL
846#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100847 // do not overwrite the 'listchars' "precedes" text with "<<<"
848 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100849 {
850 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100851 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100852 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100853
Bram Moolenaareb4de622022-10-15 13:42:17 +0100854 if (wp->w_p_nu && wp->w_p_rnu)
855 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100856 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100857 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
858 {
859 ++off;
860 ++skip;
861 }
862
863 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100864 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100865 if ((*mb_off2cells)(off, max_off) > 1)
866 // When the first half of a double-width character is
867 // overwritten, change the second half to a space.
868 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100869 ScreenLines[off] = '<';
870 if (enc_utf8)
871 ScreenLinesUC[off] = 0;
872 ScreenAttrs[off] = HL_ATTR(HLF_AT);
873 ++off;
874 }
875 }
876
877 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
zeertzjqd0c1b772024-03-16 15:03:33 +0100878 clear_end ? wp->w_width : -wp->w_width,
879 wlv->vcol - 1, wlv->screen_line_flags);
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100880}
881
882/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100883 * Called when finished with the line: draw the screen line and handle any
884 * highlighting until the right of the window.
885 */
886 static void
887draw_screen_line(win_T *wp, winlinevars_T *wlv)
888{
889#ifdef FEAT_SYN_HL
890 long v;
zeertzjqf6272552024-03-17 10:01:47 +0100891 int wcol;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100892
893 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
894 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100895 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100896 else
897 v = wp->w_leftcol;
898
zeertzjqf6272552024-03-17 10:01:47 +0100899 wcol =
900# ifdef FEAT_RIGHTLEFT
901 wp->w_p_rl ? wp->w_width - wlv->col - 1 :
902# endif
903 wlv->col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100904 // check if line ends before left margin
zeertzjqf6272552024-03-17 10:01:47 +0100905 if (wlv->vcol < v + wcol - win_col_off(wp))
906 wlv->vcol = v + wcol - win_col_off(wp);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100907# ifdef FEAT_CONCEAL
908 // Get rid of the boguscols now, we want to draw until the right
909 // edge for 'cursorcolumn'.
910 wlv->col -= wlv->boguscols;
911 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000912# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100913# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000914# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100915# endif
916
917 if (wlv->draw_color_col)
918 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
919
920 if (((wp->w_p_cuc
921 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
922 && (int)wp->w_virtcol <
923 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
924 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000925 || wlv->draw_color_col
926# ifdef LINE_ATTR
927 || wlv->line_attr != 0
928# endif
zeertzjqf6272552024-03-17 10:01:47 +0100929 || wlv->win_attr != 0))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100930 {
931 int rightmost_vcol = 0;
932 int i;
933
934 if (wp->w_p_cuc)
935 rightmost_vcol = wp->w_virtcol;
936 if (wlv->draw_color_col)
937 // determine rightmost colorcolumn to possibly draw
938 for (i = 0; wlv->color_cols[i] >= 0; ++i)
939 if (rightmost_vcol < wlv->color_cols[i])
940 rightmost_vcol = wlv->color_cols[i];
941
zeertzjqf6272552024-03-17 10:01:47 +0100942 while (
943# ifdef FEAT_RIGHTLEFT
944 wp->w_p_rl ? (wlv->col >= 0) :
945# endif
946 (wlv->col < wp->w_width))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100947 {
948 ScreenLines[wlv->off] = ' ';
949 if (enc_utf8)
950 ScreenLinesUC[wlv->off] = 0;
zeertzjqf6272552024-03-17 10:01:47 +0100951
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100952 if (wlv->draw_color_col)
953 wlv->draw_color_col = advance_color_col(
954 VCOL_HLC, &wlv->color_cols);
955
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000956 int attr = wlv->win_attr;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000957# ifdef LINE_ATTR
zeertzjq9352c282024-03-14 18:16:56 +0100958 if (wlv->line_attr != 0)
959 attr = hl_combine_attr(attr, wlv->line_attr);
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000960# endif
zeertzjq9352c282024-03-14 18:16:56 +0100961 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
962 && wlv->lnum != wp->w_cursor.lnum)
963 attr = hl_combine_attr(attr, HL_ATTR(HLF_CUC));
964 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
965 attr = hl_combine_attr(attr, HL_ATTR(HLF_MC));
zeertzjqf6272552024-03-17 10:01:47 +0100966 ScreenAttrs[wlv->off] = attr;
967 ScreenCols[wlv->off] = wlv->vcol;
968# ifdef FEAT_RIGHTLEFT
969 if (wp->w_p_rl)
970 {
971 --wlv->off;
972 --wlv->col;
973 }
974 else
975# endif
976 {
977 ++wlv->off;
978 ++wlv->col;
979 }
zeertzjqdeb22042024-03-17 19:44:30 +0100980 ++wlv->vcol;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100981
zeertzjqdeb22042024-03-17 19:44:30 +0100982 if (VCOL_HLC > rightmost_vcol
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000983# ifdef LINE_ATTR
984 && wlv->line_attr == 0
985# endif
986 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100987 break;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100988 }
989 }
990#endif
991
zeertzjqd0c1b772024-03-16 15:03:33 +0100992 // Set increasing virtual columns in ScreenCols[] to set correct curswant
993 // (or "coladd" for 'virtualedit') when clicking after end of line.
994 wlv->screen_line_flags |= SLF_INC_VCOL;
995 wlv_screen_line(wp, wlv, TRUE);
996 wlv->screen_line_flags &= ~SLF_INC_VCOL;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100997 ++wlv->row;
998 ++wlv->screen_row;
999}
1000#undef VCOL_HLC
1001
1002/*
1003 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001004 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001005 */
1006 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +01001007win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001008{
1009 wlv->col = 0;
1010 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001011#ifdef FEAT_LINEBREAK
1012 wlv->need_lbr = FALSE;
1013#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001014
1015#ifdef FEAT_RIGHTLEFT
1016 if (wp->w_p_rl)
1017 {
1018 // Rightleft window: process the text in the normal direction, but put
1019 // it in current_ScreenLine[] from right to left. Start at the
1020 // rightmost column of the window.
1021 wlv->col = wp->w_width - 1;
1022 wlv->off += wlv->col;
1023 wlv->screen_line_flags |= SLF_RIGHTLEFT;
1024 }
1025#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001026 if (save_extra)
1027 {
1028 // reset the drawing state for the start of a wrapped line
1029 wlv->draw_state = WL_START;
1030 wlv->saved_n_extra = wlv->n_extra;
1031 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001032 vim_free(wlv->saved_p_extra_free);
1033 wlv->saved_p_extra_free = wlv->p_extra_free;
1034 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001035 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001036 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001037 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001038 wlv->saved_c_extra = wlv->c_extra;
1039 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001040#ifdef FEAT_LINEBREAK
1041 wlv->need_lbr = TRUE;
1042#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001043#ifdef FEAT_SYN_HL
1044 if (!(wlv->cul_screenline
1045# ifdef FEAT_DIFF
1046 && wlv->diff_hlf == (hlf_T)0
1047# endif
1048 ))
1049 wlv->saved_char_attr = wlv->char_attr;
1050 else
1051#endif
1052 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001053
1054 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001055 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001056 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001057 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001058}
1059
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001060/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001061 * Called when wlv->draw_state is set to WL_LINE.
1062 */
1063 static void
1064win_line_continue(winlinevars_T *wlv)
1065{
1066 if (wlv->saved_n_extra > 0)
1067 {
1068 // Continue item from end of wrapped line.
1069 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001070 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001071 wlv->c_extra = wlv->saved_c_extra;
1072 wlv->c_final = wlv->saved_c_final;
1073 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001074 vim_free(wlv->p_extra_free);
1075 wlv->p_extra_free = wlv->saved_p_extra_free;
1076 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001077 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001078 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001079 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001080 wlv->char_attr = wlv->saved_char_attr;
1081 }
1082 else
1083 wlv->char_attr = wlv->win_attr;
1084}
1085
zeertzjqb7acea12022-12-12 13:20:43 +00001086#ifdef FEAT_SYN_HL
1087 static void
1088apply_cursorline_highlight(
1089 winlinevars_T *wlv,
1090 int sign_present UNUSED)
1091{
1092 wlv->cul_attr = HL_ATTR(HLF_CUL);
1093# ifdef FEAT_SIGNS
1094 // Combine the 'cursorline' and sign highlighting, depending on
1095 // the sign priority.
1096 if (sign_present && wlv->sattr.sat_linehl > 0)
1097 {
1098 if (wlv->sattr.sat_priority >= 100)
1099 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1100 else
1101 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1102 }
1103 else
1104# endif
1105# if defined(FEAT_QUICKFIX)
1106 // let the line attribute overrule 'cursorline', otherwise
1107 // it disappears when both have background set;
1108 // 'cursorline' can use underline or bold to make it show
1109 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1110# else
1111 wlv->line_attr = wlv->cul_attr;
1112# endif
1113}
1114#endif
1115
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001116/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001117 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001118 * Start at row "startrow", stop when "endrow" is reached.
zeertzjqebfd8562024-02-06 10:59:03 +01001119 * When only updating the number column, "number_only" is set to the height of
1120 * the line, otherwise it is set to 0.
Luuk van Baal30805a12023-05-27 22:22:10 +01001121 * "spv" is used to store information for spell checking, kept between
1122 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123 * wp->w_virtcol needs to be valid.
1124 *
1125 * Return the number of last row the line occupies.
1126 */
1127 int
1128win_line(
1129 win_T *wp,
1130 linenr_T lnum,
1131 int startrow,
1132 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001133 int number_only,
1134 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001136 winlinevars_T wlv; // variables passed between functions
1137
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001139 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140 char_u *line; // current line
1141 char_u *ptr; // current position in "line"
glepnir6a38aff2024-12-16 21:56:16 +01001142 int in_curline = wp == curwin && lnum == curwin->w_cursor.lnum;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143
Bram Moolenaar1306b362022-08-06 15:59:06 +01001144#ifdef FEAT_PROP_POPUP
1145 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1146#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001147#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001148 int in_linebreak = FALSE; // n_extra set for showing linebreak
1149#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01001150 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001151 int lcs_prec_todo = wp->w_lcs_chars.prec;
1152 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001154 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001155 int saved_attr2 = 0; // char_attr saved for n_attr
1156 int n_attr3 = 0; // chars with overruling special attr
1157 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158
zeertzjqb557f482023-08-22 22:07:34 +02001159 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1160 // w_skipcol or concealing
1161 int skipped_cells = 0; // nr of skipped cells for virtual text
1162 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163 int fromcol_prev = -2; // start of inverting after cursor
1164 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001165 int lnum_in_visual_area = FALSE;
1166 pos_T pos;
1167 long v;
1168
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169 int attr_pri = FALSE; // char_attr has priority
1170 int area_highlighting = FALSE; // Visual or incsearch highlighting
1171 // in this line
1172 int vi_attr = 0; // attributes for Visual and incsearch
1173 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001174 int area_attr = 0; // attributes desired by highlighting
zeertzjqf25d8f92024-12-18 21:12:25 +01001175 int search_attr = 0; // attributes desired by 'hlsearch' or
1176 // ComplMatchIns
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001177#ifdef FEAT_SYN_HL
1178 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1179 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001180 int prev_syntax_col = -1; // column of prev_syntax_attr
1181 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001182 int has_syntax = FALSE; // this buffer has syntax highl.
1183 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001184#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001185#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001186 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001187 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001188 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 int text_prop_next = 0; // next text property to use
1190 textprop_T *text_props = NULL;
1191 int *text_prop_idxs = NULL;
1192 int text_props_active = 0;
1193 proptype_T *text_prop_type = NULL;
1194 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001195 int text_prop_attr_comb = 0; // text_prop_attr combined with
1196 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001197 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001198 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001199 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001200 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001201 int saved_search_attr = 0; // search_attr to be used when n_extra
1202 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001203 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001204 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001205#endif
1206#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001207 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208# define SPWORDLEN 150
1209 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1210 int nextlinecol = 0; // column where nextline[] starts
1211 int nextline_idx = 0; // index in nextline[] where next line
1212 // starts
1213 int spell_attr = 0; // attributes desired by spelling
1214 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001215 int cur_checked_col = 0; // checked column for current line
1216#endif
zeertzjqf25d8f92024-12-18 21:12:25 +01001217 int extra_check = FALSE; // has extra highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218 int multi_attr = 0; // attributes desired by multibyte
1219 int mb_l = 1; // multi-byte byte length
1220 int mb_c = 0; // decoded multi-byte character
1221 int mb_utf8 = FALSE; // screen char is UTF-8 char
1222 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 int change_start = MAXCOL; // first col of changed area
1225 int change_end = -1; // last col of changed area
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001226 diffline_T line_changes;
1227 int change_index = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228#endif
1229 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001230 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001231 int in_multispace = FALSE; // in multiple consecutive spaces
1232 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001233#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001234 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001237 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238#ifdef FEAT_ARABIC
1239 int prev_c = 0; // previous Arabic character
1240 int prev_c1 = 0; // first composing char for prev_c
1241#endif
1242#if defined(LINE_ATTR)
1243 int did_line_attr = 0;
1244#endif
1245#ifdef FEAT_TERMINAL
1246 int get_term_attr = FALSE;
1247#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248
Martin Tournoijba43e762022-10-13 22:12:15 +01001249#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001250 // margin columns for the screen line, needed for when 'cursorlineopt'
1251 // contains "screenline"
1252 int left_curline_col = 0;
1253 int right_curline_col = 0;
1254#endif
1255
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001256#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1257 int feedback_col = 0;
1258 int feedback_old_attr = -1;
1259#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001260
1261#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1262 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001263#endif
1264#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001265 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001266#endif
1267#ifdef FEAT_CONCEAL
1268 int syntax_flags = 0;
1269 int syntax_seqnr = 0;
1270 int prev_syntax_id = 0;
1271 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1272 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001273 int did_wcol = FALSE;
1274 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001275# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001276# define FIX_FOR_BOGUSCOLS \
1277 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001278 wlv.n_extra += wlv.vcol_off_co; \
1279 wlv.vcol -= wlv.vcol_off_co; \
1280 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001281 wlv.col -= wlv.boguscols; \
1282 old_boguscols = wlv.boguscols; \
1283 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001284 }
1285#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001286# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001287#endif
1288
1289 if (startrow > endrow) // past the end already!
1290 return startrow;
1291
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001292 CLEAR_FIELD(wlv);
1293
1294 wlv.lnum = lnum;
1295 wlv.startrow = startrow;
1296 wlv.row = startrow;
1297 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001298 wlv.fromcol = -10;
1299 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001300#ifdef FEAT_LINEBREAK
1301 wlv.vcol_sbr = -1;
1302#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303
zeertzjqebfd8562024-02-06 10:59:03 +01001304 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305 {
1306 // To speed up the loop below, set extra_check when there is linebreak,
1307 // trailing white space and/or syntax processing to be done.
1308#ifdef FEAT_LINEBREAK
1309 extra_check = wp->w_p_lbr;
1310#endif
1311#ifdef FEAT_SYN_HL
1312 if (syntax_present(wp) && !wp->w_s->b_syn_error
1313# ifdef SYN_TIME_LIMIT
1314 && !wp->w_s->b_syn_slow
1315# endif
1316 )
1317 {
1318 // Prepare for syntax highlighting in this line. When there is an
1319 // error, stop syntax highlighting.
1320 save_did_emsg = did_emsg;
1321 did_emsg = FALSE;
1322 syntax_start(wp, lnum);
1323 if (did_emsg)
1324 wp->w_s->b_syn_error = TRUE;
1325 else
1326 {
1327 did_emsg = save_did_emsg;
1328#ifdef SYN_TIME_LIMIT
1329 if (!wp->w_s->b_syn_slow)
1330#endif
1331 {
1332 has_syntax = TRUE;
1333 extra_check = TRUE;
1334 }
1335 }
1336 }
1337
1338 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001339 wlv.color_cols = wp->w_p_cc_cols;
1340 if (wlv.color_cols != NULL)
1341 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342#endif
1343
1344#ifdef FEAT_TERMINAL
1345 if (term_show_buffer(wp->w_buffer))
1346 {
1347 extra_check = TRUE;
1348 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001349 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001350 }
1351#endif
1352
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001353 // handle Visual active in this window
1354 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1355 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001356 pos_T *top, *bot;
1357
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1359 {
1360 // Visual is after curwin->w_cursor
1361 top = &curwin->w_cursor;
1362 bot = &VIsual;
1363 }
1364 else
1365 {
1366 // Visual is before curwin->w_cursor
1367 top = &VIsual;
1368 bot = &curwin->w_cursor;
1369 }
1370 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1371 if (VIsual_mode == Ctrl_V)
1372 {
1373 // block mode
1374 if (lnum_in_visual_area)
1375 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001376 wlv.fromcol = wp->w_old_cursor_fcol;
1377 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001378 }
1379 }
1380 else
1381 {
1382 // non-block mode
1383 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001384 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385 else if (lnum == top->lnum)
1386 {
1387 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001388 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001389 else
1390 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001391 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001393 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001394 }
1395 }
1396 if (VIsual_mode != 'V' && lnum == bot->lnum)
1397 {
1398 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1399 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001400 wlv.fromcol = -10;
1401 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001402 }
1403 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001404 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001405 else
1406 {
1407 pos = *bot;
1408 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001409 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1410 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 else
1412 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001413 getvvcol(wp, &pos, NULL, NULL,
1414 (colnr_T *)&wlv.tocol);
1415 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416 }
1417 }
1418 }
1419 }
1420
1421 // Check if the character under the cursor should not be inverted
glepnir6a38aff2024-12-16 21:56:16 +01001422 if (!highlight_match && in_curline
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423#ifdef FEAT_GUI
1424 && !gui.in_use
1425#endif
1426 )
1427 noinvcur = TRUE;
1428
1429 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001430 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 {
1432 area_highlighting = TRUE;
1433 vi_attr = HL_ATTR(HLF_V);
1434#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1435 if ((clip_star.available && !clip_star.owned
1436 && clip_isautosel_star())
1437 || (clip_plus.available && !clip_plus.owned
1438 && clip_isautosel_plus()))
1439 vi_attr = HL_ATTR(HLF_VNC);
1440#endif
1441 }
1442 }
1443
1444 // handle 'incsearch' and ":s///c" highlighting
1445 else if (highlight_match
1446 && wp == curwin
1447 && lnum >= curwin->w_cursor.lnum
1448 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1449 {
1450 if (lnum == curwin->w_cursor.lnum)
1451 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001452 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001454 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1456 {
1457 pos.lnum = lnum;
1458 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001459 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 }
1461 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001462 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001464 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1465 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466 area_highlighting = TRUE;
1467 vi_attr = HL_ATTR(HLF_I);
1468 }
1469 }
1470
1471#ifdef FEAT_DIFF
Jonathon7c7a4e62025-01-12 09:58:00 +01001472
1473 int linestatus = 0;
1474 wlv.filler_lines = diff_check_with_linestatus(wp, lnum, &linestatus);
1475
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001476 CLEAR_FIELD(line_changes);
1477
Jonathon7c7a4e62025-01-12 09:58:00 +01001478 if (wlv.filler_lines < 0 || linestatus < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 {
Jonathon7c7a4e62025-01-12 09:58:00 +01001480 if (wlv.filler_lines == -1 || linestatus == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 {
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001482 if (diff_find_change(wp, lnum, &line_changes))
1483 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001484 wlv.diff_hlf = HLF_ADD; // added line
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001485 }
1486 else if (line_changes.num_changes > 0)
1487 {
1488 int added = diff_change_parse(
1489 &line_changes, &line_changes.changes[0],
1490 &change_start, &change_end);
1491 if (change_start == 0)
1492 {
1493 if (added)
1494 wlv.diff_hlf = HLF_TXA; // added text on changed line
1495 else
1496 wlv.diff_hlf = HLF_TXD; // changed text on changed line
1497 }
1498 else
1499 wlv.diff_hlf = HLF_CHD; // unchanged text on changed line
1500 change_index = 0;
1501 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502 else
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001503 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001504 wlv.diff_hlf = HLF_CHD; // changed line
Yee Cheng Chin9943d472025-03-26 19:41:02 +01001505 change_index = 0;
1506 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 }
1508 else
Jonathon7c7a4e62025-01-12 09:58:00 +01001509 wlv.diff_hlf = HLF_ADD;
1510
1511 if (linestatus == 0)
1512 wlv.filler_lines = 0;
1513
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001514 area_highlighting = TRUE;
1515 }
Jonathon7c7a4e62025-01-12 09:58:00 +01001516
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001517 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001518 wlv.filler_lines = wp->w_topfill;
Jonathon7c7a4e62025-01-12 09:58:00 +01001519
Bram Moolenaard7657e92022-09-20 18:59:30 +01001520 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001521#endif
1522
1523#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001524 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001525 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001526 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527#endif
1528
1529#ifdef LINE_ATTR
1530# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001531 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001532 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001533 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534# endif
1535# if defined(FEAT_QUICKFIX)
1536 // Highlight the current line in the quickfix window.
1537 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001538 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001539# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001540 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001541 area_highlighting = TRUE;
1542#endif
1543
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001544#ifdef FEAT_SPELL
zeertzjqebfd8562024-02-06 10:59:03 +01001545 if (spv->spv_has_spell && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001546 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001547 // Prepare for spell checking.
1548 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549
Luuk van Baal30805a12023-05-27 22:22:10 +01001550 // When a word wrapped from the previous line the start of the
1551 // current line is valid.
1552 if (lnum == spv->spv_checked_lnum)
1553 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001554 // Previous line was not spell checked, check for capital. This happens
1555 // for the first line in an updated region or after a closed fold.
1556 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1557 spv->spv_cap_col = 0;
1558 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001559 spv->spv_cap_col = -1;
1560 spv->spv_checked_lnum = 0;
1561
Luuk van Baal30805a12023-05-27 22:22:10 +01001562 // Get the start of the next line, so that words that wrap to the
1563 // next line are found too: "et<line-break>al.".
1564 // Trick: skip a few chars for C/shell/Vim comments
1565 nextline[SPWORDLEN] = NUL;
1566 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001567 {
1568 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1569 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1570 }
1571 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1572
1573 // If current line is empty, check first word in next line for capital.
1574 ptr = skipwhite(line);
1575 if (*ptr == NUL)
1576 {
1577 spv->spv_cap_col = 0;
1578 spv->spv_capcol_lnum = lnum + 1;
1579 }
1580 // For checking first word with a capital skip white space.
1581 else if (spv->spv_cap_col == 0)
1582 spv->spv_cap_col = ptr - line;
1583
Luuk van Baal30805a12023-05-27 22:22:10 +01001584 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001585 if (nextline[SPWORDLEN] == NUL)
1586 {
1587 // No next line or it is empty.
1588 nextlinecol = MAXCOL;
1589 nextline_idx = 0;
1590 }
1591 else
1592 {
zeertzjq94b7c322024-03-12 21:50:32 +01001593 v = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001594 if (v < SPWORDLEN)
1595 {
1596 // Short line, use it completely and append the start of the
1597 // next line.
1598 nextlinecol = 0;
1599 mch_memmove(nextline, line, (size_t)v);
1600 STRMOVE(nextline + v, nextline + SPWORDLEN);
1601 nextline_idx = v + 1;
1602 }
1603 else
1604 {
1605 // Long line, use only the last SPWORDLEN bytes.
1606 nextlinecol = v - SPWORDLEN;
1607 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1608 nextline_idx = SPWORDLEN + 1;
1609 }
1610 }
1611 }
1612#endif
1613
Luuk van Baale84c7732023-05-31 18:57:36 +01001614 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1615 ptr = line;
1616
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 if (wp->w_p_list)
1618 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001619 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001620 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001621 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001622 || wp->w_lcs_chars.trail
1623 || wp->w_lcs_chars.lead
1624 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001625 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001626
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001627 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001628 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001629 {
zeertzjq94b7c322024-03-12 21:50:32 +01001630 trailcol = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001631 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1632 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001633 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001635 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001636 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001637 {
1638 leadcol = 0;
1639 while (VIM_ISWHITE(ptr[leadcol]))
1640 ++leadcol;
1641 if (ptr[leadcol] == NUL)
1642 // in a line full of spaces all of them are treated as trailing
1643 leadcol = (colnr_T)0;
1644 else
1645 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001646 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001647 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001648 }
1649
Bram Moolenaard7657e92022-09-20 18:59:30 +01001650 wlv.wcr_attr = get_wcr_attr(wp);
1651 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001652 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001653 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654 area_highlighting = TRUE;
1655 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001656
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001657 // When w_skipcol is non-zero and there is virtual text above the actual
1658 // text, then this much of the virtual text is skipped.
1659 int skipcol_in_text_prop_above = 0;
1660
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001661#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001663 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001664
1665 char_u *prop_start;
1666 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1667 if (text_prop_count > 0)
1668 {
1669 // Make a copy of the properties, so that they are properly
1670 // aligned.
1671 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1672 if (text_props != NULL)
1673 mch_memmove(text_props, prop_start,
1674 text_prop_count * sizeof(textprop_T));
1675
1676 // Allocate an array for the indexes.
1677 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1678 if (text_prop_idxs == NULL)
1679 VIM_CLEAR(text_props);
1680
1681 if (text_props != NULL)
1682 {
1683 area_highlighting = TRUE;
1684 extra_check = TRUE;
1685
zeertzjq4e26a9a2023-12-03 17:50:47 +01001686 /* Find the last text property that inserts text. */
1687 for (int i = 0; i < text_prop_count; ++i)
1688 if (text_props[i].tp_id < 0)
1689 last_textprop_text_idx = i;
1690
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001691 // Text props "above" move the line number down to where the text
1692 // is. Only count the ones that are visible, not those that are
1693 // skipped because of w_skipcol.
1694 int text_width = wp->w_width - win_col_off(wp);
1695 for (int i = text_prop_count - 1; i >= 0; --i)
1696 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1697 {
1698 if (lnum == wp->w_topline
1699 && wp->w_skipcol - skipcol_in_text_prop_above
1700 >= text_width)
1701 {
1702 // This virtual text above is skipped, remove it from
1703 // the array.
1704 skipcol_in_text_prop_above += text_width;
1705 for (int j = i + 1; j < text_prop_count; ++j)
1706 text_props[j - 1] = text_props[j];
1707 ++i;
1708 --text_prop_count;
1709 }
1710 else
1711 ++wlv.text_prop_above_count;
1712 }
1713 }
1714 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001715
zeertzjqebfd8562024-02-06 10:59:03 +01001716 if (number_only > 0)
Bram Moolenaara572b932023-02-19 14:34:37 +00001717 {
1718 // skip over rows only used for virtual text above
1719 wlv.row += wlv.text_prop_above_count;
zeertzjq918b92b2024-03-20 19:49:20 +01001720 if (wlv.row >= endrow)
1721 {
1722 vim_free(text_props);
1723 vim_free(text_prop_idxs);
Bram Moolenaara572b932023-02-19 14:34:37 +00001724 return wlv.row;
zeertzjq918b92b2024-03-20 19:49:20 +01001725 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001726 wlv.screen_row += wlv.text_prop_above_count;
1727 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728#endif
1729
zeertzjqce53e3e2023-09-01 18:49:30 +02001730#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1731 colnr_T vcol_first_char = 0;
zeertzjqebfd8562024-02-06 10:59:03 +01001732 if (wp->w_p_lbr && number_only == 0)
zeertzjqce53e3e2023-09-01 18:49:30 +02001733 {
1734 chartabsize_T cts;
1735 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1736 (void)win_lbr_chartabsize(&cts, NULL);
1737 vcol_first_char = cts.cts_first_char;
1738 clear_chartabsize_arg(&cts);
1739 }
1740#endif
1741
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1743 // first character to be displayed.
1744 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001745 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746 else
1747 v = wp->w_leftcol;
zeertzjqebfd8562024-02-06 10:59:03 +01001748 if (v > 0 && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001750 char_u *prev_ptr = ptr;
1751 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001752 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001753 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001755 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001756 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001757 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 {
zeertzjqb557f482023-08-22 22:07:34 +02001759 head = 0;
1760 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001761 cts.cts_vcol += charsize;
1762 prev_ptr = cts.cts_ptr;
1763 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001764 if (wp->w_p_list)
1765 {
1766 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1767 || (prev_ptr > line && prev_ptr[-1] == ' '));
1768 if (!in_multispace)
1769 multispace_pos = 0;
1770 else if (cts.cts_ptr >= line + leadcol
1771 && wp->w_lcs_chars.multispace != NULL)
1772 {
1773 ++multispace_pos;
1774 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1775 multispace_pos = 0;
1776 }
1777 else if (cts.cts_ptr < line + leadcol
1778 && wp->w_lcs_chars.leadmultispace != NULL)
1779 {
1780 ++multispace_pos;
1781 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1782 multispace_pos = 0;
1783 }
1784 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001786 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001787 ptr = cts.cts_ptr;
1788 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789
1790 // When:
1791 // - 'cuc' is set, or
1792 // - 'colorcolumn' is set, or
1793 // - 'virtualedit' is set, or
1794 // - the visual mode is active,
1795 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001796 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001798 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799#endif
1800 virtual_active() ||
1801 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001802 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803
1804 // Handle a character that's not completely on the screen: Put ptr at
1805 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001806 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001807 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001808 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 }
zeertzjqb557f482023-08-22 22:07:34 +02001811 if (v > wlv.vcol)
1812 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001813
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 // Adjust for when the inverted text is before the screen,
1815 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001816 if (wlv.tocol <= wlv.vcol)
1817 wlv.fromcol = 0;
1818 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1819 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820
1821#ifdef FEAT_LINEBREAK
1822 // When w_skipcol is non-zero, first line needs 'showbreak'
1823 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001824 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001825#endif
1826#ifdef FEAT_SPELL
1827 // When spell checking a word we need to figure out the start of the
1828 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001829 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001830 {
1831 int len;
1832 colnr_T linecol = (colnr_T)(ptr - line);
1833 hlf_T spell_hlf = HLF_COUNT;
1834
1835 pos = wp->w_cursor;
1836 wp->w_cursor.lnum = lnum;
1837 wp->w_cursor.col = linecol;
Christ van Willegen - van Noort8e4c4c72024-05-17 18:49:27 +02001838 len = spell_move_to(wp, FORWARD, SMT_ALL, TRUE, &spell_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001839
1840 // spell_move_to() may call ml_get() and make "line" invalid
1841 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1842 ptr = line + linecol;
1843
John Marriottf51ff962024-06-02 19:44:11 +02001844 if (len == 0 || (int)wp->w_cursor.col > linecol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 {
1846 // no bad word found at line start, don't check until end of a
1847 // word
1848 spell_hlf = HLF_COUNT;
1849 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1850 }
1851 else
1852 {
1853 // bad word found, use attributes until end of word
1854 word_end = wp->w_cursor.col + len + 1;
1855
1856 // Turn index into actual attributes.
1857 if (spell_hlf != HLF_COUNT)
1858 spell_attr = highlight_attr[spell_hlf];
1859 }
1860 wp->w_cursor = pos;
1861
1862# ifdef FEAT_SYN_HL
1863 // Need to restart syntax highlighting for this line.
1864 if (has_syntax)
1865 syntax_start(wp, lnum);
1866# endif
1867 }
1868#endif
1869 }
1870
1871 // Correct highlighting for cursor that can't be disabled.
1872 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001873 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001874 {
1875 if (noinvcur)
1876 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001877 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 {
1879 // highlighting starts at cursor, let it start just after the
1880 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001881 fromcol_prev = wlv.fromcol;
1882 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001884 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001885 // restart highlighting after the cursor
1886 fromcol_prev = wp->w_virtcol;
1887 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001888 if (wlv.fromcol >= wlv.tocol)
1889 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001890 }
1891
1892#ifdef FEAT_SEARCH_EXTRA
zeertzjqebfd8562024-02-06 10:59:03 +01001893 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894 {
1895 v = (long)(ptr - line);
1896 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1897 &line, &screen_search_hl,
1898 &search_attr);
1899 ptr = line + v; // "line" may have been updated
1900 }
1901#endif
1902
glepnir76bdb822025-02-08 19:04:51 +01001903 if ((State & MODE_INSERT) && ins_compl_win_active(wp)
1904 && (in_curline || ins_compl_lnum_in_range(lnum)))
zeertzjqf25d8f92024-12-18 21:12:25 +01001905 area_highlighting = TRUE;
1906
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907#ifdef FEAT_SYN_HL
1908 // Cursor line highlighting for 'cursorline' in the current window.
1909 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1910 {
1911 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001912 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 if (!(wp == curwin && VIsual_active)
1914 && wp->w_p_culopt_flags != CULOPT_NBR)
1915 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001916 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001917 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1918
zeertzjqb7acea12022-12-12 13:20:43 +00001919 // Only apply CursorLine highlight here when "screenline" is not
1920 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001921 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001922 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 else
1924 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001925 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1927 }
1928 area_highlighting = TRUE;
1929 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 }
1931#endif
1932
Bram Moolenaar1306b362022-08-06 15:59:06 +01001933 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001934
1935 // Repeat for the whole displayed line.
1936 for (;;)
1937 {
1938#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001939 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001940#endif
1941#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001942 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001944
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001945 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001946 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001948#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001949 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001950 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001951 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001952 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001953 }
1954#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001955 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001956 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001957 wlv.draw_state = WL_CMDLINE;
Sean Dewar988f7432023-08-16 14:17:36 +01001958 if (wp == cmdwin_win)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001959 {
1960 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001961 wlv.n_extra = 1;
1962 wlv.c_extra = cmdwin_type;
1963 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001964 wlv.char_attr =
1965 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001966 }
1967 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001968#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001969 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001970 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001971 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001972 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001973 }
1974#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001975#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001976 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001977 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001978 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001979 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001980 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001981 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 }
1983#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001984 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001985 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001986 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001987 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001988 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001989 }
zeertzjqebfd8562024-02-06 10:59:03 +01001990
1991 // When only displaying the (relative) line number and that's done,
1992 // stop here.
1993 if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0)
1994 {
zeertzjqd0c1b772024-03-16 15:03:33 +01001995 wlv_screen_line(wp, &wlv, FALSE);
zeertzjqebfd8562024-02-06 10:59:03 +01001996 // Need to update more screen lines if:
1997 // - LineNrAbove or LineNrBelow is used, or
1998 // - still drawing filler lines.
1999 if ((wlv.row + 1 - wlv.startrow < number_only
2000 && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0))
2001#ifdef FEAT_DIFF
2002 || wlv.filler_todo > 0
2003#endif
2004 )
2005 {
2006 ++wlv.row;
2007 ++wlv.screen_row;
2008 if (wlv.row == endrow)
2009 break;
2010#ifdef FEAT_DIFF
2011 --wlv.filler_todo;
2012 if (wlv.filler_todo == 0 && wp->w_botfill)
2013 break;
2014#endif
2015 win_line_start(wp, &wlv, TRUE);
2016 continue;
2017 }
2018 else
2019 break;
2020 }
2021
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002022#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002023 // Check if 'breakindent' applies and show it.
2024 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
2025 if (wlv.n_extra == 0)
2026 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002027#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002029 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002030 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002031 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002032 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033 }
2034#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002035 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002036 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002037 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002038 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002039 }
2040 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002041
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002042#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002043 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002044 && wlv.vcol >= left_curline_col
2045 && wlv.vcol < right_curline_col)
zeertzjqb7acea12022-12-12 13:20:43 +00002046 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002047#endif
2048
2049 // When still displaying '$' of change command, stop at cursor.
zeertzjqf4ccada2024-12-17 20:50:19 +01002050 if (dollar_vcol >= 0 && in_curline && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002051 {
zeertzjqd0c1b772024-03-16 15:03:33 +01002052 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002053 // Pretend we have finished updating the window. Except when
2054 // 'cursorcolumn' is set.
2055#ifdef FEAT_SYN_HL
2056 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002057 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002058 else
2059#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002060 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002061 break;
2062 }
2063
Bram Moolenaar1306b362022-08-06 15:59:06 +01002064 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002065 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002066#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002067 if (text_props != NULL)
2068 {
2069 int pi;
2070 int bcol = (int)(ptr - line);
2071
Bram Moolenaar1306b362022-08-06 15:59:06 +01002072 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002073# ifdef FEAT_LINEBREAK
2074 && !in_linebreak
2075# endif
2076 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002077 --bcol; // still working on the previous char, e.g. Tab
2078
2079 // Check if any active property ends.
2080 for (pi = 0; pi < text_props_active; ++pi)
2081 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002082 int tpi = text_prop_idxs[pi];
2083 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002084
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002085 // An inline property ends when after the start column plus
2086 // length. An "above" property ends when used and n_extra
2087 // is zero.
2088 if ((tp->tp_col != MAXCOL
2089 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002090 {
2091 if (pi + 1 < text_props_active)
2092 mch_memmove(text_prop_idxs + pi,
2093 text_prop_idxs + pi + 1,
2094 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002095 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002096 --text_props_active;
2097 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002098# ifdef FEAT_LINEBREAK
2099 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002100 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002101 syntax_attr = 0;
2102# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002103 }
2104 }
2105
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002106# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002107 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002108 // not on the next char yet, don't start another prop
2109 --bcol;
2110# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002111 // Add any text property that starts in this column.
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002112 while (text_prop_next < text_prop_count)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002113 {
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002114 int active;
2115 textprop_T *tp = &text_props[text_prop_next];
2116 if (tp->tp_col == MAXCOL)
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002117 {
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002118 if (bcol == 0 && (tp->tp_flags & TP_FLAG_ALIGN_ABOVE))
2119 active = TRUE;
2120 else if (*ptr != NUL)
2121 break;
2122 else
2123 {
2124 // With 'nowrap' and not in the first screen line only "below"
2125 // text prop can show.
2126 active = wp->w_p_wrap
2127 || wlv.row == startrow
2128 || (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
2129 }
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002130 }
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002131 else
2132 {
2133 if (bcol < tp->tp_col - 1)
2134 break;
2135 active = bcol <= tp->tp_col - 1 + tp->tp_len;
2136 }
2137
2138 if (active)
2139 text_prop_idxs[text_props_active++] = text_prop_next;
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002140 ++text_prop_next;
2141 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002142
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002143 if (wlv.n_extra == 0 ||
2144 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002145 && !(text_prop_type != NULL &&
2146 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002147 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002148 {
2149 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002150 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002151 text_prop_flags = 0;
2152 text_prop_type = NULL;
2153 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002154 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002155 }
Dylan Thacker-Smithc8b47f22024-03-26 18:05:01 +01002156 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002157 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002158 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002159 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002160 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002161
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002162 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002163 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002164
2165 // Sort the properties on priority and/or starting last.
2166 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002167 sort_text_props(wp->w_buffer, text_props,
2168 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002169
2170 for (pi = 0; pi < text_props_active; ++pi)
2171 {
2172 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002173 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002174 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002175 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002176
Bram Moolenaarcd105412022-10-10 19:50:42 +01002177 // Only use a text property that can be displayed.
2178 // Skip "after" properties when wrap is off and at the
2179 // end of the window.
2180 if (pt != NULL
2181 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2182 && tp->tp_id != -MAXCOL
2183 && !(tp->tp_id < 0
2184 && !wp->w_p_wrap
2185 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2186 | TP_FLAG_ALIGN_ABOVE
2187 | TP_FLAG_ALIGN_BELOW)) == 0
2188 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002189 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002190 if (tp->tp_col == MAXCOL
2191 && *ptr == NUL
2192 && ((wp->w_p_list && lcs_eol_one > 0
2193 && (tp->tp_flags
2194 & TP_FLAG_ALIGN_ABOVE) == 0)
2195 || (ptr == line
2196 && !did_line
2197 && (tp->tp_flags
2198 & TP_FLAG_ALIGN_BELOW))))
2199 {
2200 // skip this prop, first display the '$' after
2201 // the line or display an empty line
2202 text_prop_follows = TRUE;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002203 continue;
2204 }
2205
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002206 if (pt->pt_hl_id > 0)
2207 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208 text_prop_type = pt;
2209 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002210 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002211 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2212 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002213 text_prop_flags = pt->pt_flags;
2214 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002215 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002216 }
2217 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002218 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002219 && -text_prop_id
2220 <= wp->w_buffer->b_textprop_text.ga_len)
2221 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002222 textprop_T *tp = &text_props[used_tpi];
2223 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002224 ->b_textprop_text.ga_data)[
2225 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002226 int above = (tp->tp_flags
2227 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002228 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002229
2230 // reset the ID in the copy to avoid it being used
2231 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002232 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002233
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002234 if (p != NULL)
2235 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002236 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002237 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002238 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002239 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002240 int wrap = tp->tp_col < MAXCOL
2241 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002242 int padding = tp->tp_col == MAXCOL
2243 && tp->tp_len > 1
2244 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002245
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002246 // Insert virtual text before the current
2247 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002248 wlv.p_extra = p;
2249 wlv.c_extra = NUL;
2250 wlv.c_final = NUL;
2251 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002252 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002253 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002254 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2255 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002256 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002257 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002258 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002259 if (*ptr == NUL)
2260 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002261 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002262# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002263 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002264 {
2265 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002266 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002267 wlv.need_showbreak = FALSE;
2268 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002269 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002270# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002271 if ((right || above || below || !wrap
2272 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002273 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002274 char_u *prev_p_extra = wlv.p_extra;
2275 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002276
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002277 // Take care of padding, right-align and
2278 // truncation.
2279 // Shared with win_lbr_chartabsize(), must do
2280 // exactly the same.
2281 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002282 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002283# ifdef FEAT_RIGHTLEFT
2284 wp->w_p_rl
2285 ? wp->w_width - wlv.col - 1
2286 :
2287# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002288 wlv.col,
2289 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002290 &n_attr, &wlv.n_attr_skip,
2291 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002292 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002293 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002294 // wlv.p_extra was allocated
2295 vim_free(p_extra_free2);
2296 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002297 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002298
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002299 if (above)
Matthias2c9f49b2025-03-16 19:27:51 +01002300 wlv.vcol_off_tp += vim_strsize(wlv.p_extra);
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002301
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002302 if (lcs_eol_one < 0
2303 && wp->w_p_wrap
2304 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002305 + wlv.n_extra - 2 > wp->w_width)
2306 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002307 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002308
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002309 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002310 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002311 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002312 {
2313 draw_screen_line(wp, &wlv);
2314
2315 // When line got too long for screen break
2316 // here.
2317 if (wlv.row == endrow)
2318 {
2319 ++wlv.row;
2320 break;
2321 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002322 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002323 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002324 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002325 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002326 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002327
Bram Moolenaarcd105412022-10-10 19:50:42 +01002328 // If the text didn't reach until the first window
2329 // column we need to skip cells.
2330 if (skip_cells > 0)
2331 {
2332 if (wlv.n_extra > skip_cells)
2333 {
2334 wlv.n_extra -= skip_cells;
2335 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002336 wlv.n_attr_skip -= skip_cells;
2337 if (wlv.n_attr_skip < 0)
2338 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002339 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002340 skip_cells = 0;
2341 }
2342 else
2343 {
2344 // the whole text is left of the window, drop
2345 // it and advance to the next one
2346 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002347 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002348 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002349 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002350 bail_out = TRUE;
2351 }
2352 }
2353
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002354 // If another text prop follows the condition below at
2355 // the last window column must know.
Dylan Thacker-Smith83925be2024-02-21 21:03:10 +01002356 // If this is an "above" text prop and 'nowrap' then we
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002357 // must wrap anyway.
2358 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002359 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002360 && (wp->w_p_wrap
2361 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002362 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002363
2364 if (bail_out)
2365 // starting a new line for "below"
2366 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002367 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002369 else if (text_prop_next < text_prop_count
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002370 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01002371 || (!wp->w_p_wrap && wlv.col == wp->w_width - 1)))
2372 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01002373 // When at last-but-one character and a text property
2374 // follows after it, we may need to flush the line after
2375 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002376 // Or when not wrapping and at the rightmost column.
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002377
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01002378 int only_below_follows = !wp->w_p_wrap && wlv.col == wp->w_width - 1;
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002379 // TODO: Store "after"/"right"/"below" text properties in order
2380 // in the buffer so only `text_props[text_prop_count - 1]`
2381 // needs to be checked for following "below" virtual text
2382 for (int i = text_prop_next; i < text_prop_count; ++i)
2383 {
2384 if (text_props[i].tp_col == MAXCOL
2385 && (!only_below_follows
2386 || (text_props[i].tp_flags & TP_FLAG_ALIGN_BELOW)))
2387 {
2388 text_prop_follows = TRUE;
2389 break;
2390 }
2391 }
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01002392 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 }
zeertzjq6e940d92023-08-17 23:21:40 +02002394
2395 if (wlv.start_extra_for_textprop)
2396 {
2397 wlv.start_extra_for_textprop = FALSE;
2398 // restore search_attr and area_attr when n_extra
2399 // is down to zero
2400 saved_search_attr = search_attr;
2401 saved_area_attr = area_attr;
2402 search_attr = 0;
2403 area_attr = 0;
2404 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002405#endif
2406
zeertzjq6e940d92023-08-17 23:21:40 +02002407 int *area_attr_p =
2408#ifdef FEAT_PROP_POPUP
2409 wlv.extra_for_textprop ? &saved_area_attr :
2410#endif
2411 &area_attr;
2412
2413 // handle Visual or match highlighting in this line
2414 if (wlv.vcol == wlv.fromcol
2415 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2416 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2417 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2418 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2419 || ((int)vcol_prev == fromcol_prev
2420 && vcol_prev < wlv.vcol // not at margin
2421 && wlv.vcol < wlv.tocol))
2422 *area_attr_p = vi_attr; // start highlighting
2423 else if (*area_attr_p != 0
2424 && (wlv.vcol == wlv.tocol
2425 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2426 *area_attr_p = 0; // stop highlighting
2427
Bram Moolenaare38fc862022-08-11 17:24:50 +01002428 if (wlv.n_extra == 0)
2429 {
zeertzjqf25d8f92024-12-18 21:12:25 +01002430#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002431 // Check for start/end of 'hlsearch' and other matches.
2432 // After end, check for start/end of next match.
2433 // When another match, have to check for start again.
2434 v = (long)(ptr - line);
2435 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2436 &screen_search_hl, &has_match_conc,
2437 &match_conc, did_line_attr, lcs_eol_one,
2438 &on_last_col);
2439 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002440
2441 // Do not allow a conceal over EOL otherwise EOL will be missed
2442 // and bad things happen.
2443 if (*ptr == NUL)
2444 has_match_conc = 0;
zeertzjqf25d8f92024-12-18 21:12:25 +01002445#else
2446 search_attr = 0;
zeertzjqe500ae82023-08-17 22:35:26 +02002447#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002448
zeertzjqf25d8f92024-12-18 21:12:25 +01002449 // Check if ComplMatchIns highlight is needed.
glepnir76bdb822025-02-08 19:04:51 +01002450 if ((State & MODE_INSERT) && ins_compl_win_active(wp)
2451 && (in_curline || ins_compl_lnum_in_range(lnum)))
zeertzjqf25d8f92024-12-18 21:12:25 +01002452 {
2453 int ins_match_attr =
glepnir76bdb822025-02-08 19:04:51 +01002454 ins_compl_col_range_attr(lnum, (int)(ptr - line));
zeertzjqf25d8f92024-12-18 21:12:25 +01002455 if (ins_match_attr > 0)
2456 search_attr =
2457 hl_combine_attr(search_attr, ins_match_attr);
2458 }
2459 }
2460
Bram Moolenaare38fc862022-08-11 17:24:50 +01002461#ifdef FEAT_DIFF
2462 if (wlv.diff_hlf != (hlf_T)0)
2463 {
Yee Cheng Chin9943d472025-03-26 19:41:02 +01002464 if (line_changes.num_changes > 0
2465 && change_index >= 0
2466 && change_index < line_changes.num_changes - 1)
2467 {
2468 if (ptr - line >= line_changes.changes[change_index+1].dc_start[line_changes.bufidx])
2469 change_index += 1;
2470 }
2471 int added = FALSE;
2472 if (line_changes.num_changes > 0 && change_index >= 0 && change_index < line_changes.num_changes)
2473 {
2474 added = diff_change_parse(&line_changes,
2475 &line_changes.changes[change_index],
2476 &change_start,
2477 &change_end);
2478 }
Bram Moolenaard097af72022-12-17 11:33:00 +00002479 // When there is extra text (e.g. virtual text) it gets the
2480 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002481 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2482 && wlv.n_extra == 0)
Yee Cheng Chin9943d472025-03-26 19:41:02 +01002483 wlv.diff_hlf = added ? HLF_TXA : HLF_TXD; // added/changed text
2484 if ((wlv.diff_hlf == HLF_TXD || wlv.diff_hlf == HLF_TXA)
2485 && ((ptr - line >= change_end && wlv.n_extra == 0)
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002486 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002487 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002488 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002489 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2490 && wp->w_p_culopt_flags != CULOPT_NBR
2491 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2492 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002493 wlv.line_attr = hl_combine_attr(
2494 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002495 }
2496#endif
2497
Bram Moolenaara74fda62019-10-19 17:38:03 +02002498#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002499 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002500 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002501 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002502# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002503 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002504 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002505# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002506 // Get syntax attribute.
2507 if (has_syntax)
2508 {
2509 // Get the syntax attribute for the character. If there
2510 // is an error, disable syntax highlighting.
2511 save_did_emsg = did_emsg;
2512 did_emsg = FALSE;
2513
2514 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002515 if (v == prev_syntax_col)
2516 // at same column again
2517 syntax_attr = prev_syntax_attr;
2518 else
2519 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002520# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002521 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002522# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002523 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002524# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002525 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002526# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002527 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002528 prev_syntax_col = v;
2529 prev_syntax_attr = syntax_attr;
2530 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002531
Bram Moolenaar34390282019-10-16 14:38:26 +02002532 if (did_emsg)
2533 {
2534 wp->w_s->b_syn_error = TRUE;
2535 has_syntax = FALSE;
2536 syntax_attr = 0;
2537 }
2538 else
2539 did_emsg = save_did_emsg;
2540# ifdef SYN_TIME_LIMIT
2541 if (wp->w_s->b_syn_slow)
2542 has_syntax = FALSE;
2543# endif
2544
2545 // Need to get the line again, a multi-line regexp may
2546 // have made it invalid.
2547 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2548 ptr = line + v;
2549# ifdef FEAT_CONCEAL
2550 // no concealing past the end of the line, it interferes
2551 // with line highlighting
2552 if (*ptr == NUL)
2553 syntax_flags = 0;
2554 else
2555 syntax_flags = get_syntax_info(&syntax_seqnr);
2556# endif
2557 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002558 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002559# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002560 // Combine text property highlight into syntax highlight.
2561 if (text_prop_type != NULL)
2562 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002563 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002564 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2565 else
2566 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002567 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002568 }
2569# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002570#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002571
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572 // Decide which of the highlight attributes to use.
2573 attr_pri = TRUE;
2574#ifdef LINE_ATTR
2575 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002576 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002577 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002578 if (!highlight_match)
2579 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002580 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002581# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002582 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002583# endif
2584 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002585 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002586 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002587 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002588# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002590# endif
2591 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002592 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002593 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2594 || wlv.vcol < wlv.fromcol
2595 || vcol_prev < fromcol_prev
2596 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002597 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002598 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002599 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002600# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002601 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002602# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002603 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002604# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605 attr_pri = FALSE;
2606 }
2607#else
2608 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002609 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002610 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002611 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612#endif
2613 else
2614 {
2615 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002617 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002618#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002619 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002620#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002621 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002622#ifdef FEAT_PROP_POPUP
2623 // override with text property highlight when "override" is TRUE
2624 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002625 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002626#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002627 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002628
2629 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002630 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002631 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002632 if (wlv.char_attr == 0)
2633 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002634 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002635 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002636 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002637
2638 // Get the next character to put on the screen.
2639
2640 // The "p_extra" points to the extra stuff that is inserted to
2641 // represent special characters (non-printable stuff) and other
2642 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002643 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002644 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2645 // "p_extra[n_extra]".
2646 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002647 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002649 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002650 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002651 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2652 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2654 if (enc_utf8 && utf_char2len(c) > 1)
2655 {
2656 mb_utf8 = TRUE;
2657 u8cc[0] = 0;
2658 c = 0xc0;
2659 }
2660 else
2661 mb_utf8 = FALSE;
2662 }
2663 else
2664 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002665 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666 if (has_mbyte)
2667 {
2668 mb_c = c;
2669 if (enc_utf8)
2670 {
2671 // If the UTF-8 character is more than one byte:
2672 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002673 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002674 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002675 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002676 mb_l = 1;
2677 else if (mb_l > 1)
2678 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002679 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002680 mb_utf8 = TRUE;
2681 c = 0xc0;
2682 }
2683 }
2684 else
2685 {
2686 // if this is a DBCS character, put it in "mb_c"
2687 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002688 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689 mb_l = 1;
2690 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002691 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002692 }
2693 if (mb_l == 0) // at the NUL at end-of-line
2694 mb_l = 1;
2695
2696 // If a double-width char doesn't fit display a '>' in the
2697 // last column.
2698 if ((
2699# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002700 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002702 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 && (*mb_char2cells)(mb_c) == 2)
2704 {
2705 c = '>';
2706 mb_c = c;
2707 mb_l = 1;
2708 mb_utf8 = FALSE;
2709 multi_attr = HL_ATTR(HLF_AT);
2710#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002711 if (wlv.cul_attr)
2712 multi_attr = hl_combine_attr(
2713 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002715 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002716
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717 // put the pointer back to output the double-width
2718 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002719 ++wlv.n_extra;
2720 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002721 }
2722 else
2723 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002724 wlv.n_extra -= mb_l - 1;
2725 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726 }
2727 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002728 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002730 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002731#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002732 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002733 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002734 // Only restore search_attr and area_attr after "n_extra" in
2735 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002736 if (wlv.saved_n_extra <= 0)
2737 {
2738 if (search_attr == 0)
2739 search_attr = saved_search_attr;
2740 if (area_attr == 0 && *ptr != NUL)
2741 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002742
2743 if (wlv.extra_for_textprop)
2744 // wlv.extra_attr should be used at this position but
2745 // not any further.
2746 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002747 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002748
2749 wlv.extra_for_textprop = FALSE;
2750 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002751 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002752#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 }
2754 else
2755 {
2756#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002757 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002758#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002759 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002761 // Get a character from the line itself.
2762 c = *ptr;
2763#ifdef FEAT_LINEBREAK
2764 c0 = *ptr;
2765#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002766 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002767 {
2768#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002769 // text is finished, may display a "below" virtual text
2770 did_line = TRUE;
2771#endif
zeertzjqb557f482023-08-22 22:07:34 +02002772 // no more cells to skip
2773 skip_cells = 0;
2774 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002775
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002776 if (has_mbyte)
2777 {
2778 mb_c = c;
2779 if (enc_utf8)
2780 {
2781 // If the UTF-8 character is more than one byte: Decode it
2782 // into "mb_c".
2783 mb_l = utfc_ptr2len(ptr);
2784 mb_utf8 = FALSE;
2785 if (mb_l > 1)
2786 {
2787 mb_c = utfc_ptr2char(ptr, u8cc);
2788 // Overlong encoded ASCII or ASCII with composing char
2789 // is displayed normally, except a NUL.
2790 if (mb_c < 0x80)
2791 {
2792 c = mb_c;
2793#ifdef FEAT_LINEBREAK
2794 c0 = mb_c;
2795#endif
2796 }
2797 mb_utf8 = TRUE;
2798
2799 // At start of the line we can have a composing char.
2800 // Draw it as a space with a composing char.
2801 if (utf_iscomposing(mb_c))
2802 {
2803 int i;
2804
2805 for (i = Screen_mco - 1; i > 0; --i)
2806 u8cc[i] = u8cc[i - 1];
2807 u8cc[0] = mb_c;
2808 mb_c = ' ';
2809 }
2810 }
2811
2812 if ((mb_l == 1 && c >= 0x80)
2813 || (mb_l >= 1 && mb_c == 0)
2814 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2815 {
2816 // Illegal UTF-8 byte: display as <xx>.
2817 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002818 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819# ifdef FEAT_RIGHTLEFT
2820 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002821 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002822# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002823 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002824 c = *wlv.p_extra;
2825 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002826 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002827 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2828 wlv.c_extra = NUL;
2829 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 if (area_attr == 0 && search_attr == 0)
2831 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002832 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002833 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002834 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002835 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 }
2837 }
2838 else if (mb_l == 0) // at the NUL at end-of-line
2839 mb_l = 1;
2840#ifdef FEAT_ARABIC
2841 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2842 {
2843 // Do Arabic shaping.
2844 int pc, pc1, nc;
2845 int pcc[MAX_MCO];
2846
2847 // The idea of what is the previous and next
2848 // character depends on 'rightleft'.
2849 if (wp->w_p_rl)
2850 {
2851 pc = prev_c;
2852 pc1 = prev_c1;
2853 nc = utf_ptr2char(ptr + mb_l);
2854 prev_c1 = u8cc[0];
2855 }
2856 else
2857 {
2858 pc = utfc_ptr2char(ptr + mb_l, pcc);
2859 nc = prev_c;
2860 pc1 = pcc[0];
2861 }
2862 prev_c = mb_c;
2863
2864 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2865 }
2866 else
2867 prev_c = mb_c;
2868#endif
2869 }
2870 else // enc_dbcs
2871 {
2872 mb_l = MB_BYTE2LEN(c);
2873 if (mb_l == 0) // at the NUL at end-of-line
2874 mb_l = 1;
2875 else if (mb_l > 1)
2876 {
2877 // We assume a second byte below 32 is illegal.
2878 // Hopefully this is OK for all double-byte encodings!
2879 if (ptr[1] >= 32)
2880 mb_c = (c << 8) + ptr[1];
2881 else
2882 {
2883 if (ptr[1] == NUL)
2884 {
2885 // head byte at end of line
2886 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002887 transchar_nonprint(wp->w_buffer, wlv.extra, c);
John Marriottf51ff962024-06-02 19:44:11 +02002888 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889 }
2890 else
2891 {
2892 // illegal tail byte
2893 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002894 STRCPY(wlv.extra, "XX");
John Marriottf51ff962024-06-02 19:44:11 +02002895 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002897 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002898 wlv.c_extra = NUL;
2899 wlv.c_final = NUL;
2900 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 if (area_attr == 0 && search_attr == 0)
2902 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002903 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002904 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002905 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002906 // save current attr
2907 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 }
2909 mb_c = c;
2910 }
2911 }
2912 }
2913 // If a double-width char doesn't fit display a '>' in the
2914 // last column; the character is displayed at the start of the
2915 // next line.
2916 if ((
2917# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002918 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002920 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921 && (*mb_char2cells)(mb_c) == 2)
2922 {
2923 c = '>';
2924 mb_c = c;
2925 mb_utf8 = FALSE;
2926 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002927 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002928 // Put pointer back so that the character will be
2929 // displayed at the start of the next line.
2930 --ptr;
2931#ifdef FEAT_CONCEAL
2932 did_decrement_ptr = TRUE;
2933#endif
2934 }
2935 else if (*ptr != NUL)
2936 ptr += mb_l - 1;
2937
2938 // If a double-width char doesn't fit at the left side display
2939 // a '<' in the first column. Don't do this for unprintable
2940 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002941 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002943 wlv.n_extra = 1;
2944 wlv.c_extra = MB_FILLER_CHAR;
2945 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 c = ' ';
2947 if (area_attr == 0 && search_attr == 0)
2948 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002949 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002950 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002951 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002952 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002953 }
2954 mb_c = c;
2955 mb_utf8 = FALSE;
2956 mb_l = 1;
2957 }
2958
2959 }
2960 ++ptr;
2961
2962 if (extra_check)
2963 {
2964#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 // Check spelling (unless at the end of the line).
2966 // Only do this when there is no syntax highlighting, the
2967 // @Spell cluster is not used or the current syntax item
2968 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002969 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002970 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 {
2972 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002973 // do not calculate cap_col at the end of the line or when
2974 // only white space is following
2975 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002976# ifdef FEAT_SYN_HL
2977 !has_syntax ||
2978# endif
2979 can_spell))
2980 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002981 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 int len;
2983 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002984
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002985 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987
2988 // Use nextline[] if possible, it has the start of the
2989 // next line concatenated.
2990 if ((prev_ptr - line) - nextlinecol >= 0)
2991 p = nextline + (prev_ptr - line) - nextlinecol;
2992 else
2993 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002994 spv->spv_cap_col -= (int)(prev_ptr - line);
2995 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2996 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 word_end = v + len;
2998
2999 // In Insert mode only highlight a word that
3000 // doesn't touch the cursor.
3001 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01003002 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 && wp->w_cursor.lnum == lnum
3004 && wp->w_cursor.col >=
3005 (colnr_T)(prev_ptr - line)
3006 && wp->w_cursor.col < (colnr_T)word_end)
3007 {
3008 spell_hlf = HLF_COUNT;
3009 spell_redraw_lnum = lnum;
3010 }
3011
3012 if (spell_hlf == HLF_COUNT && p != prev_ptr
3013 && (p - nextline) + len > nextline_idx)
3014 {
3015 // Remember that the good word continues at the
3016 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01003017 spv->spv_checked_lnum = lnum + 1;
3018 spv->spv_checked_col = (p - nextline) + len
3019 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020 }
3021
3022 // Turn index into actual attributes.
3023 if (spell_hlf != HLF_COUNT)
3024 spell_attr = highlight_attr[spell_hlf];
3025
Luuk van Baal30805a12023-05-27 22:22:10 +01003026 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 {
3028 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01003029 && (p - nextline) + spv->spv_cap_col
3030 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 {
3032 // Remember that the word in the next line
3033 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01003034 spv->spv_capcol_lnum = lnum + 1;
3035 spv->spv_cap_col = ((p - nextline)
3036 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003037 }
3038 else
3039 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01003040 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041 }
3042 }
3043 }
3044 if (spell_attr != 0)
3045 {
3046 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3048 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003050 wlv.char_attr = hl_combine_attr(spell_attr,
3051 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 }
3053#endif
3054#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02003055 // we don't want linebreak to apply for lines that start with
3056 // leading spaces, followed by long letters (since it would add
3057 // a break at the beginning of a line and this might be unexpected)
3058 //
3059 // So only allow to linebreak, once we have found chars not in
3060 // 'breakat' in the line.
3061 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
3062 !VIM_ISBREAK((int)*ptr))
3063 wlv.need_lbr = TRUE;
3064#endif
3065#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02003067 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
3069 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02003070 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
3071 : 0;
3072 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01003073 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074
zeertzjqce53e3e2023-09-01 18:49:30 +02003075 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
3076# ifdef FEAT_PROP_POPUP
3077 - vcol_first_char,
3078# endif
3079 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003080# ifdef FEAT_PROP_POPUP
3081 // do not want virtual text counted here
3082 cts.cts_has_prop_with_text = FALSE;
3083# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003084 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003085 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02003086
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003087 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003088 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003089 // line break, but for TABs the highlighting should
3090 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003091 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02003092
Bram Moolenaar1306b362022-08-06 15:59:06 +01003093 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01003095 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003096 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 wp->w_buffer->b_p_vts_array) - 1;
3098# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003099 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003100 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101# endif
3102
Bram Moolenaar1306b362022-08-06 15:59:06 +01003103 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
3104 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003105# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01003106 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00003107 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00003108# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003109 if (VIM_ISWHITE(c))
3110 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003111# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112 if (c == TAB)
3113 // See "Tab alignment" below.
3114 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003115# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 if (!wp->w_p_list)
3117 c = ' ';
3118 }
3119 }
3120#endif
zeertzjqabc80812023-09-24 23:32:18 +02003121 if (wp->w_p_list)
3122 {
3123 in_multispace = c == ' ' && (*ptr == ' '
3124 || (prev_ptr > line && prev_ptr[-1] == ' '));
3125 if (!in_multispace)
3126 multispace_pos = 0;
3127 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003128
Bram Moolenaareed9d462021-02-15 20:38:25 +01003129 // 'list': Change char 160 to 'nbsp' and space to 'space'
3130 // setting in 'listchars'. But not when the character is
3131 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 if (wp->w_p_list
3133 && ((((c == 160 && mb_l == 1)
3134 || (mb_utf8
3135 && ((mb_c == 160 && mb_l == 2)
3136 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003137 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003138 || (c == ' '
3139 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003140 && (wp->w_lcs_chars.space
3141 || (in_multispace
3142 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003143 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 && ptr - line <= trailcol)))
3145 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003146 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3147 {
3148 c = wp->w_lcs_chars.multispace[multispace_pos++];
3149 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3150 multispace_pos = 0;
3151 }
3152 else
3153 c = (c == ' ') ? wp->w_lcs_chars.space
3154 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 if (area_attr == 0 && search_attr == 0)
3156 {
3157 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003158 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003159 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003160 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 }
3162 mb_c = c;
3163 if (enc_utf8 && utf_char2len(c) > 1)
3164 {
3165 mb_utf8 = TRUE;
3166 u8cc[0] = 0;
3167 c = 0xc0;
3168 }
3169 else
3170 mb_utf8 = FALSE;
3171 }
3172
zeertzjq2e7cba32022-06-10 15:30:32 +01003173 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3174 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003176 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3177 && wp->w_lcs_chars.leadmultispace != NULL)
3178 {
3179 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003180 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3181 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003182 multispace_pos = 0;
3183 }
3184
3185 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3186 c = wp->w_lcs_chars.trail;
3187
3188 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3189 c = wp->w_lcs_chars.lead;
3190
zeertzjq2e7cba32022-06-10 15:30:32 +01003191 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003192 c = wp->w_lcs_chars.space;
3193
3194
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 if (!attr_pri)
3196 {
3197 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003198 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003199 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003200 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 }
3202 mb_c = c;
3203 if (enc_utf8 && utf_char2len(c) > 1)
3204 {
3205 mb_utf8 = TRUE;
3206 u8cc[0] = 0;
3207 c = 0xc0;
3208 }
3209 else
3210 mb_utf8 = FALSE;
3211 }
3212 }
3213
3214 // Handling of non-printable characters.
3215 if (!vim_isprintc(c))
3216 {
3217 // when getting a character from the file, we may have to
3218 // turn it into something else on the way to putting it
3219 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003220 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003222 int tab_len = 0;
3223 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003225 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003226
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227 // only adjust the tab_len, when at the first column
3228 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003229 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003230 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231#endif
3232 // tab amount depends on current column
3233#ifdef FEAT_VARTABS
3234 tab_len = tabstop_padding(vcol_adjusted,
3235 wp->w_buffer->b_p_ts,
3236 wp->w_buffer->b_p_vts_array) - 1;
3237#else
3238 tab_len = (int)wp->w_buffer->b_p_ts
3239 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3240#endif
3241
3242#ifdef FEAT_LINEBREAK
3243 if (!wp->w_p_lbr || !wp->w_p_list)
3244#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003245 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003247 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003248 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249#ifdef FEAT_LINEBREAK
3250 else
3251 {
3252 char_u *p;
3253 int len;
3254 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003255 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003257# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003258 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003260 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003261
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003263 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003264 && old_boguscols > 0
3265 && wlv.n_extra > tab_len)
3266 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003267# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003268 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003270 // If wlv.n_extra > 0, it gives the number of chars
3271 // to use for a tab, else we need to calculate the
3272 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003273 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3274 len = tab_len * tab2_len;
3275 if (wp->w_lcs_chars.tab3)
3276 len += mb_char2len(wp->w_lcs_chars.tab3)
3277 - tab2_len;
3278 if (wlv.n_extra > 0)
3279 len += wlv.n_extra - tab_len;
3280 c = wp->w_lcs_chars.tab1;
3281 p = alloc(len + 1);
3282 if (p == NULL)
3283 wlv.n_extra = 0;
3284 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003286 vim_memset(p, ' ', len);
3287 p[len] = NUL;
3288 vim_free(wlv.p_extra_free);
3289 wlv.p_extra_free = p;
3290 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003291 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003292 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003293
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003294 if (*p == NUL)
3295 {
3296 tab_len = i;
3297 break;
3298 }
3299
3300 // if tab3 is given, use it for the last
3301 // char
3302 if (wp->w_lcs_chars.tab3
3303 && i == tab_len - 1)
3304 lcs = wp->w_lcs_chars.tab3;
3305 p += mb_char2bytes(lcs, p);
3306 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003308 }
3309 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003310# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003311 // n_extra will be increased by
3312 // FIX_FOX_BOGUSCOLS macro below, so need to
3313 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003314 if (wlv.vcol_off_co > 0)
3315 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003316# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003317 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319 }
3320#endif
3321#ifdef FEAT_CONCEAL
3322 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003323 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324
3325 // Tab alignment should be identical regardless of
3326 // 'conceallevel' value. So tab compensates of all
3327 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003328 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003329 // line. Note that the tab can be longer than
3330 // 'tabstop' when there are concealed characters.
3331 FIX_FOR_BOGUSCOLS;
3332
3333 // Make sure, the highlighting for the tab char will be
3334 // correctly set further below (effectively reverts the
zeertzjq010e1532024-03-14 18:22:17 +01003335 // FIX_FOR_BOGUSCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003336 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003337 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 tab_len += vc_saved;
3339 }
3340#endif
3341 mb_utf8 = FALSE; // don't draw as UTF-8
3342 if (wp->w_p_list)
3343 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003344 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003345 ? wp->w_lcs_chars.tab3
3346 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003348 if (wp->w_p_lbr && wlv.p_extra != NULL
3349 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003350 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 else
3352#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003353 wlv.c_extra = wp->w_lcs_chars.tab2;
3354 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003356 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003357 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003358 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 mb_c = c;
3360 if (enc_utf8 && utf_char2len(c) > 1)
3361 {
3362 mb_utf8 = TRUE;
3363 u8cc[0] = 0;
3364 c = 0xc0;
3365 }
3366 }
3367 else
3368 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003369 wlv.c_final = NUL;
3370 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 c = ' ';
3372 }
3373 }
3374 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003375 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003376 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003377 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3378 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379 && VIsual_mode != Ctrl_V
3380 && (
3381# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003382 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385 && !(noinvcur
3386 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003387 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388 && lcs_eol_one > 0)
3389 {
3390 // Display a '$' after the line or highlight an extra
3391 // character if the line break is included.
3392#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3393 // For a diff line the highlighting continues after the
3394 // "$".
3395 if (
3396# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003397 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003398# ifdef LINE_ATTR
3399 &&
3400# endif
3401# endif
3402# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003403 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404# endif
3405 )
3406#endif
3407 {
3408 // In virtualedit, visual selections may extend
3409 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003410 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003411 && wlv.tocol != MAXCOL
3412 && wlv.vcol < wlv.tocol))
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01003413 wlv.p_extra = (char_u *)"";
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003414 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003416 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3417 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 else
3419 c = ' ';
3420 lcs_eol_one = -1;
3421 --ptr; // put it back at the NUL
3422 if (!attr_pri)
3423 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003424 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 n_attr = 1;
3427 }
3428 mb_c = c;
3429 if (enc_utf8 && utf_char2len(c) > 1)
3430 {
3431 mb_utf8 = TRUE;
3432 u8cc[0] = 0;
3433 c = 0xc0;
3434 }
3435 else
3436 mb_utf8 = FALSE; // don't draw as UTF-8
3437 }
3438 else if (c != NUL)
3439 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003440 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3441 if (wlv.n_extra == 0)
3442 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443#ifdef FEAT_RIGHTLEFT
3444 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003445 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003447 wlv.c_extra = NUL;
3448 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449#ifdef FEAT_LINEBREAK
3450 if (wp->w_p_lbr)
3451 {
3452 char_u *p;
3453
Bram Moolenaar1306b362022-08-06 15:59:06 +01003454 c = *wlv.p_extra;
3455 p = alloc(wlv.n_extra + 1);
John Marriottf51ff962024-06-02 19:44:11 +02003456 if (p == NULL)
3457 wlv.n_extra = 0;
3458 else
3459 {
3460 vim_memset(p, ' ', wlv.n_extra);
3461 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3462 p[wlv.n_extra] = NUL;
3463 vim_free(wlv.p_extra_free);
3464 wlv.p_extra_free = wlv.p_extra = p;
3465 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 }
3467 else
3468#endif
3469 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003470 wlv.n_extra = byte2cells(c) - 1;
3471 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472 }
3473 if (!attr_pri)
3474 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003475 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003476 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003478#ifdef FEAT_PROP_POPUP
3479 if (text_prop_type != NULL &&
3480 text_prop_flags & PT_FLAG_OVERRIDE)
3481 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3482#endif
3483
Bram Moolenaar1306b362022-08-06 15:59:06 +01003484 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 }
3486 mb_utf8 = FALSE; // don't draw as UTF-8
3487 }
3488 else if (VIsual_active
3489 && (VIsual_mode == Ctrl_V
3490 || VIsual_mode == 'v')
3491 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003492 && wlv.tocol != MAXCOL
3493 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 && (
3495#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003496 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003498 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 {
3500 c = ' ';
3501 --ptr; // put it back at the NUL
3502 }
3503#if defined(LINE_ATTR)
3504 else if ((
3505# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003506 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507# endif
3508# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003509 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003511 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512 ) && (
3513# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003514 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003516 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003518 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519# endif
3520 < wp->w_width)))
3521 {
3522 // Highlight until the right side of the window
3523 c = ' ';
3524 --ptr; // put it back at the NUL
3525
3526 // Remember we do the char for line highlighting.
3527 ++did_line_attr;
3528
3529 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003530 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003532 || (wp->w_p_list &&
3533 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003534 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003535#ifdef FEAT_SIGNS
3536 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003537 // but not when cursorline is active
3538 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3539 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003540 wlv.char_attr = wlv.sattr.sat_linehl;
3541#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542# ifdef FEAT_DIFF
Yee Cheng Chin9943d472025-03-26 19:41:02 +01003543 if (wlv.diff_hlf == HLF_TXD || wlv.diff_hlf == HLF_TXA)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003545 wlv.diff_hlf = HLF_CHD;
3546 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003548 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3550 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003551 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003552 || (wlv.vcol >= left_curline_col
3553 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003554 wlv.char_attr = hl_combine_attr(
3555 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 }
3557 }
3558# endif
3559# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003562 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003563 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3564 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003566 if (!wlv.cul_screenline
3567 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003568 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003569 wlv.char_attr = hl_combine_attr(
3570 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003571 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003572 else if (wlv.line_attr)
3573 wlv.char_attr = hl_combine_attr(
3574 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003575 }
3576# endif
3577 }
3578#endif
3579 }
3580
3581#ifdef FEAT_CONCEAL
3582 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003583 && (wp != curwin || lnum != wp->w_cursor.lnum
3584 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3586 && !(lnum_in_visual_area
3587 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3588 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003589 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003590 if (((prev_syntax_id != syntax_seqnr
3591 && (syntax_flags & HL_CONCEAL) != 0)
3592 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003593 && (syn_get_sub_char() != NUL
3594 || (has_match_conc && match_conc)
3595 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596 && wp->w_p_cole != 3)
3597 {
3598 // First time at this concealed item: display one
3599 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003600 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 c = match_conc;
3602 else if (syn_get_sub_char() != NUL)
3603 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003604 else if (wp->w_lcs_chars.conceal != NUL)
3605 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606 else
3607 c = ' ';
3608
zeertzjq010e1532024-03-14 18:22:17 +01003609 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3610 // When the first char to be concealed is double-width,
3611 // need to advance one more virtual column.
3612 wlv.n_extra++;
3613
3614 mb_c = c;
3615 if (enc_utf8 && utf_char2len(c) > 1)
3616 {
3617 mb_utf8 = TRUE;
3618 u8cc[0] = 0;
3619 c = 0xc0;
3620 }
3621 else
3622 mb_utf8 = FALSE; // don't draw as UTF-8
3623
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003624 prev_syntax_id = syntax_seqnr;
3625
Bram Moolenaar1306b362022-08-06 15:59:06 +01003626 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003627 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003628 wlv.vcol += wlv.n_extra;
3629 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630 {
3631# ifdef FEAT_RIGHTLEFT
3632 if (wp->w_p_rl)
3633 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003634 wlv.col -= wlv.n_extra;
3635 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636 }
3637 else
3638# endif
3639 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003640 wlv.boguscols += wlv.n_extra;
3641 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 }
3643 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003644 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 n_attr = 0;
3646 }
zeertzjqb557f482023-08-22 22:07:34 +02003647 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648 {
3649 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003650 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003651 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652 }
3653 else
3654 {
3655 prev_syntax_id = 0;
3656 is_concealing = FALSE;
3657 }
3658
zeertzjqb557f482023-08-22 22:07:34 +02003659 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660 // not showing the '>', put pointer back to avoid getting stuck
3661 ++ptr;
3662
3663#endif // FEAT_CONCEAL
3664 }
3665
3666#ifdef FEAT_CONCEAL
3667 // In the cursor line and we may be concealing characters: correct
3668 // the cursor column when we reach its position.
zeertzjq253ff4d2024-03-13 20:38:26 +01003669 // With 'virtualedit' we may never reach cursor position, but we still
3670 // need to correct the cursor column, so do that at end of line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003671 if (!did_wcol && wlv.draw_state == WL_LINE
zeertzjqf4ccada2024-12-17 20:50:19 +01003672 && in_curline && conceal_cursor_line(wp)
zeertzjq253ff4d2024-03-13 20:38:26 +01003673 && (wlv.vcol + skip_cells >= wp->w_virtcol || c == NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003674 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003675# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003677 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003679# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003680 wp->w_wcol = wlv.col - wlv.boguscols;
zeertzjq253ff4d2024-03-13 20:38:26 +01003681 if (wlv.vcol + skip_cells < wp->w_virtcol)
3682 // Cursor beyond end of the line with 'virtualedit'.
3683 wp->w_wcol += wp->w_virtcol - wlv.vcol - skip_cells;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003684 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685 did_wcol = TRUE;
3686 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003687# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003688 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003689# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690 }
3691#endif
3692
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003693 // Use "wlv.extra_attr", but don't override visual selection
3694 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003695 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3696 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003697 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003698 && (!attr_pri
3699#ifdef FEAT_PROP_POPUP
3700 || (text_prop_flags & PT_FLAG_OVERRIDE)
3701#endif
3702 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703 {
3704#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003705 if (wlv.line_attr)
3706 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707 else
3708#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003709 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003710#ifdef FEAT_PROP_POPUP
3711 if (reset_extra_attr)
3712 {
3713 reset_extra_attr = FALSE;
3714 wlv.extra_attr = 0;
3715 }
3716#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717 }
3718
3719#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3720 // XIM don't send preedit_start and preedit_end, but they send
3721 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3722 // im_is_preediting() here.
3723 if (p_imst == IM_ON_THE_SPOT
3724 && xic != NULL
3725 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003726 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727 && !p_imdisable
3728 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003729 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730 {
3731 colnr_T tcol;
3732
3733 if (preedit_end_col == MAXCOL)
3734 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3735 else
3736 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003737 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738 {
3739 if (feedback_old_attr < 0)
3740 {
3741 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003742 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003744 wlv.char_attr = im_get_feedback_attr(feedback_col);
3745 if (wlv.char_attr < 0)
3746 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747 feedback_col++;
3748 }
3749 else if (feedback_old_attr >= 0)
3750 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003751 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003752 feedback_old_attr = -1;
3753 feedback_col = 0;
3754 }
3755 }
3756#endif
3757 // Handle the case where we are in column 0 but not on the first
3758 // character of the line and the user wants us to show us a
zeertzjq08a83a02025-02-20 22:04:09 +01003759 // special character (via 'listchars' option "precedes:<char>").
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 if (lcs_prec_todo != NUL
3761 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003762 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3763 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003764#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003765 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003766#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003767 && wlv.draw_state > WL_NR
zeertzjq13f100e2025-02-21 19:49:44 +01003768 && skip_cells <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769 && c != NUL)
3770 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003771 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772 lcs_prec_todo = NUL;
3773 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3774 {
3775 // Double-width character being overwritten by the "precedes"
3776 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003777 wlv.c_extra = MB_FILLER_CHAR;
3778 wlv.c_final = NUL;
3779 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003781 wlv.extra_attr =
3782 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003783 }
3784 mb_c = c;
3785 if (enc_utf8 && utf_char2len(c) > 1)
3786 {
3787 mb_utf8 = TRUE;
3788 u8cc[0] = 0;
3789 c = 0xc0;
3790 }
3791 else
3792 mb_utf8 = FALSE; // don't draw as UTF-8
3793 if (!attr_pri)
3794 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003795 saved_attr3 = wlv.char_attr; // save current attr
3796 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797 n_attr3 = 1;
3798 }
3799 }
3800
3801 // At end of the text line or just after the last character.
3802 if ((c == NUL
3803#if defined(LINE_ATTR)
3804 || did_line_attr == 1
3805#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003806 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003807 {
3808#ifdef FEAT_SEARCH_EXTRA
3809 // flag to indicate whether prevcol equals startcol of search_hl or
3810 // one of the matches
3811 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3812 (long)(ptr - line) - (c == NUL));
3813#endif
3814 // Invert at least one char, used for Visual and empty line or
3815 // highlight match at end of line. If it's beyond the last
3816 // char on the screen, just overwrite that one (tricky!) Not
3817 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003818 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003819 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820 && (VIsual_mode != Ctrl_V
3821 || lnum == VIsual.lnum
3822 || lnum == curwin->w_cursor.lnum)
3823 && c == NUL)
3824#ifdef FEAT_SEARCH_EXTRA
3825 // highlight 'hlsearch' match at end of line
3826 || (prevcol_hl_flag
3827# ifdef FEAT_SYN_HL
3828 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3829 && !(wp == curwin && VIsual_active))
3830# endif
3831# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003832 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833# endif
3834# if defined(LINE_ATTR)
3835 && did_line_attr <= 1
3836# endif
3837 )
3838#endif
3839 ))
3840 {
3841 int n = 0;
3842
3843#ifdef FEAT_RIGHTLEFT
3844 if (wp->w_p_rl)
3845 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003846 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003847 n = 1;
3848 }
3849 else
3850#endif
3851 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003852 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003853 n = -1;
3854 }
3855 if (n != 0)
3856 {
3857 // At the window boundary, highlight the last character
3858 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003859 wlv.off += n;
3860 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861 }
3862 else
3863 {
3864 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003865 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003866 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003867 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868 }
3869#ifdef FEAT_SEARCH_EXTRA
3870 if (area_attr == 0)
3871 {
3872 // Use attributes from match with highest priority among
3873 // 'search_hl' and the match list.
3874 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003875 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876 }
3877#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003878 ScreenAttrs[wlv.off] = wlv.char_attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01003879 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003880#ifdef FEAT_RIGHTLEFT
3881 if (wp->w_p_rl)
3882 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003883 --wlv.col;
3884 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003885 }
3886 else
3887#endif
3888 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003889 ++wlv.col;
3890 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003891 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003892 ++wlv.vcol;
3893 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894 }
3895 }
3896
3897 // At end of the text line.
3898 if (c == NUL)
3899 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003900#ifdef FEAT_PROP_POPUP
3901 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003902 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003903 // Put the pointer back to the NUL.
3904 --ptr;
3905 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003907 else
3908#endif
3909 {
3910 draw_screen_line(wp, &wlv);
3911
3912 // Update w_cline_height and w_cline_folded if the cursor line
3913 // was updated (saves a call to plines() later).
zeertzjqf4ccada2024-12-17 20:50:19 +01003914 if (in_curline)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003915 {
3916 curwin->w_cline_row = startrow;
3917 curwin->w_cline_height = wlv.row - startrow;
3918#ifdef FEAT_FOLDING
3919 curwin->w_cline_folded = FALSE;
3920#endif
3921 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3922 }
3923 break;
3924 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003925 }
3926
3927 // Show "extends" character from 'listchars' if beyond the line end and
3928 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003929 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003930 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003931 && wp->w_p_list
3932 && !wp->w_p_wrap
3933#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003934 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003935#endif
3936 && (
3937#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003938 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003939#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003940 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003942 || lcs_eol_one > 0
3943 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003944 || *wlv.p_extra != NUL))
3945#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003946 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003947#endif
3948 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003949 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003950 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003951 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003952 mb_c = c;
3953 if (enc_utf8 && utf_char2len(c) > 1)
3954 {
3955 mb_utf8 = TRUE;
3956 u8cc[0] = 0;
3957 c = 0xc0;
3958 }
3959 else
3960 mb_utf8 = FALSE;
3961 }
3962
3963#ifdef FEAT_SYN_HL
3964 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003965 if (wlv.draw_color_col)
3966 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003967
3968 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3969 // highlight the cursor position itself.
3970 // Also highlight the 'colorcolumn' if it is different than
3971 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003972 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3973 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003974 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003975 if (((wlv.draw_state == WL_LINE
3976 || wlv.draw_state == WL_BRI
3977 || wlv.draw_state == WL_SBR)
3978 && !lnum_in_visual_area
3979 && search_attr == 0
3980 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003981# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003982 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003983# endif
3984 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003985 {
3986 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3987 && lnum != wp->w_cursor.lnum)
3988 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003989 vcol_save_attr = wlv.char_attr;
3990 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3991 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003992 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003993 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003994 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003995 vcol_save_attr = wlv.char_attr;
3996 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003997 }
3998 }
3999#endif
4000
zeertzjq8fc6a1d2023-08-20 18:12:54 +02004001 if (wlv.draw_state == WL_LINE)
4002 vcol_prev = wlv.vcol;
4003
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004004 // Store character to be displayed.
4005 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02004006 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004007 {
4008 // Store the character.
4009#if defined(FEAT_RIGHTLEFT)
4010 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
4011 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00004012 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004013 --wlv.off;
4014 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004015 }
4016#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004017 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004018 if (enc_dbcs == DBCS_JPNU)
4019 {
4020 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004021 ScreenLines[wlv.off] = 0x8e;
4022 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004023 }
4024 else if (enc_utf8)
4025 {
4026 if (mb_utf8)
4027 {
4028 int i;
4029
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004030 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004031 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004032 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004033 for (i = 0; i < Screen_mco; ++i)
4034 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004035 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004036 if (u8cc[i] == 0)
4037 break;
4038 }
4039 }
4040 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004041 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004042 }
4043 if (multi_attr)
4044 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004045 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004046 multi_attr = 0;
4047 }
4048 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01004049 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004050
zeertzjqdb54e982023-09-21 16:33:09 +02004051 if (wlv.draw_state > WL_NR
4052#ifdef FEAT_DIFF
4053 && wlv.filler_todo <= 0
4054#endif
4055 )
4056 ScreenCols[wlv.off] = wlv.vcol;
4057 else
4058 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01004059
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004060 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4061 {
4062 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004063 ++wlv.off;
4064 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004065 if (enc_utf8)
4066 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004067 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004068 else
4069 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004070 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02004071
Bram Moolenaar1306b362022-08-06 15:59:06 +01004072 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004073#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004074 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004075#endif
4076 )
zeertzjqdb54e982023-09-21 16:33:09 +02004077 ScreenCols[wlv.off] = ++wlv.vcol;
4078 else
4079 ScreenCols[wlv.off] = -1;
4080
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004081 // When "wlv.tocol" is halfway a character, set it to the end
4082 // of the character, otherwise highlighting won't stop.
4083 if (wlv.tocol == wlv.vcol)
4084 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01004085
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004086#ifdef FEAT_RIGHTLEFT
4087 if (wp->w_p_rl)
4088 {
4089 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004090 --wlv.off;
4091 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004092 }
4093#endif
4094 }
4095#ifdef FEAT_RIGHTLEFT
4096 if (wp->w_p_rl)
4097 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004098 --wlv.off;
4099 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004100 }
4101 else
4102#endif
4103 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004104 ++wlv.off;
4105 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004106 }
4107 }
4108#ifdef FEAT_CONCEAL
4109 else if (wp->w_p_cole > 0 && is_concealing)
4110 {
zeertzjq010e1532024-03-14 18:22:17 +01004111 int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1;
4112
zeertzjqb557f482023-08-22 22:07:34 +02004113 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004114 ++wlv.vcol_off_co;
zeertzjq010e1532024-03-14 18:22:17 +01004115 if (concealed_wide)
4116 {
4117 // When a double-width char is concealed,
4118 // need to advance one more virtual column.
4119 ++wlv.vcol;
4120 ++wlv.vcol_off_co;
4121 }
4122
Bram Moolenaar1306b362022-08-06 15:59:06 +01004123 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004124 wlv.vcol_off_co += wlv.n_extra;
zeertzjq010e1532024-03-14 18:22:17 +01004125
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004126 if (wp->w_p_wrap)
4127 {
4128 // Special voodoo required if 'wrap' is on.
4129 //
4130 // Advance the column indicator to force the line
4131 // drawing to wrap early. This will make the line
4132 // take up the same screen space when parts are concealed,
4133 // so that cursor line computations aren't messed up.
4134 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004135 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004136 // trailing junk to be written out of the screen line
4137 // we are building, 'boguscols' keeps track of the number
4138 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004139 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004140 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004141 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004142# ifdef FEAT_RIGHTLEFT
4143 if (wp->w_p_rl)
4144 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004145 wlv.col -= wlv.n_extra;
4146 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004147 }
4148 else
4149# endif
4150 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004151 wlv.col += wlv.n_extra;
4152 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004153 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004154 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004155 n_attr = 0;
4156 }
4157
zeertzjq010e1532024-03-14 18:22:17 +01004158 if (concealed_wide)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004159 {
4160 // Need to fill two screen columns.
4161# ifdef FEAT_RIGHTLEFT
4162 if (wp->w_p_rl)
4163 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004164 --wlv.boguscols;
4165 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004166 }
4167 else
4168# endif
4169 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004170 ++wlv.boguscols;
4171 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004172 }
4173 }
4174
4175# ifdef FEAT_RIGHTLEFT
4176 if (wp->w_p_rl)
4177 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004178 --wlv.boguscols;
4179 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004180 }
4181 else
4182# endif
4183 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004184 ++wlv.boguscols;
4185 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004186 }
4187 }
4188 else
4189 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004190 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004191 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004192 wlv.vcol += wlv.n_extra;
4193 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004194 n_attr = 0;
4195 }
4196 }
4197
4198 }
4199#endif // FEAT_CONCEAL
4200 else
zeertzjqb557f482023-08-22 22:07:34 +02004201 --skip_cells;
4202
4203 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4204 {
4205 wlv.vcol += skipped_cells;
4206 skipped_cells = 0;
4207 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004208
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004209 // Only advance the "wlv.vcol" when after the 'number' or
4210 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004211 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004212#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004213 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004214#endif
4215 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004216 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004217
4218#ifdef FEAT_SYN_HL
4219 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004220 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004221#endif
4222
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004223 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004224 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4225 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004226
4227 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004228 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004229 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004230 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004231 if (wlv.n_attr_skip > 0)
4232 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004233
4234 // At end of screen line and there is more to come: Display the line
4235 // so far. If there is no more to display it is caught above.
4236 if ((
4237#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004238 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004239#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004240 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004241 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004242 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004243#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004244 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004245#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004246#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004247 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004248 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004249#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004250 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004251 && lcs_eol_one != -1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004252 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4253 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004254 )
4255 {
4256#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004257 wlv.col -= wlv.boguscols;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004258 // Apply 'cursorline' and 'wincolor' highlight.
4259 if (wlv.boguscols != 0 && (
4260# ifdef LINE_ATTR
4261 wlv.line_attr != 0 ||
4262# endif
4263 wlv.win_attr != 0
4264 )
4265 )
4266 {
4267 int attr = wlv.win_attr;
4268# ifdef LINE_ATTR
4269 if (wlv.line_attr != 0)
4270 attr = hl_combine_attr(attr, wlv.line_attr);
4271# endif
4272 while ((
4273# ifdef FEAT_RIGHTLEFT
4274 wp->w_p_rl ? wlv.col >= 0 :
4275# endif
4276 wlv.col < wp->w_width))
4277 {
4278 ScreenLines[wlv.off] = ' ';
4279 if (enc_utf8)
4280 ScreenLinesUC[wlv.off] = 0;
4281 ScreenAttrs[wlv.off] = attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01004282 ScreenCols[wlv.off] = wlv.vcol - 1;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004283# ifdef FEAT_RIGHTLEFT
4284 if (wp->w_p_rl)
4285 {
4286 wlv.off--;
4287 wlv.col--;
4288 wlv.boguscols++;
4289 }
4290 else
4291# endif
4292 {
4293 wlv.off++;
4294 wlv.col++;
4295 wlv.boguscols--;
4296 }
4297 }
4298 }
zeertzjqd0c1b772024-03-16 15:03:33 +01004299 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar75008662022-10-04 22:40:56 +01004300 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004301 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004302 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004303#else
zeertzjqd0c1b772024-03-16 15:03:33 +01004304 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004305#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004306 ++wlv.row;
4307 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004308
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004309 // When not wrapping and finished diff lines, break here.
4310 if (!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004311#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004312 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004313#endif
4314#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004315 && !text_prop_above
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004316 && !text_prop_follows
Bram Moolenaar877151b2022-10-11 15:29:50 +01004317#endif
4318 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004319 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004320#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004321 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004322 {
4323 // do not output more of the line, only the "below" prop
John Marriottf51ff962024-06-02 19:44:11 +02004324 ptr = line + (size_t)ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004325# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004326 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004327# endif
4328 }
4329#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004330
4331 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004332 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004333#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004334 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004335#endif
4336 )
4337 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004338 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4339 draw_vsep_win(wp, wlv.row);
4340 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004341 }
4342
4343 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004344 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004345 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004346 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004347 break;
4348 }
4349
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004350 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004351#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004352 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004353#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004354#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004355 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004356#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004357 && wp->w_width == Columns)
4358 {
4359 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004360 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004361
4362 // Special trick to make copy/paste of wrapped lines work with
4363 // xterm/screen: write an extra character beyond the end of
4364 // the line. This will work with all terminal types
4365 // (regardless of the xn,am settings).
4366 // Only do this on a fast tty.
4367 // Only do this if the cursor is on the current line
4368 // (something has been written in it).
4369 // Don't do this for the GUI.
4370 // Don't do this for double-width characters.
4371 // Don't do this for a window not at the right screen border.
4372 if (p_tf
4373#ifdef FEAT_GUI
4374 && !gui.in_use
4375#endif
4376 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004377 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4378 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004379 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004380 || (*mb_off2cells)(
4381 LineOffset[wlv.screen_row - 1]
4382 + (int)Columns - 2,
4383 LineOffset[wlv.screen_row]
4384 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004385 {
4386 // First make sure we are at the end of the screen line,
4387 // then output the same character again to let the
4388 // terminal know about the wrap. If the terminal doesn't
4389 // auto-wrap, we overwrite the character.
4390 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004391 screen_char(LineOffset[wlv.screen_row - 1]
4392 + (unsigned)Columns - 1,
4393 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004394
4395 // When there is a multi-byte character, just output a
4396 // space to keep it simple.
4397 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004398 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004399 out_char(' ');
4400 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004401 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004402 + (Columns - 1)]);
4403 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004404 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004405 screen_start(); // don't know where cursor is now
4406 }
4407 }
4408
Bram Moolenaar1306b362022-08-06 15:59:06 +01004409 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004410
Bram Moolenaareed9d462021-02-15 20:38:25 +01004411 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004412#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004413 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004414# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004415 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004416# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004417 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004418 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004419#endif
4420#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004421 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004422 // When the filler lines are actually below the last line of the
4423 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004424 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004425 break;
4426#endif
4427 }
4428
4429 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004430#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004431 vim_free(text_props);
4432 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004433 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004434#endif
4435
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004436 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004437 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004438 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004439}