Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1 | /* 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 Moolenaar | e89aeed | 2022-08-22 13:00:16 +0100 | [diff] [blame] | 12 | * This is the middle level, drawscreen.c is the higher level and screen.c the |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 13 | * 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 |
| 23 | advance_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 |
| 37 | margin_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; |
zeertzjq | 86dc4f8 | 2024-09-14 10:37:17 +0200 | [diff] [blame] | 42 | static int prev_width1; |
| 43 | static int prev_width2; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 44 | static int prev_left_col; |
| 45 | static int prev_right_col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 46 | |
| 47 | int cur_col_off = win_col_off(wp); |
| 48 | int width1; |
| 49 | int width2; |
| 50 | |
zeertzjq | 86dc4f8 | 2024-09-14 10:37:17 +0200 | [diff] [blame] | 51 | 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 Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 56 | { |
| 57 | *right_col = prev_right_col; |
| 58 | *left_col = prev_left_col; |
| 59 | return; |
| 60 | } |
| 61 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 62 | *left_col = 0; |
| 63 | *right_col = width1; |
| 64 | |
zeertzjq | 59149f0 | 2024-09-14 10:40:29 +0200 | [diff] [blame] | 65 | if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 66 | *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; |
zeertzjq | 86dc4f8 | 2024-09-14 10:37:17 +0200 | [diff] [blame] | 74 | prev_width1 = width1; |
| 75 | prev_width2 = width2; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 76 | saved_w_virtcol = wp->w_virtcol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 77 | } |
| 78 | #endif |
| 79 | |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 80 | #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 Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 86 | // structure with variables passed between win_line() and other functions |
| 87 | typedef 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 Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 101 | int vcol_off_co; // offset for concealed characters |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 102 | #endif |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 103 | int vcol_off_tp; // offset for virtual text |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 104 | #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 Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 114 | int wcr_attr; // attributes from 'wincolor' |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 115 | #ifdef FEAT_SYN_HL |
| 116 | int cul_attr; // set when 'cursorline' active |
| 117 | #endif |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 118 | #ifdef LINE_ATTR |
| 119 | int line_attr; // for the whole line, includes 'cursorline' |
| 120 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 121 | |
| 122 | int screen_line_flags; // flags for screen_line() |
| 123 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 124 | int fromcol; // start of inverting |
| 125 | int tocol; // end of inverting |
| 126 | |
| 127 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 128 | long vcol_sbr; // virtual column after showbreak |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 129 | int need_showbreak; // overlong line, skipping first x chars |
| 130 | int dont_use_showbreak; // do not use 'showbreak' |
| 131 | #endif |
Bram Moolenaar | ec5e148 | 2022-09-21 16:38:13 +0100 | [diff] [blame] | 132 | #ifdef FEAT_PROP_POPUP |
| 133 | int text_prop_above_count; |
| 134 | #endif |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 135 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 136 | // 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 Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 144 | char_u *p_extra_free; // p_extra buffer that needs to be freed |
Bram Moolenaar | ee28c70 | 2022-11-17 14:56:00 +0000 | [diff] [blame] | 145 | int extra_attr; // attributes for p_extra, should be combined |
| 146 | // with win_attr if needed |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 147 | int n_attr_skip; // chars to skip before using extra_attr |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 148 | int c_extra; // extra chars, all the same |
| 149 | int c_final; // final char, mandatory if set |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 150 | int extra_for_textprop; // n_extra set for textprop |
| 151 | int start_extra_for_textprop; // extra_for_textprop was just set |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 152 | |
| 153 | // saved "extra" items for when draw_state becomes WL_LINE (again) |
| 154 | int saved_n_extra; |
| 155 | char_u *saved_p_extra; |
zeertzjq | 58e1e01 | 2023-06-04 18:46:28 +0100 | [diff] [blame] | 156 | char_u *saved_p_extra_free; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 157 | int saved_extra_attr; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 158 | int saved_n_attr_skip; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 159 | int saved_extra_for_textprop; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 160 | int saved_c_extra; |
| 161 | int saved_c_final; |
| 162 | int saved_char_attr; |
| 163 | |
Bram Moolenaar | 2b1ddf1 | 2022-09-21 11:21:57 +0100 | [diff] [blame] | 164 | char_u extra[NUMBUFLEN + MB_MAXBYTES]; |
| 165 | // "%ld " and 'fdc' must fit in here, as well |
| 166 | // any text sign |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 167 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 168 | #ifdef FEAT_DIFF |
| 169 | hlf_T diff_hlf; // type of diff highlighting |
| 170 | #endif |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 171 | 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 Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 176 | #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 Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 181 | } 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 Tournoij | 7904fa4 | 2022-10-04 16:28:45 +0100 | [diff] [blame] | 185 | #define WL_CMDLINE (WL_START + 1) // cmdline window column |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 186 | #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 Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 209 | #if defined(FEAT_SIGNS) || defined(FEAT_FOLDING) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 210 | /* |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 211 | * Return TRUE if CursorLineSign highlight is to be used. |
| 212 | */ |
| 213 | static int |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 214 | use_cursor_line_highlight(win_T *wp, linenr_T lnum) |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 215 | { |
| 216 | return wp->w_p_cul |
| 217 | && lnum == wp->w_cursor.lnum |
| 218 | && (wp->w_p_culopt_flags & CULOPT_NBR); |
| 219 | } |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 220 | #endif |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 221 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 222 | |
| 223 | #ifdef FEAT_FOLDING |
| 224 | /* |
| 225 | * Setup for drawing the 'foldcolumn', if there is one. |
| 226 | */ |
| 227 | static void |
| 228 | handle_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 Lakshmanan | 465de3a | 2022-12-26 12:50:04 +0000 | [diff] [blame] | 238 | if (wlv->p_extra_free == NULL) |
| 239 | return; |
| 240 | |
| 241 | wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free, |
zeertzjq | 58e1e01 | 2023-06-04 18:46:28 +0100 | [diff] [blame] | 242 | wp, FALSE, wlv->lnum); |
Yegappan Lakshmanan | 465de3a | 2022-12-26 12:50:04 +0000 | [diff] [blame] | 243 | 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 Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 251 | } |
| 252 | #endif |
| 253 | |
| 254 | #ifdef FEAT_SIGNS |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 255 | /* |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 256 | * 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 Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 259 | * Otherwise the sign is going to be displayed in the sign column. |
| 260 | */ |
| 261 | static void |
| 262 | get_sign_display_info( |
| 263 | int nrcol, |
| 264 | win_T *wp, |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 265 | winlinevars_T *wlv) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 266 | { |
| 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 Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 273 | wlv->c_extra = ' '; |
| 274 | wlv->c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 275 | if (nrcol) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 276 | wlv->n_extra = number_width(wp) + 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 277 | else |
| 278 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 279 | if (use_cursor_line_highlight(wp, wlv->lnum)) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 280 | wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS)); |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 281 | else |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 282 | wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 283 | wlv->n_extra = 2; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 284 | } |
| 285 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 286 | if (wlv->row == wlv->startrow |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 287 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 288 | + wlv->filler_lines && wlv->filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 289 | #endif |
| 290 | ) |
| 291 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 292 | text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 293 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 294 | icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 295 | if (gui.in_use && icon_sign != 0) |
| 296 | { |
| 297 | // Use the image in this position. |
| 298 | if (nrcol) |
| 299 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 300 | wlv->c_extra = NUL; |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 301 | wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), |
| 302 | "%-*c ", number_width(wp), SIGN_BYTE); |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 303 | wlv->p_extra = wlv->extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 304 | } |
| 305 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 306 | wlv->c_extra = SIGN_BYTE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 307 | # ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 308 | if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum) |
| 309 | > 1)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 310 | { |
| 311 | if (nrcol) |
| 312 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 313 | wlv->c_extra = NUL; |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 314 | wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), |
| 315 | "%-*c ", number_width(wp), MULTISIGN_BYTE); |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 316 | wlv->p_extra = wlv->extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 317 | } |
| 318 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 319 | wlv->c_extra = MULTISIGN_BYTE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 320 | } |
| 321 | # endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 322 | wlv->c_final = NUL; |
| 323 | wlv->char_attr = icon_sign; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 324 | } |
| 325 | else |
| 326 | # endif |
| 327 | if (text_sign != 0) |
| 328 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 329 | wlv->p_extra = wlv->sattr.sat_text; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 330 | if (wlv->p_extra != NULL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 331 | { |
| 332 | if (nrcol) |
| 333 | { |
Bram Moolenaar | 2b1ddf1 | 2022-09-21 11:21:57 +0100 | [diff] [blame] | 334 | int width = number_width(wp) - 2; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 335 | |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 336 | 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 Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 340 | wlv->p_extra = wlv->extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 341 | } |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 342 | else |
| 343 | wlv->n_extra = (int)STRLEN(wlv->p_extra); |
| 344 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 345 | wlv->c_extra = NUL; |
| 346 | wlv->c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 347 | } |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 348 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 349 | if (use_cursor_line_highlight(wp, wlv->lnum) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 350 | && wlv->sattr.sat_culhl > 0) |
| 351 | wlv->char_attr = wlv->sattr.sat_culhl; |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 352 | else |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 353 | wlv->char_attr = wlv->sattr.sat_texthl; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | } |
| 357 | #endif |
| 358 | |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 359 | /* |
| 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 |
| 364 | handle_lnum_col( |
| 365 | win_T *wp, |
| 366 | winlinevars_T *wlv, |
| 367 | int sign_present UNUSED, |
Bram Moolenaar | 3172423 | 2022-09-20 20:25:36 +0100 | [diff] [blame] | 368 | int num_attr UNUSED) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 369 | { |
Bram Moolenaar | 35b251d | 2022-10-06 20:18:16 +0100 | [diff] [blame] | 370 | int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL; |
Bram Moolenaar | b99e6e6 | 2022-10-17 18:55:03 +0100 | [diff] [blame] | 371 | int lnum_row = wlv->startrow + wlv->filler_lines |
| 372 | #ifdef FEAT_PROP_POPUP |
| 373 | + wlv->text_prop_above_count |
| 374 | #endif |
| 375 | ; |
Bram Moolenaar | 35b251d | 2022-10-06 20:18:16 +0100 | [diff] [blame] | 376 | |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 377 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | b99e6e6 | 2022-10-17 18:55:03 +0100 | [diff] [blame] | 378 | && (wlv->row <= lnum_row || !has_cpo_n) |
Bram Moolenaar | 3725116 | 2022-10-06 20:48:00 +0100 | [diff] [blame] | 379 | // 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 Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 386 | { |
| 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 Moolenaar | ec5e148 | 2022-09-21 16:38:13 +0100 | [diff] [blame] | 397 | // When there are text properties above the line put the line number |
| 398 | // below them. |
Bram Moolenaar | b99e6e6 | 2022-10-17 18:55:03 +0100 | [diff] [blame] | 399 | if (wlv->row == lnum_row |
zeertzjq | 88bb3e0 | 2023-05-02 20:52:59 +0100 | [diff] [blame] | 400 | && (wp->w_skipcol == 0 || wlv->row > 0 |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 401 | || (wp->w_p_nu && wp->w_p_rnu))) |
Bram Moolenaar | ec5e148 | 2022-09-21 16:38:13 +0100 | [diff] [blame] | 402 | { |
| 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 Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 421 | vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), fmt, number_width(wp), num); |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 422 | if (wp->w_skipcol > 0 && wlv->startrow == 0) |
Bram Moolenaar | ec5e148 | 2022-09-21 16:38:13 +0100 | [diff] [blame] | 423 | 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 Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 446 | } |
| 447 | else |
| 448 | { |
Bram Moolenaar | ec5e148 | 2022-09-21 16:38:13 +0100 | [diff] [blame] | 449 | wlv->c_extra = ' '; |
| 450 | wlv->c_final = NUL; |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 451 | } |
| 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) |
| 464 | && (wlv->row == wlv->startrow + wlv->filler_lines |
| 465 | || (wlv->row > wlv->startrow + wlv->filler_lines |
| 466 | && (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 Moolenaar | 2d2e25b | 2022-09-20 21:09:42 +0100 | [diff] [blame] | 484 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 485 | #ifdef FEAT_LINEBREAK |
| 486 | static void |
| 487 | handle_breakindent(win_T *wp, winlinevars_T *wlv) |
| 488 | { |
| 489 | if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1 |
Bram Moolenaar | 9466fb8 | 2022-10-11 14:54:42 +0100 | [diff] [blame] | 490 | && *get_showbreak_value(wp) != NUL) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 491 | // 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 |
zeertzjq | 588f20d | 2023-12-05 15:47:09 +0100 | [diff] [blame] | 502 | if (wp->w_p_bri && (wlv->row > wlv->startrow |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 503 | # ifdef FEAT_DIFF |
zeertzjq | 588f20d | 2023-12-05 15:47:09 +0100 | [diff] [blame] | 504 | + wlv->filler_lines |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 505 | # endif |
zeertzjq | 588f20d | 2023-12-05 15:47:09 +0100 | [diff] [blame] | 506 | || wlv->need_showbreak) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 507 | # 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 | } |
zeertzjq | 2362772 | 2023-12-27 19:08:53 +0100 | [diff] [blame] | 528 | |
| 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 Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 534 | // 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 | } |
zeertzjq | 7e4f62a | 2023-12-28 23:19:52 +0100 | [diff] [blame] | 539 | |
| 540 | if (wp->w_skipcol > 0 && wlv->startrow == 0 && wp->w_p_wrap |
| 541 | && wp->w_briopt_sbr) |
| 542 | wlv->need_showbreak = FALSE; |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | #endif |
| 546 | |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 547 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 548 | static void |
| 549 | handle_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 Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 584 | wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr); |
Bram Moolenaar | f578ca2 | 2023-06-10 19:40:30 +0100 | [diff] [blame] | 585 | |
| 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 Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 590 | // Correct end of highlighted area for 'showbreak', |
| 591 | // required when 'linebreak' is also set. |
| 592 | if (wlv->tocol == wlv->vcol) |
zeertzjq | df23d7f | 2024-02-09 18:14:12 +0100 | [diff] [blame] | 593 | wlv->tocol = wlv->vcol_sbr; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 594 | // 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 | } |
zeertzjq | 7e4f62a | 2023-12-28 23:19:52 +0100 | [diff] [blame] | 602 | |
| 603 | if (wp->w_skipcol == 0 || wlv->startrow > 0 || !wp->w_p_wrap |
| 604 | || !wp->w_briopt_sbr) |
| 605 | wlv->need_showbreak = FALSE; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 606 | # endif |
| 607 | } |
| 608 | #endif |
| 609 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 610 | #if defined(FEAT_PROP_POPUP) || defined(PROTO) |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 611 | /* |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 612 | * Return the cell size of virtual text after truncation. |
| 613 | */ |
| 614 | static int |
| 615 | textprop_size_after_trunc( |
| 616 | win_T *wp, |
| 617 | int flags, // TP_FLAG_ALIGN_* |
| 618 | int added, |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 619 | int padding, |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 620 | char_u *text, |
| 621 | int *n_used_ptr) |
| 622 | { |
| 623 | int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE)) |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 624 | ? wp->w_width - win_col_off(wp) : added; |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 625 | int strsize = 0; |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 626 | char_u *p; |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 627 | |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 628 | // if the remaining size is too small and 'wrap' is set we wrap anyway and |
Bram Moolenaar | 7e01746 | 2022-10-11 21:02:09 +0100 | [diff] [blame] | 629 | // use the next line |
| 630 | if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap) |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 631 | space += wp->w_width; |
Bram Moolenaar | 9466fb8 | 2022-10-11 14:54:42 +0100 | [diff] [blame] | 632 | if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE)) |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 633 | space -= padding; |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 634 | |
| 635 | for (p = text; *p != NUL; p += (*mb_ptr2len)(p)) |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 636 | { |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 637 | int clen = ptr2cells(p); |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 638 | |
| 639 | if (strsize + clen > space) |
| 640 | break; |
| 641 | strsize += clen; |
| 642 | } |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 643 | *n_used_ptr = (int)(p - text); |
| 644 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 645 | return strsize; |
| 646 | } |
| 647 | |
| 648 | /* |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 649 | * 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 Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 655 | */ |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 656 | int |
| 657 | text_prop_position( |
| 658 | win_T *wp, |
| 659 | textprop_T *tp, |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 660 | int vcol, // current text column |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 661 | int scr_col, // current screen column |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 662 | 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 Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 665 | int *n_attr_skip, // cells to skip attr, NULL if not used |
| 666 | int do_skip) // skip_cells is not zero |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 667 | { |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 668 | int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT); |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 669 | int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 670 | int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW); |
Bram Moolenaar | 1aeb3eb | 2023-01-01 14:04:51 +0000 | [diff] [blame] | 671 | int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 672 | int padding = tp->tp_col == MAXCOL && tp->tp_len > 1 |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 673 | ? tp->tp_len - 1 : 0; |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 674 | int col_with_padding = scr_col + (below ? 0 : padding); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 675 | int room = wp->w_width - col_with_padding; |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 676 | int before = room; // spaces before the text |
| 677 | int after = 0; // spaces after the text |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 678 | int n_used = *n_extra; |
| 679 | char_u *l = NULL; |
| 680 | int strsize = vim_strsize(*p_extra); |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 681 | int cells = wrap ? strsize : textprop_size_after_trunc(wp, |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 682 | tp->tp_flags, before, padding, *p_extra, &n_used); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 683 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 684 | if (wrap || right || above || below || padding > 0 || n_used < *n_extra) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 685 | { |
Bram Moolenaar | ccf2837 | 2022-10-10 21:10:03 +0100 | [diff] [blame] | 686 | int col_off = win_col_off(wp) - win_col_off2(wp); |
Bram Moolenaar | b84d565 | 2022-09-20 17:57:53 +0100 | [diff] [blame] | 687 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 688 | if (above) |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 689 | { |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 690 | before = 0; |
Bram Moolenaar | 79f8b84 | 2022-09-11 13:31:01 +0100 | [diff] [blame] | 691 | after = wp->w_width - cells - win_col_off(wp) - padding; |
Bram Moolenaar | 2354b66 | 2023-04-23 21:42:25 +0100 | [diff] [blame] | 692 | if (after < 0) |
| 693 | { |
| 694 | // text "above" has too much padding to fit |
| 695 | padding += after; |
| 696 | after = 0; |
| 697 | } |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 698 | } |
| 699 | else |
| 700 | { |
| 701 | // Right-align: fill with before |
| 702 | if (right) |
| 703 | before -= cells; |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 704 | |
| 705 | // Below-align: empty line add one character |
Bram Moolenaar | 7c02ad9 | 2022-11-29 21:37:13 +0000 | [diff] [blame] | 706 | if (below && vcol == 0 && col_with_padding == col_off |
| 707 | && wp->w_width - col_off == before) |
| 708 | col_with_padding += 1; |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 709 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 710 | if (before < 0 |
| 711 | || !(right || below) |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 712 | || (below ? (col_with_padding <= col_off || !wp->w_p_wrap) |
| 713 | : (n_used < *n_extra))) |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 714 | { |
Bram Moolenaar | 7e01746 | 2022-10-11 21:02:09 +0100 | [diff] [blame] | 715 | if (right && (wrap |
| 716 | || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap))) |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 717 | { |
| 718 | // right-align on next line instead of wrapping if possible |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 719 | before = wp->w_width - col_off - strsize + room; |
| 720 | if (before < 0) |
| 721 | before = 0; |
| 722 | else |
| 723 | n_used = *n_extra; |
| 724 | } |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 725 | else if (below && before > vcol && do_skip) |
| 726 | before -= vcol; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 727 | else |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 728 | before = 0; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 729 | } |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 730 | } |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 731 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 732 | // 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 Brabandt | f1cc4d5 | 2023-08-12 00:14:14 +0200 | [diff] [blame] | 742 | l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 743 | if (n_attr == NULL || l != NULL) |
| 744 | { |
| 745 | int off = 0; |
| 746 | |
| 747 | if (n_attr != NULL) |
| 748 | { |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 749 | vim_memset(l, ' ', before); |
| 750 | off += before; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 751 | 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 Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 761 | off = before + after + padding + n_used; |
| 762 | cells += before + after + padding; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 763 | } |
| 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-east | 4c42c7e | 2023-04-17 21:44:57 +0100 | [diff] [blame] | 772 | 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 Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 798 | lp -= (*mb_head_off)(l, lp); |
h-east | 4c42c7e | 2023-04-17 21:44:57 +0100 | [diff] [blame] | 799 | STRCPY(lp, cp); |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 800 | n_used = lp - l + 3 - before - padding; |
h-east | 4c42c7e | 2023-04-17 21:44:57 +0100 | [diff] [blame] | 801 | if (cp != buf) |
| 802 | vim_free(cp); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 803 | } |
| 804 | else |
| 805 | // change last character to '>' |
| 806 | *lp = '>'; |
| 807 | } |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 808 | else if (after > 0) |
| 809 | { |
| 810 | vim_memset(l + off, ' ', after); |
| 811 | l[off + after] = NUL; |
| 812 | } |
| 813 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 814 | *p_extra = l; |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 815 | *n_extra = n_used + before + after + padding; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 816 | *n_attr = mb_charlen(*p_extra); |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 817 | // n_attr_skip will not be decremented before draw_state is |
| 818 | // WL_LINE |
Christian Brabandt | f1cc4d5 | 2023-08-12 00:14:14 +0200 | [diff] [blame] | 819 | *n_attr_skip = before + (padding > 0 ? padding : 0); |
zeertzjq | 9352c28 | 2024-03-14 18:16:56 +0100 | [diff] [blame] | 820 | *n_attr -= *n_attr_skip; |
| 821 | if (above) |
| 822 | *n_attr -= after; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 823 | } |
| 824 | } |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 825 | } |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 826 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 827 | if (n_attr == NULL) |
| 828 | return cells; |
| 829 | return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 830 | } |
| 831 | #endif |
| 832 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 833 | /* |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 834 | * Call screen_line() using values from "wlv". |
Bram Moolenaar | 0937b9f | 2022-10-06 21:24:34 +0100 | [diff] [blame] | 835 | * Also takes care of putting "<<<" on the first line for 'smoothscroll' |
| 836 | * when 'showbreak' is not set. |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 837 | * When "clear_end" is TRUE clear until the end of the screen line. |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 838 | */ |
| 839 | static void |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 840 | wlv_screen_line(win_T *wp, winlinevars_T *wlv, int clear_end) |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 841 | { |
Bram Moolenaar | 0937b9f | 2022-10-06 21:24:34 +0100 | [diff] [blame] | 842 | if (wlv->row == 0 && wp->w_skipcol > 0 |
| 843 | #if defined(FEAT_LINEBREAK) |
Bram Moolenaar | 13cdde3 | 2022-10-15 14:07:48 +0100 | [diff] [blame] | 844 | // do not overwrite the 'showbreak' text with "<<<" |
Bram Moolenaar | 0937b9f | 2022-10-06 21:24:34 +0100 | [diff] [blame] | 845 | && *get_showbreak_value(wp) == NUL |
| 846 | #endif |
Bram Moolenaar | 13cdde3 | 2022-10-15 14:07:48 +0100 | [diff] [blame] | 847 | // do not overwrite the 'listchars' "precedes" text with "<<<" |
| 848 | && !(wp->w_p_list && wp->w_lcs_chars.prec != 0)) |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 849 | { |
| 850 | int off = (int)(current_ScreenLine - ScreenLines); |
zeertzjq | ecb87dd | 2023-06-03 19:45:06 +0100 | [diff] [blame] | 851 | int max_off = off + screen_Columns; |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 852 | int skip = 0; |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 853 | |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 854 | if (wp->w_p_nu && wp->w_p_rnu) |
| 855 | // Do not overwrite the line number, change "123 text" to |
Bram Moolenaar | f578ca2 | 2023-06-10 19:40:30 +0100 | [diff] [blame] | 856 | // "123<<<xt". |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 857 | 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 Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 864 | { |
zeertzjq | ecb87dd | 2023-06-03 19:45:06 +0100 | [diff] [blame] | 865 | 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 Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 869 | 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, |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 878 | clear_end ? wp->w_width : -wp->w_width, |
| 879 | wlv->vcol - 1, wlv->screen_line_flags); |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | /* |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 883 | * 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 |
| 887 | draw_screen_line(win_T *wp, winlinevars_T *wlv) |
| 888 | { |
| 889 | #ifdef FEAT_SYN_HL |
| 890 | long v; |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 891 | int wcol; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 892 | |
| 893 | // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. |
| 894 | if (wp->w_p_wrap) |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 895 | v = wlv->startrow == 0 ? wp->w_skipcol : 0; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 896 | else |
| 897 | v = wp->w_leftcol; |
| 898 | |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 899 | wcol = |
| 900 | # ifdef FEAT_RIGHTLEFT |
| 901 | wp->w_p_rl ? wp->w_width - wlv->col - 1 : |
| 902 | # endif |
| 903 | wlv->col; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 904 | // check if line ends before left margin |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 905 | if (wlv->vcol < v + wcol - win_col_off(wp)) |
| 906 | wlv->vcol = v + wcol - win_col_off(wp); |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 907 | # 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 Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 912 | # define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 913 | # else |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 914 | # define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 915 | # 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 Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 925 | || wlv->draw_color_col |
| 926 | # ifdef LINE_ATTR |
| 927 | || wlv->line_attr != 0 |
| 928 | # endif |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 929 | || wlv->win_attr != 0)) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 930 | { |
| 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 | |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 942 | while ( |
| 943 | # ifdef FEAT_RIGHTLEFT |
| 944 | wp->w_p_rl ? (wlv->col >= 0) : |
| 945 | # endif |
| 946 | (wlv->col < wp->w_width)) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 947 | { |
| 948 | ScreenLines[wlv->off] = ' '; |
| 949 | if (enc_utf8) |
| 950 | ScreenLinesUC[wlv->off] = 0; |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 951 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 952 | if (wlv->draw_color_col) |
| 953 | wlv->draw_color_col = advance_color_col( |
| 954 | VCOL_HLC, &wlv->color_cols); |
| 955 | |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 956 | int attr = wlv->win_attr; |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 957 | # ifdef LINE_ATTR |
zeertzjq | 9352c28 | 2024-03-14 18:16:56 +0100 | [diff] [blame] | 958 | if (wlv->line_attr != 0) |
| 959 | attr = hl_combine_attr(attr, wlv->line_attr); |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 960 | # endif |
zeertzjq | 9352c28 | 2024-03-14 18:16:56 +0100 | [diff] [blame] | 961 | 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)); |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 966 | 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 | } |
zeertzjq | deb2204 | 2024-03-17 19:44:30 +0100 | [diff] [blame] | 980 | ++wlv->vcol; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 981 | |
zeertzjq | deb2204 | 2024-03-17 19:44:30 +0100 | [diff] [blame] | 982 | if (VCOL_HLC > rightmost_vcol |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 983 | # ifdef LINE_ATTR |
| 984 | && wlv->line_attr == 0 |
| 985 | # endif |
| 986 | && wlv->win_attr == 0) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 987 | break; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | #endif |
| 991 | |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 992 | // 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 Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 997 | ++wlv->row; |
| 998 | ++wlv->screen_row; |
| 999 | } |
| 1000 | #undef VCOL_HLC |
| 1001 | |
| 1002 | /* |
| 1003 | * Start a screen line at column zero. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1004 | * When "save_extra" is TRUE save and reset n_extra, p_extra, etc. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1005 | */ |
| 1006 | static void |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1007 | win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1008 | { |
| 1009 | wlv->col = 0; |
| 1010 | wlv->off = (unsigned)(current_ScreenLine - ScreenLines); |
Christian Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 1011 | #ifdef FEAT_LINEBREAK |
| 1012 | wlv->need_lbr = FALSE; |
| 1013 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1014 | |
| 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 Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1026 | 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; |
zeertzjq | 58e1e01 | 2023-06-04 18:46:28 +0100 | [diff] [blame] | 1032 | vim_free(wlv->saved_p_extra_free); |
| 1033 | wlv->saved_p_extra_free = wlv->p_extra_free; |
| 1034 | wlv->p_extra_free = NULL; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 1035 | wlv->saved_extra_attr = wlv->extra_attr; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 1036 | wlv->saved_n_attr_skip = wlv->n_attr_skip; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 1037 | wlv->saved_extra_for_textprop = wlv->extra_for_textprop; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1038 | wlv->saved_c_extra = wlv->c_extra; |
| 1039 | wlv->saved_c_final = wlv->c_final; |
Christian Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 1040 | #ifdef FEAT_LINEBREAK |
| 1041 | wlv->need_lbr = TRUE; |
| 1042 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1043 | #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 Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 1053 | |
| 1054 | // these are not used until restored in win_line_continue() |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1055 | wlv->n_extra = 0; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 1056 | wlv->n_attr_skip = 0; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1057 | } |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1060 | /* |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1061 | * Called when wlv->draw_state is set to WL_LINE. |
| 1062 | */ |
| 1063 | static void |
| 1064 | win_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 Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 1070 | wlv->saved_n_extra = 0; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1071 | wlv->c_extra = wlv->saved_c_extra; |
| 1072 | wlv->c_final = wlv->saved_c_final; |
| 1073 | wlv->p_extra = wlv->saved_p_extra; |
zeertzjq | 58e1e01 | 2023-06-04 18:46:28 +0100 | [diff] [blame] | 1074 | vim_free(wlv->p_extra_free); |
| 1075 | wlv->p_extra_free = wlv->saved_p_extra_free; |
| 1076 | wlv->saved_p_extra_free = NULL; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 1077 | wlv->extra_attr = wlv->saved_extra_attr; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 1078 | wlv->n_attr_skip = wlv->saved_n_attr_skip; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 1079 | wlv->extra_for_textprop = wlv->saved_extra_for_textprop; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1080 | wlv->char_attr = wlv->saved_char_attr; |
| 1081 | } |
| 1082 | else |
| 1083 | wlv->char_attr = wlv->win_attr; |
| 1084 | } |
| 1085 | |
zeertzjq | b7acea1 | 2022-12-12 13:20:43 +0000 | [diff] [blame] | 1086 | #ifdef FEAT_SYN_HL |
| 1087 | static void |
| 1088 | apply_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 Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1116 | /* |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1117 | * Display line "lnum" of window "wp" on the screen. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1118 | * Start at row "startrow", stop when "endrow" is reached. |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1119 | * 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 Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1121 | * "spv" is used to store information for spell checking, kept between |
| 1122 | * sequential calls for the same window. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1123 | * wp->w_virtcol needs to be valid. |
| 1124 | * |
| 1125 | * Return the number of last row the line occupies. |
| 1126 | */ |
| 1127 | int |
| 1128 | win_line( |
| 1129 | win_T *wp, |
| 1130 | linenr_T lnum, |
| 1131 | int startrow, |
| 1132 | int endrow, |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1133 | int number_only, |
| 1134 | spellvars_T *spv UNUSED) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1135 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1136 | winlinevars_T wlv; // variables passed between functions |
| 1137 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1138 | int c = 0; // init for GCC |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1139 | long vcol_prev = -1; // "wlv.vcol" of previous character |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1140 | char_u *line; // current line |
| 1141 | char_u *ptr; // current position in "line" |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1142 | int in_curline = wp == curwin && lnum == curwin->w_cursor.lnum; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1143 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1144 | #ifdef FEAT_PROP_POPUP |
| 1145 | char_u *p_extra_free2 = NULL; // another p_extra to be freed |
| 1146 | #endif |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 1147 | #if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1148 | int in_linebreak = FALSE; // n_extra set for showing linebreak |
| 1149 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1150 | int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 1151 | int lcs_prec_todo = wp->w_lcs_chars.prec; |
| 1152 | // prec until it's been used |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1153 | |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 1154 | int n_attr = 0; // chars with special attr |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 1155 | 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 Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1158 | |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 1159 | 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 Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1163 | int fromcol_prev = -2; // start of inverting after cursor |
| 1164 | int noinvcur = FALSE; // don't invert the cursor |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1165 | int lnum_in_visual_area = FALSE; |
| 1166 | pos_T pos; |
| 1167 | long v; |
| 1168 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1169 | 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 Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1174 | int area_attr = 0; // attributes desired by highlighting |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 1175 | int search_attr = 0; // attributes desired by 'hlsearch' or |
| 1176 | // ComplMatchIns |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1177 | #ifdef FEAT_SYN_HL |
| 1178 | int vcol_save_attr = 0; // saved attr for 'cursorcolumn' |
| 1179 | int syntax_attr = 0; // attributes desired by syntax |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 1180 | int prev_syntax_col = -1; // column of prev_syntax_attr |
| 1181 | int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1182 | int has_syntax = FALSE; // this buffer has syntax highl. |
| 1183 | int save_did_emsg; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1184 | #endif |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 1185 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 1186 | int did_line = FALSE; // set to TRUE when line text done |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1187 | int text_prop_count; |
zeertzjq | 4e26a9a | 2023-12-03 17:50:47 +0100 | [diff] [blame] | 1188 | int last_textprop_text_idx = -1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1189 | 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 Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 1195 | int text_prop_attr_comb = 0; // text_prop_attr combined with |
| 1196 | // syntax_attr |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1197 | int text_prop_id = 0; // active property ID |
Bram Moolenaar | 4d2031f | 2022-08-05 20:03:55 +0100 | [diff] [blame] | 1198 | int text_prop_flags = 0; |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 1199 | int text_prop_above = FALSE; // first doing virtual text above |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 1200 | int text_prop_follows = FALSE; // another text prop to display |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 1201 | int saved_search_attr = 0; // search_attr to be used when n_extra |
| 1202 | // goes to zero |
Bram Moolenaar | 6eda17d | 2022-09-12 19:25:11 +0100 | [diff] [blame] | 1203 | int saved_area_attr = 0; // idem for area_attr |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 1204 | int reset_extra_attr = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1205 | #endif |
| 1206 | #ifdef FEAT_SPELL |
Bram Moolenaar | ae49aa8 | 2022-02-25 21:05:36 +0000 | [diff] [blame] | 1207 | int can_spell = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1208 | # 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 Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1215 | int cur_checked_col = 0; // checked column for current line |
| 1216 | #endif |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 1217 | int extra_check = FALSE; // has extra highlighting |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1218 | 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 Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1223 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1224 | int change_start = MAXCOL; // first col of changed area |
| 1225 | int change_end = -1; // last col of changed area |
| 1226 | #endif |
| 1227 | colnr_T trailcol = MAXCOL; // start of trailing spaces |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 1228 | colnr_T leadcol = 0; // start of leading spaces |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 1229 | int in_multispace = FALSE; // in multiple consecutive spaces |
| 1230 | int multispace_pos = 0; // position in lcs-multispace string |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1231 | #ifdef LINE_ATTR |
Bram Moolenaar | bf91584 | 2022-08-06 22:38:02 +0100 | [diff] [blame] | 1232 | int line_attr_save = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1233 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1234 | int sign_present = FALSE; |
James McCoy | a80aad7 | 2021-12-22 19:45:28 +0000 | [diff] [blame] | 1235 | int num_attr = 0; // attribute for the number column |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1236 | #ifdef FEAT_ARABIC |
| 1237 | int prev_c = 0; // previous Arabic character |
| 1238 | int prev_c1 = 0; // first composing char for prev_c |
| 1239 | #endif |
| 1240 | #if defined(LINE_ATTR) |
| 1241 | int did_line_attr = 0; |
| 1242 | #endif |
| 1243 | #ifdef FEAT_TERMINAL |
| 1244 | int get_term_attr = FALSE; |
| 1245 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1246 | |
Martin Tournoij | ba43e76 | 2022-10-13 22:12:15 +0100 | [diff] [blame] | 1247 | #if defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1248 | // margin columns for the screen line, needed for when 'cursorlineopt' |
| 1249 | // contains "screenline" |
| 1250 | int left_curline_col = 0; |
| 1251 | int right_curline_col = 0; |
| 1252 | #endif |
| 1253 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1254 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
| 1255 | int feedback_col = 0; |
| 1256 | int feedback_old_attr = -1; |
| 1257 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1258 | |
| 1259 | #if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) |
| 1260 | int match_conc = 0; // cchar for match functions |
Martin Tournoij | ba43e76 | 2022-10-13 22:12:15 +0100 | [diff] [blame] | 1261 | #endif |
| 1262 | #if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK) |
Bram Moolenaar | 0c359af | 2021-11-29 19:18:57 +0000 | [diff] [blame] | 1263 | int on_last_col = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1264 | #endif |
| 1265 | #ifdef FEAT_CONCEAL |
| 1266 | int syntax_flags = 0; |
| 1267 | int syntax_seqnr = 0; |
| 1268 | int prev_syntax_id = 0; |
| 1269 | int conceal_attr = HL_ATTR(HLF_CONCEAL); |
| 1270 | int is_concealing = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1271 | int did_wcol = FALSE; |
| 1272 | int old_boguscols = 0; |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 1273 | # define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1274 | # define FIX_FOR_BOGUSCOLS \ |
| 1275 | { \ |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 1276 | wlv.n_extra += wlv.vcol_off_co; \ |
| 1277 | wlv.vcol -= wlv.vcol_off_co; \ |
| 1278 | wlv.vcol_off_co = 0; \ |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1279 | wlv.col -= wlv.boguscols; \ |
| 1280 | old_boguscols = wlv.boguscols; \ |
| 1281 | wlv.boguscols = 0; \ |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1282 | } |
| 1283 | #else |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 1284 | # define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1285 | #endif |
| 1286 | |
| 1287 | if (startrow > endrow) // past the end already! |
| 1288 | return startrow; |
| 1289 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1290 | CLEAR_FIELD(wlv); |
| 1291 | |
| 1292 | wlv.lnum = lnum; |
| 1293 | wlv.startrow = startrow; |
| 1294 | wlv.row = startrow; |
| 1295 | wlv.screen_row = wlv.row + W_WINROW(wp); |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1296 | wlv.fromcol = -10; |
| 1297 | wlv.tocol = MAXCOL; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1298 | #ifdef FEAT_LINEBREAK |
| 1299 | wlv.vcol_sbr = -1; |
| 1300 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1301 | |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1302 | if (number_only == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1303 | { |
| 1304 | // To speed up the loop below, set extra_check when there is linebreak, |
| 1305 | // trailing white space and/or syntax processing to be done. |
| 1306 | #ifdef FEAT_LINEBREAK |
| 1307 | extra_check = wp->w_p_lbr; |
| 1308 | #endif |
| 1309 | #ifdef FEAT_SYN_HL |
| 1310 | if (syntax_present(wp) && !wp->w_s->b_syn_error |
| 1311 | # ifdef SYN_TIME_LIMIT |
| 1312 | && !wp->w_s->b_syn_slow |
| 1313 | # endif |
| 1314 | ) |
| 1315 | { |
| 1316 | // Prepare for syntax highlighting in this line. When there is an |
| 1317 | // error, stop syntax highlighting. |
| 1318 | save_did_emsg = did_emsg; |
| 1319 | did_emsg = FALSE; |
| 1320 | syntax_start(wp, lnum); |
| 1321 | if (did_emsg) |
| 1322 | wp->w_s->b_syn_error = TRUE; |
| 1323 | else |
| 1324 | { |
| 1325 | did_emsg = save_did_emsg; |
| 1326 | #ifdef SYN_TIME_LIMIT |
| 1327 | if (!wp->w_s->b_syn_slow) |
| 1328 | #endif |
| 1329 | { |
| 1330 | has_syntax = TRUE; |
| 1331 | extra_check = TRUE; |
| 1332 | } |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | // Check for columns to display for 'colorcolumn'. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1337 | wlv.color_cols = wp->w_p_cc_cols; |
| 1338 | if (wlv.color_cols != NULL) |
| 1339 | wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1340 | #endif |
| 1341 | |
| 1342 | #ifdef FEAT_TERMINAL |
| 1343 | if (term_show_buffer(wp->w_buffer)) |
| 1344 | { |
| 1345 | extra_check = TRUE; |
| 1346 | get_term_attr = TRUE; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1347 | wlv.win_attr = term_get_attr(wp, lnum, -1); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1348 | } |
| 1349 | #endif |
| 1350 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1351 | // handle Visual active in this window |
| 1352 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 1353 | { |
Bram Moolenaar | 14285cb | 2020-03-27 20:58:37 +0100 | [diff] [blame] | 1354 | pos_T *top, *bot; |
| 1355 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1356 | if (LTOREQ_POS(curwin->w_cursor, VIsual)) |
| 1357 | { |
| 1358 | // Visual is after curwin->w_cursor |
| 1359 | top = &curwin->w_cursor; |
| 1360 | bot = &VIsual; |
| 1361 | } |
| 1362 | else |
| 1363 | { |
| 1364 | // Visual is before curwin->w_cursor |
| 1365 | top = &VIsual; |
| 1366 | bot = &curwin->w_cursor; |
| 1367 | } |
| 1368 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
| 1369 | if (VIsual_mode == Ctrl_V) |
| 1370 | { |
| 1371 | // block mode |
| 1372 | if (lnum_in_visual_area) |
| 1373 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1374 | wlv.fromcol = wp->w_old_cursor_fcol; |
| 1375 | wlv.tocol = wp->w_old_cursor_lcol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | else |
| 1379 | { |
| 1380 | // non-block mode |
| 1381 | if (lnum > top->lnum && lnum <= bot->lnum) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1382 | wlv.fromcol = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1383 | else if (lnum == top->lnum) |
| 1384 | { |
| 1385 | if (VIsual_mode == 'V') // linewise |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1386 | wlv.fromcol = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1387 | else |
| 1388 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1389 | getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1390 | if (gchar_pos(top) == NUL) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1391 | wlv.tocol = wlv.fromcol + 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1392 | } |
| 1393 | } |
| 1394 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 1395 | { |
| 1396 | if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0) |
| 1397 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1398 | wlv.fromcol = -10; |
| 1399 | wlv.tocol = MAXCOL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1400 | } |
| 1401 | else if (bot->col == MAXCOL) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1402 | wlv.tocol = MAXCOL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1403 | else |
| 1404 | { |
| 1405 | pos = *bot; |
| 1406 | if (*p_sel == 'e') |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1407 | getvvcol(wp, &pos, (colnr_T *)&wlv.tocol, |
| 1408 | NULL, NULL); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1409 | else |
| 1410 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1411 | getvvcol(wp, &pos, NULL, NULL, |
| 1412 | (colnr_T *)&wlv.tocol); |
| 1413 | ++wlv.tocol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1414 | } |
| 1415 | } |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | // Check if the character under the cursor should not be inverted |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1420 | if (!highlight_match && in_curline |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1421 | #ifdef FEAT_GUI |
| 1422 | && !gui.in_use |
| 1423 | #endif |
| 1424 | ) |
| 1425 | noinvcur = TRUE; |
| 1426 | |
| 1427 | // if inverting in this line set area_highlighting |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1428 | if (wlv.fromcol >= 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1429 | { |
| 1430 | area_highlighting = TRUE; |
| 1431 | vi_attr = HL_ATTR(HLF_V); |
| 1432 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
| 1433 | if ((clip_star.available && !clip_star.owned |
| 1434 | && clip_isautosel_star()) |
| 1435 | || (clip_plus.available && !clip_plus.owned |
| 1436 | && clip_isautosel_plus())) |
| 1437 | vi_attr = HL_ATTR(HLF_VNC); |
| 1438 | #endif |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | // handle 'incsearch' and ":s///c" highlighting |
| 1443 | else if (highlight_match |
| 1444 | && wp == curwin |
| 1445 | && lnum >= curwin->w_cursor.lnum |
| 1446 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 1447 | { |
| 1448 | if (lnum == curwin->w_cursor.lnum) |
| 1449 | getvcol(curwin, &(curwin->w_cursor), |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1450 | (colnr_T *)&wlv.fromcol, NULL, NULL); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1451 | else |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1452 | wlv.fromcol = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1453 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 1454 | { |
| 1455 | pos.lnum = lnum; |
| 1456 | pos.col = search_match_endcol; |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1457 | getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1458 | } |
| 1459 | else |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1460 | wlv.tocol = MAXCOL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1461 | // do at least one character; happens when past end of line |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1462 | if (wlv.fromcol == wlv.tocol && search_match_endcol) |
| 1463 | wlv.tocol = wlv.fromcol + 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1464 | area_highlighting = TRUE; |
| 1465 | vi_attr = HL_ATTR(HLF_I); |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1470 | wlv.filler_lines = diff_check(wp, lnum); |
| 1471 | if (wlv.filler_lines < 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1472 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1473 | if (wlv.filler_lines == -1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1474 | { |
| 1475 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1476 | wlv.diff_hlf = HLF_ADD; // added line |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1477 | else if (change_start == 0) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1478 | wlv.diff_hlf = HLF_TXD; // changed text |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1479 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1480 | wlv.diff_hlf = HLF_CHD; // changed line |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1481 | } |
| 1482 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1483 | wlv.diff_hlf = HLF_ADD; // added line |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1484 | wlv.filler_lines = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1485 | area_highlighting = TRUE; |
| 1486 | } |
| 1487 | if (lnum == wp->w_topline) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1488 | wlv.filler_lines = wp->w_topfill; |
| 1489 | wlv.filler_todo = wlv.filler_lines; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1490 | #endif |
| 1491 | |
| 1492 | #ifdef FEAT_SIGNS |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1493 | sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr); |
James McCoy | a80aad7 | 2021-12-22 19:45:28 +0000 | [diff] [blame] | 1494 | if (sign_present) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1495 | num_attr = wlv.sattr.sat_numhl; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1496 | #endif |
| 1497 | |
| 1498 | #ifdef LINE_ATTR |
| 1499 | # ifdef FEAT_SIGNS |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1500 | // If this line has a sign with line highlighting set wlv.line_attr. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1501 | if (sign_present) |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1502 | wlv.line_attr = wlv.sattr.sat_linehl; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1503 | # endif |
| 1504 | # if defined(FEAT_QUICKFIX) |
| 1505 | // Highlight the current line in the quickfix window. |
| 1506 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1507 | wlv.line_attr = HL_ATTR(HLF_QFL); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1508 | # endif |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1509 | if (wlv.line_attr != 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1510 | area_highlighting = TRUE; |
| 1511 | #endif |
| 1512 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1513 | #ifdef FEAT_SPELL |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1514 | if (spv->spv_has_spell && number_only == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1515 | { |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1516 | // Prepare for spell checking. |
| 1517 | extra_check = TRUE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1518 | |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1519 | // When a word wrapped from the previous line the start of the |
| 1520 | // current line is valid. |
| 1521 | if (lnum == spv->spv_checked_lnum) |
| 1522 | cur_checked_col = spv->spv_checked_col; |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 1523 | // Previous line was not spell checked, check for capital. This happens |
| 1524 | // for the first line in an updated region or after a closed fold. |
| 1525 | if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0)) |
| 1526 | spv->spv_cap_col = 0; |
| 1527 | else if (lnum != spv->spv_capcol_lnum) |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1528 | spv->spv_cap_col = -1; |
| 1529 | spv->spv_checked_lnum = 0; |
| 1530 | |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1531 | // Get the start of the next line, so that words that wrap to the |
| 1532 | // next line are found too: "et<line-break>al.". |
| 1533 | // Trick: skip a few chars for C/shell/Vim comments |
| 1534 | nextline[SPWORDLEN] = NUL; |
| 1535 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 1536 | { |
| 1537 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 1538 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 1539 | } |
| 1540 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 1541 | |
| 1542 | // If current line is empty, check first word in next line for capital. |
| 1543 | ptr = skipwhite(line); |
| 1544 | if (*ptr == NUL) |
| 1545 | { |
| 1546 | spv->spv_cap_col = 0; |
| 1547 | spv->spv_capcol_lnum = lnum + 1; |
| 1548 | } |
| 1549 | // For checking first word with a capital skip white space. |
| 1550 | else if (spv->spv_cap_col == 0) |
| 1551 | spv->spv_cap_col = ptr - line; |
| 1552 | |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1553 | // Copy the end of the current line into nextline[]. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1554 | if (nextline[SPWORDLEN] == NUL) |
| 1555 | { |
| 1556 | // No next line or it is empty. |
| 1557 | nextlinecol = MAXCOL; |
| 1558 | nextline_idx = 0; |
| 1559 | } |
| 1560 | else |
| 1561 | { |
zeertzjq | 94b7c32 | 2024-03-12 21:50:32 +0100 | [diff] [blame] | 1562 | v = ml_get_buf_len(wp->w_buffer, lnum); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1563 | if (v < SPWORDLEN) |
| 1564 | { |
| 1565 | // Short line, use it completely and append the start of the |
| 1566 | // next line. |
| 1567 | nextlinecol = 0; |
| 1568 | mch_memmove(nextline, line, (size_t)v); |
| 1569 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
| 1570 | nextline_idx = v + 1; |
| 1571 | } |
| 1572 | else |
| 1573 | { |
| 1574 | // Long line, use only the last SPWORDLEN bytes. |
| 1575 | nextlinecol = v - SPWORDLEN; |
| 1576 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 1577 | nextline_idx = SPWORDLEN + 1; |
| 1578 | } |
| 1579 | } |
| 1580 | } |
| 1581 | #endif |
| 1582 | |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 1583 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 1584 | ptr = line; |
| 1585 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1586 | if (wp->w_p_list) |
| 1587 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1588 | if (wp->w_lcs_chars.space |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 1589 | || wp->w_lcs_chars.multispace != NULL |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 1590 | || wp->w_lcs_chars.leadmultispace != NULL |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1591 | || wp->w_lcs_chars.trail |
| 1592 | || wp->w_lcs_chars.lead |
| 1593 | || wp->w_lcs_chars.nbsp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1594 | extra_check = TRUE; |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 1595 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1596 | // find start of trailing whitespace |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1597 | if (wp->w_lcs_chars.trail) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1598 | { |
zeertzjq | 94b7c32 | 2024-03-12 21:50:32 +0100 | [diff] [blame] | 1599 | trailcol = ml_get_buf_len(wp->w_buffer, lnum); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1600 | while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1])) |
| 1601 | --trailcol; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1602 | trailcol += (colnr_T)(ptr - line); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1603 | } |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 1604 | // find end of leading whitespace |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 1605 | if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL) |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 1606 | { |
| 1607 | leadcol = 0; |
| 1608 | while (VIM_ISWHITE(ptr[leadcol])) |
| 1609 | ++leadcol; |
| 1610 | if (ptr[leadcol] == NUL) |
| 1611 | // in a line full of spaces all of them are treated as trailing |
| 1612 | leadcol = (colnr_T)0; |
| 1613 | else |
| 1614 | // keep track of the first column not filled with spaces |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1615 | leadcol += (colnr_T)(ptr - line) + 1; |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 1616 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1617 | } |
| 1618 | |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1619 | wlv.wcr_attr = get_wcr_attr(wp); |
| 1620 | if (wlv.wcr_attr != 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1621 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1622 | wlv.win_attr = wlv.wcr_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1623 | area_highlighting = TRUE; |
| 1624 | } |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1625 | |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 1626 | // When w_skipcol is non-zero and there is virtual text above the actual |
| 1627 | // text, then this much of the virtual text is skipped. |
| 1628 | int skipcol_in_text_prop_above = 0; |
| 1629 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 1630 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1631 | if (WIN_IS_POPUP(wp)) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1632 | wlv.screen_line_flags |= SLF_POPUP; |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 1633 | |
| 1634 | char_u *prop_start; |
| 1635 | text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE); |
| 1636 | if (text_prop_count > 0) |
| 1637 | { |
| 1638 | // Make a copy of the properties, so that they are properly |
| 1639 | // aligned. |
| 1640 | text_props = ALLOC_MULT(textprop_T, text_prop_count); |
| 1641 | if (text_props != NULL) |
| 1642 | mch_memmove(text_props, prop_start, |
| 1643 | text_prop_count * sizeof(textprop_T)); |
| 1644 | |
| 1645 | // Allocate an array for the indexes. |
| 1646 | text_prop_idxs = ALLOC_MULT(int, text_prop_count); |
| 1647 | if (text_prop_idxs == NULL) |
| 1648 | VIM_CLEAR(text_props); |
| 1649 | |
| 1650 | if (text_props != NULL) |
| 1651 | { |
| 1652 | area_highlighting = TRUE; |
| 1653 | extra_check = TRUE; |
| 1654 | |
zeertzjq | 4e26a9a | 2023-12-03 17:50:47 +0100 | [diff] [blame] | 1655 | /* Find the last text property that inserts text. */ |
| 1656 | for (int i = 0; i < text_prop_count; ++i) |
| 1657 | if (text_props[i].tp_id < 0) |
| 1658 | last_textprop_text_idx = i; |
| 1659 | |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 1660 | // Text props "above" move the line number down to where the text |
| 1661 | // is. Only count the ones that are visible, not those that are |
| 1662 | // skipped because of w_skipcol. |
| 1663 | int text_width = wp->w_width - win_col_off(wp); |
| 1664 | for (int i = text_prop_count - 1; i >= 0; --i) |
| 1665 | if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE) |
| 1666 | { |
| 1667 | if (lnum == wp->w_topline |
| 1668 | && wp->w_skipcol - skipcol_in_text_prop_above |
| 1669 | >= text_width) |
| 1670 | { |
| 1671 | // This virtual text above is skipped, remove it from |
| 1672 | // the array. |
| 1673 | skipcol_in_text_prop_above += text_width; |
| 1674 | for (int j = i + 1; j < text_prop_count; ++j) |
| 1675 | text_props[j - 1] = text_props[j]; |
| 1676 | ++i; |
| 1677 | --text_prop_count; |
| 1678 | } |
| 1679 | else |
| 1680 | ++wlv.text_prop_above_count; |
| 1681 | } |
| 1682 | } |
| 1683 | } |
Bram Moolenaar | a572b93 | 2023-02-19 14:34:37 +0000 | [diff] [blame] | 1684 | |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1685 | if (number_only > 0) |
Bram Moolenaar | a572b93 | 2023-02-19 14:34:37 +0000 | [diff] [blame] | 1686 | { |
| 1687 | // skip over rows only used for virtual text above |
| 1688 | wlv.row += wlv.text_prop_above_count; |
zeertzjq | 918b92b | 2024-03-20 19:49:20 +0100 | [diff] [blame] | 1689 | if (wlv.row >= endrow) |
| 1690 | { |
| 1691 | vim_free(text_props); |
| 1692 | vim_free(text_prop_idxs); |
Bram Moolenaar | a572b93 | 2023-02-19 14:34:37 +0000 | [diff] [blame] | 1693 | return wlv.row; |
zeertzjq | 918b92b | 2024-03-20 19:49:20 +0100 | [diff] [blame] | 1694 | } |
Bram Moolenaar | a572b93 | 2023-02-19 14:34:37 +0000 | [diff] [blame] | 1695 | wlv.screen_row += wlv.text_prop_above_count; |
| 1696 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1697 | #endif |
| 1698 | |
zeertzjq | ce53e3e | 2023-09-01 18:49:30 +0200 | [diff] [blame] | 1699 | #if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP) |
| 1700 | colnr_T vcol_first_char = 0; |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1701 | if (wp->w_p_lbr && number_only == 0) |
zeertzjq | ce53e3e | 2023-09-01 18:49:30 +0200 | [diff] [blame] | 1702 | { |
| 1703 | chartabsize_T cts; |
| 1704 | init_chartabsize_arg(&cts, wp, lnum, 0, line, line); |
| 1705 | (void)win_lbr_chartabsize(&cts, NULL); |
| 1706 | vcol_first_char = cts.cts_first_char; |
| 1707 | clear_chartabsize_arg(&cts); |
| 1708 | } |
| 1709 | #endif |
| 1710 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1711 | // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 1712 | // first character to be displayed. |
| 1713 | if (wp->w_p_wrap) |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 1714 | v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1715 | else |
| 1716 | v = wp->w_leftcol; |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1717 | if (v > 0 && number_only == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1718 | { |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1719 | char_u *prev_ptr = ptr; |
| 1720 | chartabsize_T cts; |
Bram Moolenaar | 6d023f9 | 2022-07-25 21:15:45 +0100 | [diff] [blame] | 1721 | int charsize = 0; |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 1722 | int head = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1723 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1724 | init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr); |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 1725 | cts.cts_max_head_vcol = v; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1726 | while (cts.cts_vcol < v && *cts.cts_ptr != NUL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1727 | { |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 1728 | head = 0; |
| 1729 | charsize = win_lbr_chartabsize(&cts, &head); |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1730 | cts.cts_vcol += charsize; |
| 1731 | prev_ptr = cts.cts_ptr; |
| 1732 | MB_PTR_ADV(cts.cts_ptr); |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 1733 | if (wp->w_p_list) |
| 1734 | { |
| 1735 | in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' ' |
| 1736 | || (prev_ptr > line && prev_ptr[-1] == ' ')); |
| 1737 | if (!in_multispace) |
| 1738 | multispace_pos = 0; |
| 1739 | else if (cts.cts_ptr >= line + leadcol |
| 1740 | && wp->w_lcs_chars.multispace != NULL) |
| 1741 | { |
| 1742 | ++multispace_pos; |
| 1743 | if (wp->w_lcs_chars.multispace[multispace_pos] == NUL) |
| 1744 | multispace_pos = 0; |
| 1745 | } |
| 1746 | else if (cts.cts_ptr < line + leadcol |
| 1747 | && wp->w_lcs_chars.leadmultispace != NULL) |
| 1748 | { |
| 1749 | ++multispace_pos; |
| 1750 | if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL) |
| 1751 | multispace_pos = 0; |
| 1752 | } |
| 1753 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1754 | } |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1755 | wlv.vcol = cts.cts_vcol; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1756 | ptr = cts.cts_ptr; |
| 1757 | clear_chartabsize_arg(&cts); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1758 | |
| 1759 | // When: |
| 1760 | // - 'cuc' is set, or |
| 1761 | // - 'colorcolumn' is set, or |
| 1762 | // - 'virtualedit' is set, or |
| 1763 | // - the visual mode is active, |
| 1764 | // the end of the line may be before the start of the displayed part. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1765 | if (wlv.vcol < v && ( |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1766 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1767 | wp->w_p_cuc || wlv.draw_color_col || |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1768 | #endif |
| 1769 | virtual_active() || |
| 1770 | (VIsual_active && wp->w_buffer == curwin->w_buffer))) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1771 | wlv.vcol = v; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1772 | |
| 1773 | // Handle a character that's not completely on the screen: Put ptr at |
| 1774 | // that character but skip the first few screen characters. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1775 | if (wlv.vcol > v) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1776 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1777 | wlv.vcol -= charsize; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1778 | ptr = prev_ptr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1779 | } |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 1780 | if (v > wlv.vcol) |
| 1781 | skip_cells = v - wlv.vcol - head; |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 1782 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1783 | // Adjust for when the inverted text is before the screen, |
| 1784 | // and when the start of the inverted text is before the screen. |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1785 | if (wlv.tocol <= wlv.vcol) |
| 1786 | wlv.fromcol = 0; |
| 1787 | else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol) |
| 1788 | wlv.fromcol = wlv.vcol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1789 | |
| 1790 | #ifdef FEAT_LINEBREAK |
| 1791 | // When w_skipcol is non-zero, first line needs 'showbreak' |
| 1792 | if (wp->w_p_wrap) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1793 | wlv.need_showbreak = TRUE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1794 | #endif |
| 1795 | #ifdef FEAT_SPELL |
| 1796 | // When spell checking a word we need to figure out the start of the |
| 1797 | // word and if it's badly spelled or not. |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1798 | if (spv->spv_has_spell) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1799 | { |
| 1800 | int len; |
| 1801 | colnr_T linecol = (colnr_T)(ptr - line); |
| 1802 | hlf_T spell_hlf = HLF_COUNT; |
| 1803 | |
| 1804 | pos = wp->w_cursor; |
| 1805 | wp->w_cursor.lnum = lnum; |
| 1806 | wp->w_cursor.col = linecol; |
Christ van Willegen - van Noort | 8e4c4c7 | 2024-05-17 18:49:27 +0200 | [diff] [blame] | 1807 | len = spell_move_to(wp, FORWARD, SMT_ALL, TRUE, &spell_hlf); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1808 | |
| 1809 | // spell_move_to() may call ml_get() and make "line" invalid |
| 1810 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 1811 | ptr = line + linecol; |
| 1812 | |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 1813 | if (len == 0 || (int)wp->w_cursor.col > linecol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1814 | { |
| 1815 | // no bad word found at line start, don't check until end of a |
| 1816 | // word |
| 1817 | spell_hlf = HLF_COUNT; |
| 1818 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
| 1819 | } |
| 1820 | else |
| 1821 | { |
| 1822 | // bad word found, use attributes until end of word |
| 1823 | word_end = wp->w_cursor.col + len + 1; |
| 1824 | |
| 1825 | // Turn index into actual attributes. |
| 1826 | if (spell_hlf != HLF_COUNT) |
| 1827 | spell_attr = highlight_attr[spell_hlf]; |
| 1828 | } |
| 1829 | wp->w_cursor = pos; |
| 1830 | |
| 1831 | # ifdef FEAT_SYN_HL |
| 1832 | // Need to restart syntax highlighting for this line. |
| 1833 | if (has_syntax) |
| 1834 | syntax_start(wp, lnum); |
| 1835 | # endif |
| 1836 | } |
| 1837 | #endif |
| 1838 | } |
| 1839 | |
| 1840 | // Correct highlighting for cursor that can't be disabled. |
| 1841 | // Avoids having to check this for each character. |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1842 | if (wlv.fromcol >= 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1843 | { |
| 1844 | if (noinvcur) |
| 1845 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1846 | if ((colnr_T)wlv.fromcol == wp->w_virtcol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1847 | { |
| 1848 | // highlighting starts at cursor, let it start just after the |
| 1849 | // cursor |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1850 | fromcol_prev = wlv.fromcol; |
| 1851 | wlv.fromcol = -1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1852 | } |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1853 | else if ((colnr_T)wlv.fromcol < wp->w_virtcol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1854 | // restart highlighting after the cursor |
| 1855 | fromcol_prev = wp->w_virtcol; |
| 1856 | } |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1857 | if (wlv.fromcol >= wlv.tocol) |
| 1858 | wlv.fromcol = -1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | #ifdef FEAT_SEARCH_EXTRA |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1862 | if (number_only == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1863 | { |
| 1864 | v = (long)(ptr - line); |
| 1865 | area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v, |
| 1866 | &line, &screen_search_hl, |
| 1867 | &search_attr); |
| 1868 | ptr = line + v; // "line" may have been updated |
| 1869 | } |
| 1870 | #endif |
| 1871 | |
glepnir | 8d0bb6d | 2024-12-24 09:44:35 +0100 | [diff] [blame] | 1872 | if ((State & MODE_INSERT) && in_curline && ins_compl_win_active(wp)) |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 1873 | area_highlighting = TRUE; |
| 1874 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1875 | #ifdef FEAT_SYN_HL |
| 1876 | // Cursor line highlighting for 'cursorline' in the current window. |
| 1877 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 1878 | { |
| 1879 | // Do not show the cursor line in the text when Visual mode is active, |
zeertzjq | c20e46a | 2022-03-23 14:55:23 +0000 | [diff] [blame] | 1880 | // because it's not clear what is selected then. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1881 | if (!(wp == curwin && VIsual_active) |
| 1882 | && wp->w_p_culopt_flags != CULOPT_NBR) |
| 1883 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1884 | wlv.cul_screenline = (wp->w_p_wrap |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1885 | && (wp->w_p_culopt_flags & CULOPT_SCRLINE)); |
| 1886 | |
zeertzjq | b7acea1 | 2022-12-12 13:20:43 +0000 | [diff] [blame] | 1887 | // Only apply CursorLine highlight here when "screenline" is not |
| 1888 | // present in 'cursorlineopt'. Otherwise it's done later. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1889 | if (!wlv.cul_screenline) |
zeertzjq | b7acea1 | 2022-12-12 13:20:43 +0000 | [diff] [blame] | 1890 | apply_cursorline_highlight(&wlv, sign_present); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1891 | else |
| 1892 | { |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1893 | line_attr_save = wlv.line_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1894 | margin_columns_win(wp, &left_curline_col, &right_curline_col); |
| 1895 | } |
| 1896 | area_highlighting = TRUE; |
| 1897 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1898 | } |
| 1899 | #endif |
| 1900 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1901 | win_line_start(wp, &wlv, FALSE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1902 | |
| 1903 | // Repeat for the whole displayed line. |
| 1904 | for (;;) |
| 1905 | { |
| 1906 | #if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1907 | int has_match_conc = 0; // match wants to conceal |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1908 | #endif |
| 1909 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1910 | int did_decrement_ptr = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1911 | #endif |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1912 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1913 | // Skip this quickly when working on the text. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1914 | if (wlv.draw_state != WL_LINE) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1915 | { |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1916 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1917 | if (wlv.cul_screenline) |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1918 | { |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1919 | wlv.cul_attr = 0; |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1920 | wlv.line_attr = line_attr_save; |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1921 | } |
| 1922 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1923 | if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1924 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1925 | wlv.draw_state = WL_CMDLINE; |
Sean Dewar | 988f743 | 2023-08-16 14:17:36 +0100 | [diff] [blame] | 1926 | if (wp == cmdwin_win) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1927 | { |
| 1928 | // Draw the cmdline character. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1929 | wlv.n_extra = 1; |
| 1930 | wlv.c_extra = cmdwin_type; |
| 1931 | wlv.c_final = NUL; |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1932 | wlv.char_attr = |
| 1933 | hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1934 | } |
| 1935 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1936 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1937 | if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1938 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1939 | wlv.draw_state = WL_FOLD; |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1940 | handle_foldcolumn(wp, &wlv); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1941 | } |
| 1942 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1943 | #ifdef FEAT_SIGNS |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1944 | if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1945 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1946 | // Show the sign column when desired or when using Netbeans. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1947 | wlv.draw_state = WL_SIGN; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1948 | if (signcolumn_on(wp)) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1949 | get_sign_display_info(FALSE, wp, &wlv); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1950 | } |
| 1951 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1952 | if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1953 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1954 | // Show the line number, if desired. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1955 | wlv.draw_state = WL_NR; |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1956 | handle_lnum_col(wp, &wlv, sign_present, num_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1957 | } |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1958 | |
| 1959 | // When only displaying the (relative) line number and that's done, |
| 1960 | // stop here. |
| 1961 | if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0) |
| 1962 | { |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 1963 | wlv_screen_line(wp, &wlv, FALSE); |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1964 | // Need to update more screen lines if: |
| 1965 | // - LineNrAbove or LineNrBelow is used, or |
| 1966 | // - still drawing filler lines. |
| 1967 | if ((wlv.row + 1 - wlv.startrow < number_only |
| 1968 | && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0)) |
| 1969 | #ifdef FEAT_DIFF |
| 1970 | || wlv.filler_todo > 0 |
| 1971 | #endif |
| 1972 | ) |
| 1973 | { |
| 1974 | ++wlv.row; |
| 1975 | ++wlv.screen_row; |
| 1976 | if (wlv.row == endrow) |
| 1977 | break; |
| 1978 | #ifdef FEAT_DIFF |
| 1979 | --wlv.filler_todo; |
| 1980 | if (wlv.filler_todo == 0 && wp->w_botfill) |
| 1981 | break; |
| 1982 | #endif |
| 1983 | win_line_start(wp, &wlv, TRUE); |
| 1984 | continue; |
| 1985 | } |
| 1986 | else |
| 1987 | break; |
| 1988 | } |
| 1989 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1990 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1991 | // Check if 'breakindent' applies and show it. |
| 1992 | // May change wlv.draw_state to WL_BRI or WL_BRI - 1. |
| 1993 | if (wlv.n_extra == 0) |
| 1994 | handle_breakindent(wp, &wlv); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1995 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1996 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1997 | if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1998 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1999 | wlv.draw_state = WL_SBR; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 2000 | handle_showbreak_and_filler(wp, &wlv); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2001 | } |
| 2002 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2003 | if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2004 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2005 | wlv.draw_state = WL_LINE; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 2006 | win_line_continue(&wlv); // use wlv.saved_ values |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2007 | } |
| 2008 | } |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 2009 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2010 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2011 | if (wlv.cul_screenline && wlv.draw_state == WL_LINE |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2012 | && wlv.vcol >= left_curline_col |
| 2013 | && wlv.vcol < right_curline_col) |
zeertzjq | b7acea1 | 2022-12-12 13:20:43 +0000 | [diff] [blame] | 2014 | apply_cursorline_highlight(&wlv, sign_present); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2015 | #endif |
| 2016 | |
| 2017 | // When still displaying '$' of change command, stop at cursor. |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 2018 | if (dollar_vcol >= 0 && in_curline && wlv.vcol >= (long)wp->w_virtcol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2019 | { |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 2020 | wlv_screen_line(wp, &wlv, FALSE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2021 | // Pretend we have finished updating the window. Except when |
| 2022 | // 'cursorcolumn' is set. |
| 2023 | #ifdef FEAT_SYN_HL |
| 2024 | if (wp->w_p_cuc) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2025 | wlv.row = wp->w_cline_row + wp->w_cline_height; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2026 | else |
| 2027 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2028 | wlv.row = wp->w_height; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2029 | break; |
| 2030 | } |
| 2031 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2032 | if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2033 | { |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 2034 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2035 | if (text_props != NULL) |
| 2036 | { |
| 2037 | int pi; |
| 2038 | int bcol = (int)(ptr - line); |
| 2039 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2040 | if (wlv.n_extra > 0 |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2041 | # ifdef FEAT_LINEBREAK |
| 2042 | && !in_linebreak |
| 2043 | # endif |
| 2044 | ) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2045 | --bcol; // still working on the previous char, e.g. Tab |
| 2046 | |
| 2047 | // Check if any active property ends. |
| 2048 | for (pi = 0; pi < text_props_active; ++pi) |
| 2049 | { |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2050 | int tpi = text_prop_idxs[pi]; |
| 2051 | textprop_T *tp = &text_props[tpi]; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2052 | |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2053 | // An inline property ends when after the start column plus |
| 2054 | // length. An "above" property ends when used and n_extra |
| 2055 | // is zero. |
| 2056 | if ((tp->tp_col != MAXCOL |
| 2057 | && bcol >= tp->tp_col - 1 + tp->tp_len)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2058 | { |
| 2059 | if (pi + 1 < text_props_active) |
| 2060 | mch_memmove(text_prop_idxs + pi, |
| 2061 | text_prop_idxs + pi + 1, |
| 2062 | sizeof(int) |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2063 | * (text_props_active - (pi + 1))); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2064 | --text_props_active; |
| 2065 | --pi; |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2066 | # ifdef FEAT_LINEBREAK |
| 2067 | // not exactly right but should work in most cases |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2068 | if (in_linebreak && syntax_attr == text_prop_attr_comb) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2069 | syntax_attr = 0; |
| 2070 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2071 | } |
| 2072 | } |
| 2073 | |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2074 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2075 | if (wlv.n_extra > 0 && in_linebreak) |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2076 | // not on the next char yet, don't start another prop |
| 2077 | --bcol; |
| 2078 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2079 | // Add any text property that starts in this column. |
Dylan Thacker-Smith | 1134fdd | 2024-03-28 11:49:46 +0100 | [diff] [blame] | 2080 | while (text_prop_next < text_prop_count) |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 2081 | { |
Dylan Thacker-Smith | 1134fdd | 2024-03-28 11:49:46 +0100 | [diff] [blame] | 2082 | int active; |
| 2083 | textprop_T *tp = &text_props[text_prop_next]; |
| 2084 | if (tp->tp_col == MAXCOL) |
Dylan Thacker-Smith | fe0a76b | 2024-03-28 11:47:32 +0100 | [diff] [blame] | 2085 | { |
Dylan Thacker-Smith | 1134fdd | 2024-03-28 11:49:46 +0100 | [diff] [blame] | 2086 | if (bcol == 0 && (tp->tp_flags & TP_FLAG_ALIGN_ABOVE)) |
| 2087 | active = TRUE; |
| 2088 | else if (*ptr != NUL) |
| 2089 | break; |
| 2090 | else |
| 2091 | { |
| 2092 | // With 'nowrap' and not in the first screen line only "below" |
| 2093 | // text prop can show. |
| 2094 | active = wp->w_p_wrap |
| 2095 | || wlv.row == startrow |
| 2096 | || (tp->tp_flags & TP_FLAG_ALIGN_BELOW); |
| 2097 | } |
Dylan Thacker-Smith | fe0a76b | 2024-03-28 11:47:32 +0100 | [diff] [blame] | 2098 | } |
Dylan Thacker-Smith | 1134fdd | 2024-03-28 11:49:46 +0100 | [diff] [blame] | 2099 | else |
| 2100 | { |
| 2101 | if (bcol < tp->tp_col - 1) |
| 2102 | break; |
| 2103 | active = bcol <= tp->tp_col - 1 + tp->tp_len; |
| 2104 | } |
| 2105 | |
| 2106 | if (active) |
| 2107 | text_prop_idxs[text_props_active++] = text_prop_next; |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 2108 | ++text_prop_next; |
| 2109 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2110 | |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 2111 | if (wlv.n_extra == 0 || |
| 2112 | (!wlv.extra_for_textprop |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 2113 | && !(text_prop_type != NULL && |
| 2114 | text_prop_flags & PT_FLAG_OVERRIDE) |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 2115 | )) |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 2116 | { |
| 2117 | text_prop_attr = 0; |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2118 | text_prop_attr_comb = 0; |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 2119 | text_prop_flags = 0; |
| 2120 | text_prop_type = NULL; |
| 2121 | text_prop_id = 0; |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 2122 | reset_extra_attr = FALSE; |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 2123 | } |
Dylan Thacker-Smith | c8b47f2 | 2024-03-26 18:05:01 +0100 | [diff] [blame] | 2124 | if (text_props_active > 0 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2125 | { |
Bram Moolenaar | be3dbda | 2022-07-26 11:42:34 +0100 | [diff] [blame] | 2126 | int used_tpi = -1; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2127 | int used_attr = 0; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2128 | int other_tpi = -1; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2129 | |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 2130 | text_prop_above = FALSE; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2131 | text_prop_follows = FALSE; |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2132 | |
| 2133 | // Sort the properties on priority and/or starting last. |
| 2134 | // Then combine the attributes, highest priority last. |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2135 | sort_text_props(wp->w_buffer, text_props, |
| 2136 | text_prop_idxs, text_props_active); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2137 | |
| 2138 | for (pi = 0; pi < text_props_active; ++pi) |
| 2139 | { |
| 2140 | int tpi = text_prop_idxs[pi]; |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 2141 | textprop_T *tp = &text_props[tpi]; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2142 | proptype_T *pt = text_prop_type_by_id( |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2143 | wp->w_buffer, tp->tp_type); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2144 | |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2145 | // Only use a text property that can be displayed. |
| 2146 | // Skip "after" properties when wrap is off and at the |
| 2147 | // end of the window. |
| 2148 | if (pt != NULL |
| 2149 | && (pt->pt_hl_id > 0 || tp->tp_id < 0) |
| 2150 | && tp->tp_id != -MAXCOL |
| 2151 | && !(tp->tp_id < 0 |
| 2152 | && !wp->w_p_wrap |
| 2153 | && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT |
| 2154 | | TP_FLAG_ALIGN_ABOVE |
| 2155 | | TP_FLAG_ALIGN_BELOW)) == 0 |
| 2156 | && wlv.col >= wp->w_width)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2157 | { |
Bram Moolenaar | 234c3fa | 2023-02-12 14:42:15 +0000 | [diff] [blame] | 2158 | if (tp->tp_col == MAXCOL |
| 2159 | && *ptr == NUL |
| 2160 | && ((wp->w_p_list && lcs_eol_one > 0 |
| 2161 | && (tp->tp_flags |
| 2162 | & TP_FLAG_ALIGN_ABOVE) == 0) |
| 2163 | || (ptr == line |
| 2164 | && !did_line |
| 2165 | && (tp->tp_flags |
| 2166 | & TP_FLAG_ALIGN_BELOW)))) |
| 2167 | { |
| 2168 | // skip this prop, first display the '$' after |
| 2169 | // the line or display an empty line |
| 2170 | text_prop_follows = TRUE; |
Bram Moolenaar | 234c3fa | 2023-02-12 14:42:15 +0000 | [diff] [blame] | 2171 | continue; |
| 2172 | } |
| 2173 | |
Bram Moolenaar | 87f3a2c | 2022-08-10 20:50:23 +0100 | [diff] [blame] | 2174 | if (pt->pt_hl_id > 0) |
| 2175 | used_attr = syn_id2attr(pt->pt_hl_id); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2176 | text_prop_type = pt; |
| 2177 | text_prop_attr = |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2178 | hl_combine_attr(text_prop_attr, used_attr); |
Bram Moolenaar | 51b2fc2 | 2023-01-21 15:54:59 +0000 | [diff] [blame] | 2179 | if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0) |
| 2180 | other_tpi = used_tpi; |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 2181 | text_prop_flags = pt->pt_flags; |
| 2182 | text_prop_id = tp->tp_id; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2183 | used_tpi = tpi; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2184 | } |
| 2185 | } |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2186 | if (text_prop_id < 0 && used_tpi >= 0 |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2187 | && -text_prop_id |
| 2188 | <= wp->w_buffer->b_textprop_text.ga_len) |
| 2189 | { |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2190 | textprop_T *tp = &text_props[used_tpi]; |
| 2191 | char_u *p = ((char_u **)wp->w_buffer |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2192 | ->b_textprop_text.ga_data)[ |
| 2193 | -text_prop_id - 1]; |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 2194 | int above = (tp->tp_flags |
| 2195 | & TP_FLAG_ALIGN_ABOVE); |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 2196 | int bail_out = FALSE; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2197 | |
| 2198 | // reset the ID in the copy to avoid it being used |
| 2199 | // again |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2200 | tp->tp_id = -MAXCOL; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2201 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2202 | if (p != NULL) |
| 2203 | { |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2204 | int right = (tp->tp_flags |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2205 | & TP_FLAG_ALIGN_RIGHT); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2206 | int below = (tp->tp_flags |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2207 | & TP_FLAG_ALIGN_BELOW); |
zeertzjq | 3c3cf1d | 2023-09-02 21:55:00 +0200 | [diff] [blame] | 2208 | int wrap = tp->tp_col < MAXCOL |
| 2209 | || (tp->tp_flags & TP_FLAG_WRAP); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2210 | int padding = tp->tp_col == MAXCOL |
| 2211 | && tp->tp_len > 1 |
| 2212 | ? tp->tp_len - 1 : 0; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2213 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2214 | // Insert virtual text before the current |
| 2215 | // character, or add after the end of the line. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2216 | wlv.p_extra = p; |
| 2217 | wlv.c_extra = NUL; |
| 2218 | wlv.c_final = NUL; |
| 2219 | wlv.n_extra = (int)STRLEN(p); |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2220 | wlv.extra_for_textprop = TRUE; |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2221 | wlv.start_extra_for_textprop = TRUE; |
Bram Moolenaar | ee28c70 | 2022-11-17 14:56:00 +0000 | [diff] [blame] | 2222 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
| 2223 | used_attr); |
Bram Moolenaar | 09ff4b5 | 2022-08-01 16:51:02 +0100 | [diff] [blame] | 2224 | n_attr = mb_charlen(p); |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2225 | text_prop_attr = 0; |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2226 | text_prop_attr_comb = 0; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2227 | if (*ptr == NUL) |
| 2228 | // don't combine char attr after EOL |
Bram Moolenaar | 4d2031f | 2022-08-05 20:03:55 +0100 | [diff] [blame] | 2229 | text_prop_flags &= ~PT_FLAG_COMBINE; |
zeertzjq | 6b9c202 | 2023-09-11 20:01:17 +0200 | [diff] [blame] | 2230 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 2231 | if (above || below || right || !wrap) |
Bram Moolenaar | 3ec3b8e | 2022-08-05 21:39:30 +0100 | [diff] [blame] | 2232 | { |
| 2233 | // no 'showbreak' before "below" text property |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 2234 | // or after "above" or "right" text property |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 2235 | wlv.need_showbreak = FALSE; |
| 2236 | wlv.dont_use_showbreak = TRUE; |
Bram Moolenaar | 3ec3b8e | 2022-08-05 21:39:30 +0100 | [diff] [blame] | 2237 | } |
zeertzjq | 6b9c202 | 2023-09-11 20:01:17 +0200 | [diff] [blame] | 2238 | # endif |
Bram Moolenaar | 79f8b84 | 2022-09-11 13:31:01 +0100 | [diff] [blame] | 2239 | if ((right || above || below || !wrap |
| 2240 | || padding > 0) && wp->w_width > 2) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2241 | { |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2242 | char_u *prev_p_extra = wlv.p_extra; |
| 2243 | int start_line; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2244 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2245 | // Take care of padding, right-align and |
| 2246 | // truncation. |
| 2247 | // Shared with win_lbr_chartabsize(), must do |
| 2248 | // exactly the same. |
| 2249 | start_line = text_prop_position(wp, tp, |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 2250 | wlv.vcol, |
zeertzjq | 6b9c202 | 2023-09-11 20:01:17 +0200 | [diff] [blame] | 2251 | # ifdef FEAT_RIGHTLEFT |
| 2252 | wp->w_p_rl |
| 2253 | ? wp->w_width - wlv.col - 1 |
| 2254 | : |
| 2255 | # endif |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2256 | wlv.col, |
| 2257 | &wlv.n_extra, &wlv.p_extra, |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 2258 | &n_attr, &wlv.n_attr_skip, |
| 2259 | skip_cells > 0); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2260 | if (wlv.p_extra != prev_p_extra) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2261 | { |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2262 | // wlv.p_extra was allocated |
| 2263 | vim_free(p_extra_free2); |
| 2264 | p_extra_free2 = wlv.p_extra; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2265 | } |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2266 | |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 2267 | if (above) |
zeertzjq | 91d26aa | 2024-10-27 19:23:34 +0100 | [diff] [blame] | 2268 | wlv.vcol_off_tp = vim_strsize(wlv.p_extra); |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 2269 | |
Bram Moolenaar | 02edfaa | 2022-11-18 23:13:47 +0000 | [diff] [blame] | 2270 | if (lcs_eol_one < 0 |
| 2271 | && wp->w_p_wrap |
| 2272 | && wlv.col |
Bram Moolenaar | a4abe51 | 2022-09-15 19:44:09 +0100 | [diff] [blame] | 2273 | + wlv.n_extra - 2 > wp->w_width) |
| 2274 | // don't bail out at end of line |
Bram Moolenaar | a9a3648 | 2022-10-11 16:47:22 +0100 | [diff] [blame] | 2275 | text_prop_follows = TRUE; |
Bram Moolenaar | a4abe51 | 2022-09-15 19:44:09 +0100 | [diff] [blame] | 2276 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2277 | // When 'wrap' is off then for "below" we need |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 2278 | // to start a new line explicitly. |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2279 | if (start_line) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2280 | { |
| 2281 | draw_screen_line(wp, &wlv); |
| 2282 | |
| 2283 | // When line got too long for screen break |
| 2284 | // here. |
| 2285 | if (wlv.row == endrow) |
| 2286 | { |
| 2287 | ++wlv.row; |
| 2288 | break; |
| 2289 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2290 | win_line_start(wp, &wlv, TRUE); |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 2291 | bail_out = TRUE; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2292 | } |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2293 | } |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2294 | } |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2295 | |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2296 | // If the text didn't reach until the first window |
| 2297 | // column we need to skip cells. |
| 2298 | if (skip_cells > 0) |
| 2299 | { |
| 2300 | if (wlv.n_extra > skip_cells) |
| 2301 | { |
| 2302 | wlv.n_extra -= skip_cells; |
| 2303 | wlv.p_extra += skip_cells; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 2304 | wlv.n_attr_skip -= skip_cells; |
| 2305 | if (wlv.n_attr_skip < 0) |
| 2306 | wlv.n_attr_skip = 0; |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2307 | skipped_cells += skip_cells; |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2308 | skip_cells = 0; |
| 2309 | } |
| 2310 | else |
| 2311 | { |
| 2312 | // the whole text is left of the window, drop |
| 2313 | // it and advance to the next one |
| 2314 | skip_cells -= wlv.n_extra; |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2315 | skipped_cells += wlv.n_extra; |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2316 | wlv.n_extra = 0; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 2317 | wlv.n_attr_skip = 0; |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2318 | bail_out = TRUE; |
| 2319 | } |
| 2320 | } |
| 2321 | |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2322 | // If another text prop follows the condition below at |
| 2323 | // the last window column must know. |
Dylan Thacker-Smith | 83925be | 2024-02-21 21:03:10 +0100 | [diff] [blame] | 2324 | // If this is an "above" text prop and 'nowrap' then we |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 2325 | // must wrap anyway. |
| 2326 | text_prop_above = above; |
Bram Moolenaar | a9a3648 | 2022-10-11 16:47:22 +0100 | [diff] [blame] | 2327 | text_prop_follows |= other_tpi != -1 |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2328 | && (wp->w_p_wrap |
| 2329 | || (text_props[other_tpi].tp_flags |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 2330 | & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT))); |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 2331 | |
| 2332 | if (bail_out) |
| 2333 | // starting a new line for "below" |
| 2334 | continue; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2335 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2336 | } |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2337 | else if (text_prop_next < text_prop_count |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 2338 | && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL) |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 2339 | || (!wp->w_p_wrap && wlv.col == wp->w_width - 1))) |
| 2340 | { |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2341 | // When at last-but-one character and a text property |
| 2342 | // follows after it, we may need to flush the line after |
| 2343 | // displaying that character. |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 2344 | // Or when not wrapping and at the rightmost column. |
Dylan Thacker-Smith | fe0a76b | 2024-03-28 11:47:32 +0100 | [diff] [blame] | 2345 | |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 2346 | int only_below_follows = !wp->w_p_wrap && wlv.col == wp->w_width - 1; |
Dylan Thacker-Smith | fe0a76b | 2024-03-28 11:47:32 +0100 | [diff] [blame] | 2347 | // TODO: Store "after"/"right"/"below" text properties in order |
| 2348 | // in the buffer so only `text_props[text_prop_count - 1]` |
| 2349 | // needs to be checked for following "below" virtual text |
| 2350 | for (int i = text_prop_next; i < text_prop_count; ++i) |
| 2351 | { |
| 2352 | if (text_props[i].tp_col == MAXCOL |
| 2353 | && (!only_below_follows |
| 2354 | || (text_props[i].tp_flags & TP_FLAG_ALIGN_BELOW))) |
| 2355 | { |
| 2356 | text_prop_follows = TRUE; |
| 2357 | break; |
| 2358 | } |
| 2359 | } |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 2360 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2361 | } |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2362 | |
| 2363 | if (wlv.start_extra_for_textprop) |
| 2364 | { |
| 2365 | wlv.start_extra_for_textprop = FALSE; |
| 2366 | // restore search_attr and area_attr when n_extra |
| 2367 | // is down to zero |
| 2368 | saved_search_attr = search_attr; |
| 2369 | saved_area_attr = area_attr; |
| 2370 | search_attr = 0; |
| 2371 | area_attr = 0; |
| 2372 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2373 | #endif |
| 2374 | |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2375 | int *area_attr_p = |
| 2376 | #ifdef FEAT_PROP_POPUP |
| 2377 | wlv.extra_for_textprop ? &saved_area_attr : |
| 2378 | #endif |
| 2379 | &area_attr; |
| 2380 | |
| 2381 | // handle Visual or match highlighting in this line |
| 2382 | if (wlv.vcol == wlv.fromcol |
| 2383 | || (has_mbyte && wlv.vcol + 1 == wlv.fromcol |
| 2384 | && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1) |
| 2385 | || (wlv.n_extra > 0 && wlv.p_extra != NULL |
| 2386 | && (*mb_ptr2cells)(wlv.p_extra) > 1))) |
| 2387 | || ((int)vcol_prev == fromcol_prev |
| 2388 | && vcol_prev < wlv.vcol // not at margin |
| 2389 | && wlv.vcol < wlv.tocol)) |
| 2390 | *area_attr_p = vi_attr; // start highlighting |
| 2391 | else if (*area_attr_p != 0 |
| 2392 | && (wlv.vcol == wlv.tocol |
| 2393 | || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol))) |
| 2394 | *area_attr_p = 0; // stop highlighting |
| 2395 | |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2396 | if (wlv.n_extra == 0) |
| 2397 | { |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 2398 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2399 | // Check for start/end of 'hlsearch' and other matches. |
| 2400 | // After end, check for start/end of next match. |
| 2401 | // When another match, have to check for start again. |
| 2402 | v = (long)(ptr - line); |
| 2403 | search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line, |
| 2404 | &screen_search_hl, &has_match_conc, |
| 2405 | &match_conc, did_line_attr, lcs_eol_one, |
| 2406 | &on_last_col); |
| 2407 | ptr = line + v; // "line" may have been changed |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2408 | |
| 2409 | // Do not allow a conceal over EOL otherwise EOL will be missed |
| 2410 | // and bad things happen. |
| 2411 | if (*ptr == NUL) |
| 2412 | has_match_conc = 0; |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 2413 | #else |
| 2414 | search_attr = 0; |
zeertzjq | e500ae8 | 2023-08-17 22:35:26 +0200 | [diff] [blame] | 2415 | #endif |
zeertzjq | b25dbb3 | 2023-08-13 18:11:05 +0200 | [diff] [blame] | 2416 | |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 2417 | // Check if ComplMatchIns highlight is needed. |
glepnir | 8d0bb6d | 2024-12-24 09:44:35 +0100 | [diff] [blame] | 2418 | if ((State & MODE_INSERT) && in_curline |
| 2419 | && ins_compl_win_active(wp)) |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 2420 | { |
| 2421 | int ins_match_attr = |
| 2422 | ins_compl_col_range_attr((int)(ptr - line)); |
| 2423 | if (ins_match_attr > 0) |
| 2424 | search_attr = |
| 2425 | hl_combine_attr(search_attr, ins_match_attr); |
| 2426 | } |
| 2427 | } |
| 2428 | |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2429 | #ifdef FEAT_DIFF |
| 2430 | if (wlv.diff_hlf != (hlf_T)0) |
| 2431 | { |
Bram Moolenaar | d097af7 | 2022-12-17 11:33:00 +0000 | [diff] [blame] | 2432 | // When there is extra text (e.g. virtual text) it gets the |
| 2433 | // diff highlighting for the line, but not for changed text. |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2434 | if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start |
| 2435 | && wlv.n_extra == 0) |
| 2436 | wlv.diff_hlf = HLF_TXD; // changed text |
Bram Moolenaar | 417e88b | 2022-12-17 15:03:02 +0000 | [diff] [blame] | 2437 | if (wlv.diff_hlf == HLF_TXD |
| 2438 | && ((ptr - line > change_end && wlv.n_extra == 0) |
| 2439 | || (wlv.n_extra > 0 && wlv.extra_for_textprop))) |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2440 | wlv.diff_hlf = HLF_CHD; // changed line |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2441 | wlv.line_attr = HL_ATTR(wlv.diff_hlf); |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2442 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 2443 | && wp->w_p_culopt_flags != CULOPT_NBR |
| 2444 | && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col |
| 2445 | && wlv.vcol <= right_curline_col))) |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2446 | wlv.line_attr = hl_combine_attr( |
| 2447 | wlv.line_attr, HL_ATTR(HLF_CUL)); |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2448 | } |
| 2449 | #endif |
| 2450 | |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2451 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2452 | if (extra_check && wlv.n_extra == 0) |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2453 | { |
Bram Moolenaar | 82260af | 2019-10-20 13:16:22 +0200 | [diff] [blame] | 2454 | syntax_attr = 0; |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2455 | # ifdef FEAT_TERMINAL |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2456 | if (get_term_attr) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2457 | syntax_attr = term_get_attr(wp, lnum, wlv.vcol); |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2458 | # endif |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2459 | // Get syntax attribute. |
| 2460 | if (has_syntax) |
| 2461 | { |
| 2462 | // Get the syntax attribute for the character. If there |
| 2463 | // is an error, disable syntax highlighting. |
| 2464 | save_did_emsg = did_emsg; |
| 2465 | did_emsg = FALSE; |
| 2466 | |
| 2467 | v = (long)(ptr - line); |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 2468 | if (v == prev_syntax_col) |
| 2469 | // at same column again |
| 2470 | syntax_attr = prev_syntax_attr; |
| 2471 | else |
| 2472 | { |
Bram Moolenaar | b2fe1d6 | 2019-10-16 21:33:40 +0200 | [diff] [blame] | 2473 | # ifdef FEAT_SPELL |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 2474 | can_spell = TRUE; |
Bram Moolenaar | b2fe1d6 | 2019-10-16 21:33:40 +0200 | [diff] [blame] | 2475 | # endif |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 2476 | syntax_attr = get_syntax_attr((colnr_T)v, |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2477 | # ifdef FEAT_SPELL |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2478 | spv->spv_has_spell ? &can_spell : |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2479 | # endif |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2480 | NULL, FALSE); |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 2481 | prev_syntax_col = v; |
| 2482 | prev_syntax_attr = syntax_attr; |
| 2483 | } |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2484 | |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2485 | if (did_emsg) |
| 2486 | { |
| 2487 | wp->w_s->b_syn_error = TRUE; |
| 2488 | has_syntax = FALSE; |
| 2489 | syntax_attr = 0; |
| 2490 | } |
| 2491 | else |
| 2492 | did_emsg = save_did_emsg; |
| 2493 | # ifdef SYN_TIME_LIMIT |
| 2494 | if (wp->w_s->b_syn_slow) |
| 2495 | has_syntax = FALSE; |
| 2496 | # endif |
| 2497 | |
| 2498 | // Need to get the line again, a multi-line regexp may |
| 2499 | // have made it invalid. |
| 2500 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 2501 | ptr = line + v; |
| 2502 | # ifdef FEAT_CONCEAL |
| 2503 | // no concealing past the end of the line, it interferes |
| 2504 | // with line highlighting |
| 2505 | if (*ptr == NUL) |
| 2506 | syntax_flags = 0; |
| 2507 | else |
| 2508 | syntax_flags = get_syntax_info(&syntax_seqnr); |
| 2509 | # endif |
| 2510 | } |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2511 | } |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 2512 | # ifdef FEAT_PROP_POPUP |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 2513 | // Combine text property highlight into syntax highlight. |
| 2514 | if (text_prop_type != NULL) |
| 2515 | { |
Bram Moolenaar | 4d2031f | 2022-08-05 20:03:55 +0100 | [diff] [blame] | 2516 | if (text_prop_flags & PT_FLAG_COMBINE) |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 2517 | syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr); |
| 2518 | else |
| 2519 | syntax_attr = text_prop_attr; |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2520 | text_prop_attr_comb = syntax_attr; |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 2521 | } |
| 2522 | # endif |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2523 | #endif |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2524 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2525 | // Decide which of the highlight attributes to use. |
| 2526 | attr_pri = TRUE; |
| 2527 | #ifdef LINE_ATTR |
| 2528 | if (area_attr != 0) |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2529 | { |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2530 | wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr); |
Bram Moolenaar | 2d5f385 | 2021-04-21 15:11:42 +0200 | [diff] [blame] | 2531 | if (!highlight_match) |
| 2532 | // let search highlight show in Visual area if possible |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2533 | wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2534 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2535 | wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2536 | # endif |
| 2537 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2538 | else if (search_attr != 0) |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2539 | { |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2540 | wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2541 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2542 | wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2543 | # endif |
| 2544 | } |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2545 | else if (wlv.line_attr != 0 |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 2546 | && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL) |
| 2547 | || wlv.vcol < wlv.fromcol |
| 2548 | || vcol_prev < fromcol_prev |
| 2549 | || wlv.vcol >= wlv.tocol)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2550 | { |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2551 | // Use wlv.line_attr when not in the Visual or 'incsearch' area |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2552 | // (area_attr may be 0 when "noinvcur" is set). |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2553 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2554 | wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr); |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 2555 | # else |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2556 | wlv.char_attr = wlv.line_attr; |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2557 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2558 | attr_pri = FALSE; |
| 2559 | } |
| 2560 | #else |
| 2561 | if (area_attr != 0) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2562 | wlv.char_attr = area_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2563 | else if (search_attr != 0) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2564 | wlv.char_attr = search_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2565 | #endif |
| 2566 | else |
| 2567 | { |
| 2568 | attr_pri = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2569 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2570 | wlv.char_attr = syntax_attr; |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2571 | #else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2572 | wlv.char_attr = 0; |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2573 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2574 | } |
Bram Moolenaar | 4d2031f | 2022-08-05 20:03:55 +0100 | [diff] [blame] | 2575 | #ifdef FEAT_PROP_POPUP |
| 2576 | // override with text property highlight when "override" is TRUE |
| 2577 | if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE)) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2578 | wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr); |
Bram Moolenaar | 4d2031f | 2022-08-05 20:03:55 +0100 | [diff] [blame] | 2579 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2580 | } |
Bram Moolenaar | 024dbd2 | 2019-11-02 22:00:15 +0100 | [diff] [blame] | 2581 | |
| 2582 | // combine attribute with 'wincolor' |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2583 | if (wlv.win_attr != 0) |
Bram Moolenaar | 024dbd2 | 2019-11-02 22:00:15 +0100 | [diff] [blame] | 2584 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2585 | if (wlv.char_attr == 0) |
| 2586 | wlv.char_attr = wlv.win_attr; |
Bram Moolenaar | 024dbd2 | 2019-11-02 22:00:15 +0100 | [diff] [blame] | 2587 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2588 | wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr); |
Bram Moolenaar | 024dbd2 | 2019-11-02 22:00:15 +0100 | [diff] [blame] | 2589 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2590 | |
| 2591 | // Get the next character to put on the screen. |
| 2592 | |
| 2593 | // The "p_extra" points to the extra stuff that is inserted to |
| 2594 | // represent special characters (non-printable stuff) and other |
| 2595 | // things. When all characters are the same, c_extra is used. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2596 | // If wlv.c_final is set, it will compulsorily be used at the end. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2597 | // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 2598 | // "p_extra[n_extra]". |
| 2599 | // For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2600 | if (wlv.n_extra > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2601 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2602 | if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2603 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2604 | c = (wlv.n_extra == 1 && wlv.c_final != NUL) |
| 2605 | ? wlv.c_final : wlv.c_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2606 | mb_c = c; // doesn't handle non-utf-8 multi-byte! |
| 2607 | if (enc_utf8 && utf_char2len(c) > 1) |
| 2608 | { |
| 2609 | mb_utf8 = TRUE; |
| 2610 | u8cc[0] = 0; |
| 2611 | c = 0xc0; |
| 2612 | } |
| 2613 | else |
| 2614 | mb_utf8 = FALSE; |
| 2615 | } |
| 2616 | else |
| 2617 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2618 | c = *wlv.p_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2619 | if (has_mbyte) |
| 2620 | { |
| 2621 | mb_c = c; |
| 2622 | if (enc_utf8) |
| 2623 | { |
| 2624 | // If the UTF-8 character is more than one byte: |
| 2625 | // Decode it into "mb_c". |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2626 | mb_l = utfc_ptr2len(wlv.p_extra); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2627 | mb_utf8 = FALSE; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2628 | if (mb_l > wlv.n_extra) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2629 | mb_l = 1; |
| 2630 | else if (mb_l > 1) |
| 2631 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2632 | mb_c = utfc_ptr2char(wlv.p_extra, u8cc); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2633 | mb_utf8 = TRUE; |
| 2634 | c = 0xc0; |
| 2635 | } |
| 2636 | } |
| 2637 | else |
| 2638 | { |
| 2639 | // if this is a DBCS character, put it in "mb_c" |
| 2640 | mb_l = MB_BYTE2LEN(c); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2641 | if (mb_l >= wlv.n_extra) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2642 | mb_l = 1; |
| 2643 | else if (mb_l > 1) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2644 | mb_c = (c << 8) + wlv.p_extra[1]; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2645 | } |
| 2646 | if (mb_l == 0) // at the NUL at end-of-line |
| 2647 | mb_l = 1; |
| 2648 | |
| 2649 | // If a double-width char doesn't fit display a '>' in the |
| 2650 | // last column. |
| 2651 | if (( |
| 2652 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2653 | wp->w_p_rl ? (wlv.col <= 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2654 | # endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2655 | (wlv.col >= wp->w_width - 1)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2656 | && (*mb_char2cells)(mb_c) == 2) |
| 2657 | { |
| 2658 | c = '>'; |
| 2659 | mb_c = c; |
| 2660 | mb_l = 1; |
| 2661 | mb_utf8 = FALSE; |
| 2662 | multi_attr = HL_ATTR(HLF_AT); |
| 2663 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 2664 | if (wlv.cul_attr) |
| 2665 | multi_attr = hl_combine_attr( |
| 2666 | multi_attr, wlv.cul_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2667 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2668 | multi_attr = hl_combine_attr(wlv.win_attr, multi_attr); |
Bram Moolenaar | 92e25ab | 2019-11-26 22:39:10 +0100 | [diff] [blame] | 2669 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2670 | // put the pointer back to output the double-width |
| 2671 | // character at the start of the next line. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2672 | ++wlv.n_extra; |
| 2673 | --wlv.p_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2674 | } |
| 2675 | else |
| 2676 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2677 | wlv.n_extra -= mb_l - 1; |
| 2678 | wlv.p_extra += mb_l - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2679 | } |
| 2680 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2681 | ++wlv.p_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2682 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2683 | --wlv.n_extra; |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2684 | #if defined(FEAT_PROP_POPUP) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2685 | if (wlv.n_extra <= 0) |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2686 | { |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 2687 | // Only restore search_attr and area_attr after "n_extra" in |
| 2688 | // the next screen line is also done. |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2689 | if (wlv.saved_n_extra <= 0) |
| 2690 | { |
| 2691 | if (search_attr == 0) |
| 2692 | search_attr = saved_search_attr; |
| 2693 | if (area_attr == 0 && *ptr != NUL) |
| 2694 | area_attr = saved_area_attr; |
Bram Moolenaar | 637862f | 2022-11-24 23:04:02 +0000 | [diff] [blame] | 2695 | |
| 2696 | if (wlv.extra_for_textprop) |
| 2697 | // wlv.extra_attr should be used at this position but |
| 2698 | // not any further. |
| 2699 | reset_extra_attr = TRUE; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2700 | } |
Bram Moolenaar | 637862f | 2022-11-24 23:04:02 +0000 | [diff] [blame] | 2701 | |
| 2702 | wlv.extra_for_textprop = FALSE; |
| 2703 | in_linebreak = FALSE; |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2704 | } |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2705 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2706 | } |
| 2707 | else |
| 2708 | { |
| 2709 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 2710 | int c0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2711 | #endif |
zeertzjq | e500ae8 | 2023-08-17 22:35:26 +0200 | [diff] [blame] | 2712 | char_u *prev_ptr = ptr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2713 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2714 | // Get a character from the line itself. |
| 2715 | c = *ptr; |
| 2716 | #ifdef FEAT_LINEBREAK |
| 2717 | c0 = *ptr; |
| 2718 | #endif |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2719 | if (c == NUL) |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2720 | { |
| 2721 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2722 | // text is finished, may display a "below" virtual text |
| 2723 | did_line = TRUE; |
| 2724 | #endif |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2725 | // no more cells to skip |
| 2726 | skip_cells = 0; |
| 2727 | } |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2728 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2729 | if (has_mbyte) |
| 2730 | { |
| 2731 | mb_c = c; |
| 2732 | if (enc_utf8) |
| 2733 | { |
| 2734 | // If the UTF-8 character is more than one byte: Decode it |
| 2735 | // into "mb_c". |
| 2736 | mb_l = utfc_ptr2len(ptr); |
| 2737 | mb_utf8 = FALSE; |
| 2738 | if (mb_l > 1) |
| 2739 | { |
| 2740 | mb_c = utfc_ptr2char(ptr, u8cc); |
| 2741 | // Overlong encoded ASCII or ASCII with composing char |
| 2742 | // is displayed normally, except a NUL. |
| 2743 | if (mb_c < 0x80) |
| 2744 | { |
| 2745 | c = mb_c; |
| 2746 | #ifdef FEAT_LINEBREAK |
| 2747 | c0 = mb_c; |
| 2748 | #endif |
| 2749 | } |
| 2750 | mb_utf8 = TRUE; |
| 2751 | |
| 2752 | // At start of the line we can have a composing char. |
| 2753 | // Draw it as a space with a composing char. |
| 2754 | if (utf_iscomposing(mb_c)) |
| 2755 | { |
| 2756 | int i; |
| 2757 | |
| 2758 | for (i = Screen_mco - 1; i > 0; --i) |
| 2759 | u8cc[i] = u8cc[i - 1]; |
| 2760 | u8cc[0] = mb_c; |
| 2761 | mb_c = ' '; |
| 2762 | } |
| 2763 | } |
| 2764 | |
| 2765 | if ((mb_l == 1 && c >= 0x80) |
| 2766 | || (mb_l >= 1 && mb_c == 0) |
| 2767 | || (mb_l > 1 && (!vim_isprintc(mb_c)))) |
| 2768 | { |
| 2769 | // Illegal UTF-8 byte: display as <xx>. |
| 2770 | // Non-BMP character : display as ? or fullwidth ?. |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2771 | transchar_hex(wlv.extra, mb_c); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2772 | # ifdef FEAT_RIGHTLEFT |
| 2773 | if (wp->w_p_rl) // reverse |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2774 | rl_mirror(wlv.extra); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2775 | # endif |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2776 | wlv.p_extra = wlv.extra; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2777 | c = *wlv.p_extra; |
| 2778 | mb_c = mb_ptr2char_adv(&wlv.p_extra); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2779 | mb_utf8 = (c >= 0x80); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2780 | wlv.n_extra = (int)STRLEN(wlv.p_extra); |
| 2781 | wlv.c_extra = NUL; |
| 2782 | wlv.c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2783 | if (area_attr == 0 && search_attr == 0) |
| 2784 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2785 | n_attr = wlv.n_extra + 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2786 | wlv.extra_attr = hl_combine_attr( |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2787 | wlv.win_attr, HL_ATTR(HLF_8)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2788 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2789 | } |
| 2790 | } |
| 2791 | else if (mb_l == 0) // at the NUL at end-of-line |
| 2792 | mb_l = 1; |
| 2793 | #ifdef FEAT_ARABIC |
| 2794 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 2795 | { |
| 2796 | // Do Arabic shaping. |
| 2797 | int pc, pc1, nc; |
| 2798 | int pcc[MAX_MCO]; |
| 2799 | |
| 2800 | // The idea of what is the previous and next |
| 2801 | // character depends on 'rightleft'. |
| 2802 | if (wp->w_p_rl) |
| 2803 | { |
| 2804 | pc = prev_c; |
| 2805 | pc1 = prev_c1; |
| 2806 | nc = utf_ptr2char(ptr + mb_l); |
| 2807 | prev_c1 = u8cc[0]; |
| 2808 | } |
| 2809 | else |
| 2810 | { |
| 2811 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
| 2812 | nc = prev_c; |
| 2813 | pc1 = pcc[0]; |
| 2814 | } |
| 2815 | prev_c = mb_c; |
| 2816 | |
| 2817 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
| 2818 | } |
| 2819 | else |
| 2820 | prev_c = mb_c; |
| 2821 | #endif |
| 2822 | } |
| 2823 | else // enc_dbcs |
| 2824 | { |
| 2825 | mb_l = MB_BYTE2LEN(c); |
| 2826 | if (mb_l == 0) // at the NUL at end-of-line |
| 2827 | mb_l = 1; |
| 2828 | else if (mb_l > 1) |
| 2829 | { |
| 2830 | // We assume a second byte below 32 is illegal. |
| 2831 | // Hopefully this is OK for all double-byte encodings! |
| 2832 | if (ptr[1] >= 32) |
| 2833 | mb_c = (c << 8) + ptr[1]; |
| 2834 | else |
| 2835 | { |
| 2836 | if (ptr[1] == NUL) |
| 2837 | { |
| 2838 | // head byte at end of line |
| 2839 | mb_l = 1; |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2840 | transchar_nonprint(wp->w_buffer, wlv.extra, c); |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 2841 | wlv.n_extra = (int)STRLEN(wlv.extra) - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2842 | } |
| 2843 | else |
| 2844 | { |
| 2845 | // illegal tail byte |
| 2846 | mb_l = 2; |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2847 | STRCPY(wlv.extra, "XX"); |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 2848 | wlv.n_extra = 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2849 | } |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2850 | wlv.p_extra = wlv.extra; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2851 | wlv.c_extra = NUL; |
| 2852 | wlv.c_final = NUL; |
| 2853 | c = *wlv.p_extra++; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2854 | if (area_attr == 0 && search_attr == 0) |
| 2855 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2856 | n_attr = wlv.n_extra + 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2857 | wlv.extra_attr = hl_combine_attr( |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2858 | wlv.win_attr, HL_ATTR(HLF_8)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2859 | // save current attr |
| 2860 | saved_attr2 = wlv.char_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2861 | } |
| 2862 | mb_c = c; |
| 2863 | } |
| 2864 | } |
| 2865 | } |
| 2866 | // If a double-width char doesn't fit display a '>' in the |
| 2867 | // last column; the character is displayed at the start of the |
| 2868 | // next line. |
| 2869 | if (( |
| 2870 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2871 | wp->w_p_rl ? (wlv.col <= 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2872 | # endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2873 | (wlv.col >= wp->w_width - 1)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2874 | && (*mb_char2cells)(mb_c) == 2) |
| 2875 | { |
| 2876 | c = '>'; |
| 2877 | mb_c = c; |
| 2878 | mb_utf8 = FALSE; |
| 2879 | mb_l = 1; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2880 | multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2881 | // Put pointer back so that the character will be |
| 2882 | // displayed at the start of the next line. |
| 2883 | --ptr; |
| 2884 | #ifdef FEAT_CONCEAL |
| 2885 | did_decrement_ptr = TRUE; |
| 2886 | #endif |
| 2887 | } |
| 2888 | else if (*ptr != NUL) |
| 2889 | ptr += mb_l - 1; |
| 2890 | |
| 2891 | // If a double-width char doesn't fit at the left side display |
| 2892 | // a '<' in the first column. Don't do this for unprintable |
| 2893 | // characters. |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2894 | if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2895 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2896 | wlv.n_extra = 1; |
| 2897 | wlv.c_extra = MB_FILLER_CHAR; |
| 2898 | wlv.c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2899 | c = ' '; |
| 2900 | if (area_attr == 0 && search_attr == 0) |
| 2901 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2902 | n_attr = wlv.n_extra + 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2903 | wlv.extra_attr = hl_combine_attr( |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2904 | wlv.win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2905 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2906 | } |
| 2907 | mb_c = c; |
| 2908 | mb_utf8 = FALSE; |
| 2909 | mb_l = 1; |
| 2910 | } |
| 2911 | |
| 2912 | } |
| 2913 | ++ptr; |
| 2914 | |
| 2915 | if (extra_check) |
| 2916 | { |
| 2917 | #ifdef FEAT_SPELL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2918 | // Check spelling (unless at the end of the line). |
| 2919 | // Only do this when there is no syntax highlighting, the |
| 2920 | // @Spell cluster is not used or the current syntax item |
| 2921 | // contains the @Spell cluster. |
Bram Moolenaar | 7751d1d | 2019-10-18 20:37:08 +0200 | [diff] [blame] | 2922 | v = (long)(ptr - line); |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2923 | if (spv->spv_has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2924 | { |
| 2925 | spell_attr = 0; |
Christian Brabandt | afa23d1 | 2022-08-09 12:25:10 +0100 | [diff] [blame] | 2926 | // do not calculate cap_col at the end of the line or when |
| 2927 | // only white space is following |
| 2928 | if (c != 0 && (*skipwhite(prev_ptr) != NUL) && ( |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2929 | # ifdef FEAT_SYN_HL |
| 2930 | !has_syntax || |
| 2931 | # endif |
| 2932 | can_spell)) |
| 2933 | { |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 2934 | char_u *p; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2935 | int len; |
| 2936 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 2937 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2938 | if (has_mbyte) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2939 | v -= mb_l - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2940 | |
| 2941 | // Use nextline[] if possible, it has the start of the |
| 2942 | // next line concatenated. |
| 2943 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 2944 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 2945 | else |
| 2946 | p = prev_ptr; |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2947 | spv->spv_cap_col -= (int)(prev_ptr - line); |
| 2948 | len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col, |
| 2949 | spv->spv_unchanged); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2950 | word_end = v + len; |
| 2951 | |
| 2952 | // In Insert mode only highlight a word that |
| 2953 | // doesn't touch the cursor. |
| 2954 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 2955 | && (State & MODE_INSERT) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2956 | && wp->w_cursor.lnum == lnum |
| 2957 | && wp->w_cursor.col >= |
| 2958 | (colnr_T)(prev_ptr - line) |
| 2959 | && wp->w_cursor.col < (colnr_T)word_end) |
| 2960 | { |
| 2961 | spell_hlf = HLF_COUNT; |
| 2962 | spell_redraw_lnum = lnum; |
| 2963 | } |
| 2964 | |
| 2965 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
| 2966 | && (p - nextline) + len > nextline_idx) |
| 2967 | { |
| 2968 | // Remember that the good word continues at the |
| 2969 | // start of the next line. |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2970 | spv->spv_checked_lnum = lnum + 1; |
| 2971 | spv->spv_checked_col = (p - nextline) + len |
| 2972 | - nextline_idx; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | // Turn index into actual attributes. |
| 2976 | if (spell_hlf != HLF_COUNT) |
| 2977 | spell_attr = highlight_attr[spell_hlf]; |
| 2978 | |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2979 | if (spv->spv_cap_col > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2980 | { |
| 2981 | if (p != prev_ptr |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2982 | && (p - nextline) + spv->spv_cap_col |
| 2983 | >= nextline_idx) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2984 | { |
| 2985 | // Remember that the word in the next line |
| 2986 | // must start with a capital. |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2987 | spv->spv_capcol_lnum = lnum + 1; |
| 2988 | spv->spv_cap_col = ((p - nextline) |
| 2989 | + spv->spv_cap_col - nextline_idx); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2990 | } |
| 2991 | else |
| 2992 | // Compute the actual column. |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2993 | spv->spv_cap_col += (prev_ptr - line); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2994 | } |
| 2995 | } |
| 2996 | } |
| 2997 | if (spell_attr != 0) |
| 2998 | { |
| 2999 | if (!attr_pri) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3000 | wlv.char_attr = hl_combine_attr(wlv.char_attr, |
| 3001 | spell_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3002 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3003 | wlv.char_attr = hl_combine_attr(spell_attr, |
| 3004 | wlv.char_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3005 | } |
| 3006 | #endif |
| 3007 | #ifdef FEAT_LINEBREAK |
Christian Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 3008 | // we don't want linebreak to apply for lines that start with |
| 3009 | // leading spaces, followed by long letters (since it would add |
| 3010 | // a break at the beginning of a line and this might be unexpected) |
| 3011 | // |
| 3012 | // So only allow to linebreak, once we have found chars not in |
| 3013 | // 'breakat' in the line. |
| 3014 | if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL && |
| 3015 | !VIM_ISBREAK((int)*ptr)) |
| 3016 | wlv.need_lbr = TRUE; |
| 3017 | #endif |
| 3018 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3019 | // Found last space before word: check for line break. |
Christian Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 3020 | if (wp->w_p_lbr && c0 == c && wlv.need_lbr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3021 | && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr)) |
| 3022 | { |
Bram Moolenaar | 20e0c3d | 2021-08-31 20:57:55 +0200 | [diff] [blame] | 3023 | int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) |
| 3024 | : 0; |
| 3025 | char_u *p = ptr - (mb_off + 1); |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 3026 | chartabsize_T cts; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3027 | |
zeertzjq | ce53e3e | 2023-09-01 18:49:30 +0200 | [diff] [blame] | 3028 | init_chartabsize_arg(&cts, wp, lnum, wlv.vcol |
| 3029 | # ifdef FEAT_PROP_POPUP |
| 3030 | - vcol_first_char, |
| 3031 | # endif |
| 3032 | line, p); |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 3033 | # ifdef FEAT_PROP_POPUP |
| 3034 | // do not want virtual text counted here |
| 3035 | cts.cts_has_prop_with_text = FALSE; |
| 3036 | # endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3037 | wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1; |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 3038 | clear_chartabsize_arg(&cts); |
Bram Moolenaar | a06e345 | 2021-05-29 17:56:37 +0200 | [diff] [blame] | 3039 | |
Bram Moolenaar | 0bbca54 | 2022-01-11 13:14:54 +0000 | [diff] [blame] | 3040 | if (on_last_col && c != TAB) |
Bram Moolenaar | 0c359af | 2021-11-29 19:18:57 +0000 | [diff] [blame] | 3041 | // Do not continue search/match highlighting over the |
Bram Moolenaar | 0bbca54 | 2022-01-11 13:14:54 +0000 | [diff] [blame] | 3042 | // line break, but for TABs the highlighting should |
| 3043 | // include the complete width of the character |
Bram Moolenaar | 0c359af | 2021-11-29 19:18:57 +0000 | [diff] [blame] | 3044 | search_attr = 0; |
Bram Moolenaar | a06e345 | 2021-05-29 17:56:37 +0200 | [diff] [blame] | 3045 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3046 | if (c == TAB && wlv.n_extra + wlv.col > wp->w_width) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3047 | # ifdef FEAT_VARTABS |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3048 | wlv.n_extra = tabstop_padding(wlv.vcol, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3049 | wp->w_buffer->b_p_ts, |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3050 | wp->w_buffer->b_p_vts_array) - 1; |
| 3051 | # else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3052 | wlv.n_extra = (int)wp->w_buffer->b_p_ts |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3053 | - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3054 | # endif |
| 3055 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3056 | wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' '; |
| 3057 | wlv.c_final = NUL; |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 3058 | # ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3059 | if (wlv.n_extra > 0 && c != TAB) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 3060 | in_linebreak = TRUE; |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 3061 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3062 | if (VIM_ISWHITE(c)) |
| 3063 | { |
Bram Moolenaar | 912bc4a | 2019-12-01 18:58:11 +0100 | [diff] [blame] | 3064 | # ifdef FEAT_CONCEAL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3065 | if (c == TAB) |
| 3066 | // See "Tab alignment" below. |
| 3067 | FIX_FOR_BOGUSCOLS; |
Bram Moolenaar | 912bc4a | 2019-12-01 18:58:11 +0100 | [diff] [blame] | 3068 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3069 | if (!wp->w_p_list) |
| 3070 | c = ' '; |
| 3071 | } |
| 3072 | } |
| 3073 | #endif |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 3074 | if (wp->w_p_list) |
| 3075 | { |
| 3076 | in_multispace = c == ' ' && (*ptr == ' ' |
| 3077 | || (prev_ptr > line && prev_ptr[-1] == ' ')); |
| 3078 | if (!in_multispace) |
| 3079 | multispace_pos = 0; |
| 3080 | } |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 3081 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3082 | // 'list': Change char 160 to 'nbsp' and space to 'space' |
| 3083 | // setting in 'listchars'. But not when the character is |
| 3084 | // followed by a composing character (use mb_l to check that). |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3085 | if (wp->w_p_list |
| 3086 | && ((((c == 160 && mb_l == 1) |
| 3087 | || (mb_utf8 |
| 3088 | && ((mb_c == 160 && mb_l == 2) |
| 3089 | || (mb_c == 0x202f && mb_l == 3)))) |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3090 | && wp->w_lcs_chars.nbsp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3091 | || (c == ' ' |
| 3092 | && mb_l == 1 |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 3093 | && (wp->w_lcs_chars.space |
| 3094 | || (in_multispace |
| 3095 | && wp->w_lcs_chars.multispace != NULL)) |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 3096 | && ptr - line >= leadcol |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3097 | && ptr - line <= trailcol))) |
| 3098 | { |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 3099 | if (in_multispace && wp->w_lcs_chars.multispace != NULL) |
| 3100 | { |
| 3101 | c = wp->w_lcs_chars.multispace[multispace_pos++]; |
| 3102 | if (wp->w_lcs_chars.multispace[multispace_pos] == NUL) |
| 3103 | multispace_pos = 0; |
| 3104 | } |
| 3105 | else |
| 3106 | c = (c == ' ') ? wp->w_lcs_chars.space |
| 3107 | : wp->w_lcs_chars.nbsp; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3108 | if (area_attr == 0 && search_attr == 0) |
| 3109 | { |
| 3110 | n_attr = 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3111 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3112 | HL_ATTR(HLF_8)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3113 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3114 | } |
| 3115 | mb_c = c; |
| 3116 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3117 | { |
| 3118 | mb_utf8 = TRUE; |
| 3119 | u8cc[0] = 0; |
| 3120 | c = 0xc0; |
| 3121 | } |
| 3122 | else |
| 3123 | mb_utf8 = FALSE; |
| 3124 | } |
| 3125 | |
zeertzjq | 2e7cba3 | 2022-06-10 15:30:32 +0100 | [diff] [blame] | 3126 | if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol) |
| 3127 | || (leadcol != 0 && ptr < line + leadcol))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3128 | { |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 3129 | if (leadcol != 0 && in_multispace && ptr < line + leadcol |
| 3130 | && wp->w_lcs_chars.leadmultispace != NULL) |
| 3131 | { |
| 3132 | c = wp->w_lcs_chars.leadmultispace[multispace_pos++]; |
zeertzjq | 2e7cba3 | 2022-06-10 15:30:32 +0100 | [diff] [blame] | 3133 | if (wp->w_lcs_chars.leadmultispace[multispace_pos] |
| 3134 | == NUL) |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 3135 | multispace_pos = 0; |
| 3136 | } |
| 3137 | |
| 3138 | else if (ptr > line + trailcol && wp->w_lcs_chars.trail) |
| 3139 | c = wp->w_lcs_chars.trail; |
| 3140 | |
| 3141 | else if (ptr < line + leadcol && wp->w_lcs_chars.lead) |
| 3142 | c = wp->w_lcs_chars.lead; |
| 3143 | |
zeertzjq | 2e7cba3 | 2022-06-10 15:30:32 +0100 | [diff] [blame] | 3144 | else if (leadcol != 0 && wp->w_lcs_chars.space) |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 3145 | c = wp->w_lcs_chars.space; |
| 3146 | |
| 3147 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3148 | if (!attr_pri) |
| 3149 | { |
| 3150 | n_attr = 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3151 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3152 | HL_ATTR(HLF_8)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3153 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3154 | } |
| 3155 | mb_c = c; |
| 3156 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3157 | { |
| 3158 | mb_utf8 = TRUE; |
| 3159 | u8cc[0] = 0; |
| 3160 | c = 0xc0; |
| 3161 | } |
| 3162 | else |
| 3163 | mb_utf8 = FALSE; |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | // Handling of non-printable characters. |
| 3168 | if (!vim_isprintc(c)) |
| 3169 | { |
| 3170 | // when getting a character from the file, we may have to |
| 3171 | // turn it into something else on the way to putting it |
| 3172 | // into "ScreenLines". |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3173 | if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3174 | { |
Bram Moolenaar | c67c89c | 2022-12-02 16:39:44 +0000 | [diff] [blame] | 3175 | int tab_len = 0; |
| 3176 | long vcol_adjusted = wlv.vcol; // removed showbreak len |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3177 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | c67c89c | 2022-12-02 16:39:44 +0000 | [diff] [blame] | 3178 | char_u *sbr = get_showbreak_value(wp); |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 3179 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3180 | // only adjust the tab_len, when at the first column |
| 3181 | // after the showbreak value was drawn |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 3182 | if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3183 | vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3184 | #endif |
| 3185 | // tab amount depends on current column |
| 3186 | #ifdef FEAT_VARTABS |
| 3187 | tab_len = tabstop_padding(vcol_adjusted, |
| 3188 | wp->w_buffer->b_p_ts, |
| 3189 | wp->w_buffer->b_p_vts_array) - 1; |
| 3190 | #else |
| 3191 | tab_len = (int)wp->w_buffer->b_p_ts |
| 3192 | - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; |
| 3193 | #endif |
| 3194 | |
| 3195 | #ifdef FEAT_LINEBREAK |
| 3196 | if (!wp->w_p_lbr || !wp->w_p_list) |
| 3197 | #endif |
Bram Moolenaar | c67c89c | 2022-12-02 16:39:44 +0000 | [diff] [blame] | 3198 | { |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3199 | // tab amount depends on current column |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3200 | wlv.n_extra = tab_len; |
Bram Moolenaar | c67c89c | 2022-12-02 16:39:44 +0000 | [diff] [blame] | 3201 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3202 | #ifdef FEAT_LINEBREAK |
| 3203 | else |
| 3204 | { |
| 3205 | char_u *p; |
| 3206 | int len; |
| 3207 | int i; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3208 | int saved_nextra = wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3209 | |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3210 | # ifdef FEAT_CONCEAL |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3211 | if (wlv.vcol_off_co > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3212 | // there are characters to conceal |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3213 | tab_len += wlv.vcol_off_co; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3214 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3215 | // boguscols before FIX_FOR_BOGUSCOLS macro from above |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3216 | if (wp->w_p_list && wp->w_lcs_chars.tab1 |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3217 | && old_boguscols > 0 |
| 3218 | && wlv.n_extra > tab_len) |
| 3219 | tab_len += wlv.n_extra - tab_len; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3220 | # endif |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3221 | if (tab_len > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3222 | { |
Bram Moolenaar | c67c89c | 2022-12-02 16:39:44 +0000 | [diff] [blame] | 3223 | // If wlv.n_extra > 0, it gives the number of chars |
| 3224 | // to use for a tab, else we need to calculate the |
| 3225 | // width for a tab. |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3226 | int tab2_len = mb_char2len(wp->w_lcs_chars.tab2); |
| 3227 | len = tab_len * tab2_len; |
| 3228 | if (wp->w_lcs_chars.tab3) |
| 3229 | len += mb_char2len(wp->w_lcs_chars.tab3) |
| 3230 | - tab2_len; |
| 3231 | if (wlv.n_extra > 0) |
| 3232 | len += wlv.n_extra - tab_len; |
| 3233 | c = wp->w_lcs_chars.tab1; |
| 3234 | p = alloc(len + 1); |
| 3235 | if (p == NULL) |
| 3236 | wlv.n_extra = 0; |
| 3237 | else |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3238 | { |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3239 | vim_memset(p, ' ', len); |
| 3240 | p[len] = NUL; |
| 3241 | vim_free(wlv.p_extra_free); |
| 3242 | wlv.p_extra_free = p; |
| 3243 | for (i = 0; i < tab_len; i++) |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3244 | { |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3245 | int lcs = wp->w_lcs_chars.tab2; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3246 | |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3247 | if (*p == NUL) |
| 3248 | { |
| 3249 | tab_len = i; |
| 3250 | break; |
| 3251 | } |
| 3252 | |
| 3253 | // if tab3 is given, use it for the last |
| 3254 | // char |
| 3255 | if (wp->w_lcs_chars.tab3 |
| 3256 | && i == tab_len - 1) |
| 3257 | lcs = wp->w_lcs_chars.tab3; |
| 3258 | p += mb_char2bytes(lcs, p); |
| 3259 | wlv.n_extra += mb_char2len(lcs) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3260 | - (saved_nextra > 0 ? 1 : 0); |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3261 | } |
| 3262 | wlv.p_extra = wlv.p_extra_free; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3263 | # ifdef FEAT_CONCEAL |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3264 | // n_extra will be increased by |
| 3265 | // FIX_FOX_BOGUSCOLS macro below, so need to |
| 3266 | // adjust for that here |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3267 | if (wlv.vcol_off_co > 0) |
| 3268 | wlv.n_extra -= wlv.vcol_off_co; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3269 | # endif |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3270 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3271 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3272 | } |
| 3273 | #endif |
| 3274 | #ifdef FEAT_CONCEAL |
| 3275 | { |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3276 | int vc_saved = wlv.vcol_off_co; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3277 | |
| 3278 | // Tab alignment should be identical regardless of |
| 3279 | // 'conceallevel' value. So tab compensates of all |
| 3280 | // previous concealed characters, and thus resets |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3281 | // vcol_off_co and boguscols accumulated so far in the |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3282 | // line. Note that the tab can be longer than |
| 3283 | // 'tabstop' when there are concealed characters. |
| 3284 | FIX_FOR_BOGUSCOLS; |
| 3285 | |
| 3286 | // Make sure, the highlighting for the tab char will be |
| 3287 | // correctly set further below (effectively reverts the |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 3288 | // FIX_FOR_BOGUSCOLS macro). |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3289 | if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3290 | && wp->w_lcs_chars.tab1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3291 | tab_len += vc_saved; |
| 3292 | } |
| 3293 | #endif |
| 3294 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 3295 | if (wp->w_p_list) |
| 3296 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3297 | c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3) |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3298 | ? wp->w_lcs_chars.tab3 |
| 3299 | : wp->w_lcs_chars.tab1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3300 | #ifdef FEAT_LINEBREAK |
h-east | 194555c | 2023-03-02 18:49:09 +0000 | [diff] [blame] | 3301 | if (wp->w_p_lbr && wlv.p_extra != NULL |
| 3302 | && *wlv.p_extra != NUL) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3303 | wlv.c_extra = NUL; // using p_extra from above |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3304 | else |
| 3305 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3306 | wlv.c_extra = wp->w_lcs_chars.tab2; |
| 3307 | wlv.c_final = wp->w_lcs_chars.tab3; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3308 | n_attr = tab_len + 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3309 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3310 | HL_ATTR(HLF_8)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3311 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3312 | mb_c = c; |
| 3313 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3314 | { |
| 3315 | mb_utf8 = TRUE; |
| 3316 | u8cc[0] = 0; |
| 3317 | c = 0xc0; |
| 3318 | } |
| 3319 | } |
| 3320 | else |
| 3321 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3322 | wlv.c_final = NUL; |
| 3323 | wlv.c_extra = ' '; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3324 | c = ' '; |
| 3325 | } |
| 3326 | } |
| 3327 | else if (c == NUL |
Bram Moolenaar | 234c3fa | 2023-02-12 14:42:15 +0000 | [diff] [blame] | 3328 | && wlv.n_extra == 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3329 | && (wp->w_p_list |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 3330 | || ((wlv.fromcol >= 0 || fromcol_prev >= 0) |
| 3331 | && wlv.tocol > wlv.vcol |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3332 | && VIsual_mode != Ctrl_V |
| 3333 | && ( |
| 3334 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3335 | wp->w_p_rl ? (wlv.col >= 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3336 | # endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3337 | (wlv.col < wp->w_width)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3338 | && !(noinvcur |
| 3339 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3340 | && (colnr_T)wlv.vcol == wp->w_virtcol))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3341 | && lcs_eol_one > 0) |
| 3342 | { |
| 3343 | // Display a '$' after the line or highlight an extra |
| 3344 | // character if the line break is included. |
| 3345 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 3346 | // For a diff line the highlighting continues after the |
| 3347 | // "$". |
| 3348 | if ( |
| 3349 | # ifdef FEAT_DIFF |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3350 | wlv.diff_hlf == (hlf_T)0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3351 | # ifdef LINE_ATTR |
| 3352 | && |
| 3353 | # endif |
| 3354 | # endif |
| 3355 | # ifdef LINE_ATTR |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3356 | wlv.line_attr == 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3357 | # endif |
| 3358 | ) |
| 3359 | #endif |
| 3360 | { |
| 3361 | // In virtualedit, visual selections may extend |
| 3362 | // beyond end of line. |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 3363 | if (!(area_highlighting && virtual_active() |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 3364 | && wlv.tocol != MAXCOL |
| 3365 | && wlv.vcol < wlv.tocol)) |
Dylan Thacker-Smith | f548ae7 | 2024-02-24 10:17:11 +0100 | [diff] [blame] | 3366 | wlv.p_extra = (char_u *)""; |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 3367 | wlv.n_extra = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3368 | } |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3369 | if (wp->w_p_list && wp->w_lcs_chars.eol > 0) |
| 3370 | c = wp->w_lcs_chars.eol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3371 | else |
| 3372 | c = ' '; |
| 3373 | lcs_eol_one = -1; |
| 3374 | --ptr; // put it back at the NUL |
| 3375 | if (!attr_pri) |
| 3376 | { |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3377 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3378 | HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3379 | n_attr = 1; |
| 3380 | } |
| 3381 | mb_c = c; |
| 3382 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3383 | { |
| 3384 | mb_utf8 = TRUE; |
| 3385 | u8cc[0] = 0; |
| 3386 | c = 0xc0; |
| 3387 | } |
| 3388 | else |
| 3389 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 3390 | } |
| 3391 | else if (c != NUL) |
| 3392 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3393 | wlv.p_extra = transchar_buf(wp->w_buffer, c); |
| 3394 | if (wlv.n_extra == 0) |
| 3395 | wlv.n_extra = byte2cells(c) - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3396 | #ifdef FEAT_RIGHTLEFT |
| 3397 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3398 | rl_mirror(wlv.p_extra); // reverse "<12>" |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3399 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3400 | wlv.c_extra = NUL; |
| 3401 | wlv.c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3402 | #ifdef FEAT_LINEBREAK |
| 3403 | if (wp->w_p_lbr) |
| 3404 | { |
| 3405 | char_u *p; |
| 3406 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3407 | c = *wlv.p_extra; |
| 3408 | p = alloc(wlv.n_extra + 1); |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 3409 | if (p == NULL) |
| 3410 | wlv.n_extra = 0; |
| 3411 | else |
| 3412 | { |
| 3413 | vim_memset(p, ' ', wlv.n_extra); |
| 3414 | STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1); |
| 3415 | p[wlv.n_extra] = NUL; |
| 3416 | vim_free(wlv.p_extra_free); |
| 3417 | wlv.p_extra_free = wlv.p_extra = p; |
| 3418 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3419 | } |
| 3420 | else |
| 3421 | #endif |
| 3422 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3423 | wlv.n_extra = byte2cells(c) - 1; |
| 3424 | c = *wlv.p_extra++; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3425 | } |
| 3426 | if (!attr_pri) |
| 3427 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3428 | n_attr = wlv.n_extra + 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3429 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3430 | HL_ATTR(HLF_8)); |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 3431 | #ifdef FEAT_PROP_POPUP |
| 3432 | if (text_prop_type != NULL && |
| 3433 | text_prop_flags & PT_FLAG_OVERRIDE) |
| 3434 | wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr); |
| 3435 | #endif |
| 3436 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3437 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3438 | } |
| 3439 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 3440 | } |
| 3441 | else if (VIsual_active |
| 3442 | && (VIsual_mode == Ctrl_V |
| 3443 | || VIsual_mode == 'v') |
| 3444 | && virtual_active() |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 3445 | && wlv.tocol != MAXCOL |
| 3446 | && wlv.vcol < wlv.tocol |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3447 | && ( |
| 3448 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3449 | wp->w_p_rl ? (wlv.col >= 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3450 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3451 | (wlv.col < wp->w_width))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3452 | { |
| 3453 | c = ' '; |
| 3454 | --ptr; // put it back at the NUL |
| 3455 | } |
| 3456 | #if defined(LINE_ATTR) |
| 3457 | else if (( |
| 3458 | # ifdef FEAT_DIFF |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3459 | wlv.diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3460 | # endif |
| 3461 | # ifdef FEAT_TERMINAL |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3462 | wlv.win_attr != 0 || |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3463 | # endif |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3464 | wlv.line_attr != 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3465 | ) && ( |
| 3466 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3467 | wp->w_p_rl ? (wlv.col >= 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3468 | # endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3469 | (wlv.col |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3470 | # ifdef FEAT_CONCEAL |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3471 | - wlv.boguscols |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3472 | # endif |
| 3473 | < wp->w_width))) |
| 3474 | { |
| 3475 | // Highlight until the right side of the window |
| 3476 | c = ' '; |
| 3477 | --ptr; // put it back at the NUL |
| 3478 | |
| 3479 | // Remember we do the char for line highlighting. |
| 3480 | ++did_line_attr; |
| 3481 | |
| 3482 | // don't do search HL for the rest of the line |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3483 | if (wlv.line_attr != 0 && wlv.char_attr == search_attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3484 | && (did_line_attr > 1 |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3485 | || (wp->w_p_list && |
| 3486 | wp->w_lcs_chars.eol > 0))) |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3487 | wlv.char_attr = wlv.line_attr; |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 3488 | #ifdef FEAT_SIGNS |
| 3489 | // At end of line: if Sign is present with line highlight, reset char_attr |
Christian Brabandt | e1eaae2 | 2023-08-19 22:36:12 +0200 | [diff] [blame] | 3490 | // but not when cursorline is active |
| 3491 | if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE |
| 3492 | && !(wp->w_p_cul && lnum == wp->w_cursor.lnum)) |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 3493 | wlv.char_attr = wlv.sattr.sat_linehl; |
| 3494 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3495 | # ifdef FEAT_DIFF |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3496 | if (wlv.diff_hlf == HLF_TXD) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3497 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3498 | wlv.diff_hlf = HLF_CHD; |
| 3499 | if (vi_attr == 0 || wlv.char_attr != vi_attr) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3500 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3501 | wlv.char_attr = HL_ATTR(wlv.diff_hlf); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3502 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 3503 | && wp->w_p_culopt_flags != CULOPT_NBR |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3504 | && (!wlv.cul_screenline |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3505 | || (wlv.vcol >= left_curline_col |
| 3506 | && wlv.vcol <= right_curline_col))) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3507 | wlv.char_attr = hl_combine_attr( |
| 3508 | wlv.char_attr, HL_ATTR(HLF_CUL)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3509 | } |
| 3510 | } |
| 3511 | # endif |
| 3512 | # ifdef FEAT_TERMINAL |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3513 | if (wlv.win_attr != 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3514 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3515 | wlv.char_attr = wlv.win_attr; |
Bram Moolenaar | a381773 | 2019-10-16 16:31:44 +0200 | [diff] [blame] | 3516 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 3517 | && wp->w_p_culopt_flags != CULOPT_NBR) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3518 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3519 | if (!wlv.cul_screenline |
| 3520 | || (wlv.vcol >= left_curline_col |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3521 | && wlv.vcol <= right_curline_col)) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3522 | wlv.char_attr = hl_combine_attr( |
| 3523 | wlv.char_attr, HL_ATTR(HLF_CUL)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3524 | } |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3525 | else if (wlv.line_attr) |
| 3526 | wlv.char_attr = hl_combine_attr( |
| 3527 | wlv.char_attr, wlv.line_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3528 | } |
| 3529 | # endif |
| 3530 | } |
| 3531 | #endif |
| 3532 | } |
| 3533 | |
| 3534 | #ifdef FEAT_CONCEAL |
| 3535 | if ( wp->w_p_cole > 0 |
LemonBoy | 9830db6 | 2022-05-08 21:25:20 +0100 | [diff] [blame] | 3536 | && (wp != curwin || lnum != wp->w_cursor.lnum |
| 3537 | || conceal_cursor_line(wp)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3538 | && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0) |
| 3539 | && !(lnum_in_visual_area |
| 3540 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
| 3541 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3542 | wlv.char_attr = conceal_attr; |
LemonBoy | 9830db6 | 2022-05-08 21:25:20 +0100 | [diff] [blame] | 3543 | if (((prev_syntax_id != syntax_seqnr |
| 3544 | && (syntax_flags & HL_CONCEAL) != 0) |
| 3545 | || has_match_conc > 1) |
Bram Moolenaar | 211dd3f | 2020-06-25 20:07:04 +0200 | [diff] [blame] | 3546 | && (syn_get_sub_char() != NUL |
| 3547 | || (has_match_conc && match_conc) |
| 3548 | || wp->w_p_cole == 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3549 | && wp->w_p_cole != 3) |
| 3550 | { |
| 3551 | // First time at this concealed item: display one |
| 3552 | // character. |
Bram Moolenaar | 211dd3f | 2020-06-25 20:07:04 +0200 | [diff] [blame] | 3553 | if (has_match_conc && match_conc) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3554 | c = match_conc; |
| 3555 | else if (syn_get_sub_char() != NUL) |
| 3556 | c = syn_get_sub_char(); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3557 | else if (wp->w_lcs_chars.conceal != NUL) |
| 3558 | c = wp->w_lcs_chars.conceal; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3559 | else |
| 3560 | c = ' '; |
| 3561 | |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 3562 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 3563 | // When the first char to be concealed is double-width, |
| 3564 | // need to advance one more virtual column. |
| 3565 | wlv.n_extra++; |
| 3566 | |
| 3567 | mb_c = c; |
| 3568 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3569 | { |
| 3570 | mb_utf8 = TRUE; |
| 3571 | u8cc[0] = 0; |
| 3572 | c = 0xc0; |
| 3573 | } |
| 3574 | else |
| 3575 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 3576 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3577 | prev_syntax_id = syntax_seqnr; |
| 3578 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3579 | if (wlv.n_extra > 0) |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3580 | wlv.vcol_off_co += wlv.n_extra; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3581 | wlv.vcol += wlv.n_extra; |
| 3582 | if (wp->w_p_wrap && wlv.n_extra > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3583 | { |
| 3584 | # ifdef FEAT_RIGHTLEFT |
| 3585 | if (wp->w_p_rl) |
| 3586 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3587 | wlv.col -= wlv.n_extra; |
| 3588 | wlv.boguscols -= wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3589 | } |
| 3590 | else |
| 3591 | # endif |
| 3592 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3593 | wlv.boguscols += wlv.n_extra; |
| 3594 | wlv.col += wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3595 | } |
| 3596 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3597 | wlv.n_extra = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3598 | n_attr = 0; |
| 3599 | } |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 3600 | else if (skip_cells == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3601 | { |
| 3602 | is_concealing = TRUE; |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 3603 | skip_cells = 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3604 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3605 | } |
| 3606 | else |
| 3607 | { |
| 3608 | prev_syntax_id = 0; |
| 3609 | is_concealing = FALSE; |
| 3610 | } |
| 3611 | |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 3612 | if (skip_cells > 0 && did_decrement_ptr) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3613 | // not showing the '>', put pointer back to avoid getting stuck |
| 3614 | ++ptr; |
| 3615 | |
| 3616 | #endif // FEAT_CONCEAL |
| 3617 | } |
| 3618 | |
| 3619 | #ifdef FEAT_CONCEAL |
| 3620 | // In the cursor line and we may be concealing characters: correct |
| 3621 | // the cursor column when we reach its position. |
zeertzjq | 253ff4d | 2024-03-13 20:38:26 +0100 | [diff] [blame] | 3622 | // With 'virtualedit' we may never reach cursor position, but we still |
| 3623 | // need to correct the cursor column, so do that at end of line. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3624 | if (!did_wcol && wlv.draw_state == WL_LINE |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 3625 | && in_curline && conceal_cursor_line(wp) |
zeertzjq | 253ff4d | 2024-03-13 20:38:26 +0100 | [diff] [blame] | 3626 | && (wlv.vcol + skip_cells >= wp->w_virtcol || c == NUL)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3627 | { |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 3628 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3629 | if (wp->w_p_rl) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3630 | wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3631 | else |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 3632 | # endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3633 | wp->w_wcol = wlv.col - wlv.boguscols; |
zeertzjq | 253ff4d | 2024-03-13 20:38:26 +0100 | [diff] [blame] | 3634 | if (wlv.vcol + skip_cells < wp->w_virtcol) |
| 3635 | // Cursor beyond end of the line with 'virtualedit'. |
| 3636 | wp->w_wcol += wp->w_virtcol - wlv.vcol - skip_cells; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3637 | wp->w_wrow = wlv.row; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3638 | did_wcol = TRUE; |
| 3639 | curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL; |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 3640 | # ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 6a07644 | 2020-11-15 20:32:58 +0100 | [diff] [blame] | 3641 | curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED); |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 3642 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3643 | } |
| 3644 | #endif |
| 3645 | |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3646 | // Use "wlv.extra_attr", but don't override visual selection |
| 3647 | // highlighting, unless text property overrides. |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 3648 | // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero. |
| 3649 | if (wlv.n_attr_skip == 0 && n_attr > 0 |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3650 | && wlv.draw_state == WL_LINE |
Bram Moolenaar | 677a39f | 2022-08-14 16:50:42 +0100 | [diff] [blame] | 3651 | && (!attr_pri |
| 3652 | #ifdef FEAT_PROP_POPUP |
| 3653 | || (text_prop_flags & PT_FLAG_OVERRIDE) |
| 3654 | #endif |
| 3655 | )) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3656 | { |
| 3657 | #ifdef LINE_ATTR |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3658 | if (wlv.line_attr) |
| 3659 | wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3660 | else |
| 3661 | #endif |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3662 | wlv.char_attr = wlv.extra_attr; |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 3663 | #ifdef FEAT_PROP_POPUP |
| 3664 | if (reset_extra_attr) |
| 3665 | { |
| 3666 | reset_extra_attr = FALSE; |
| 3667 | wlv.extra_attr = 0; |
| 3668 | } |
| 3669 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
| 3673 | // XIM don't send preedit_start and preedit_end, but they send |
| 3674 | // preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 3675 | // im_is_preediting() here. |
| 3676 | if (p_imst == IM_ON_THE_SPOT |
| 3677 | && xic != NULL |
| 3678 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 3679 | && (State & MODE_INSERT) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3680 | && !p_imdisable |
| 3681 | && im_is_preediting() |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3682 | && wlv.draw_state == WL_LINE) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3683 | { |
| 3684 | colnr_T tcol; |
| 3685 | |
| 3686 | if (preedit_end_col == MAXCOL) |
| 3687 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
| 3688 | else |
| 3689 | tcol = preedit_end_col; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3690 | if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3691 | { |
| 3692 | if (feedback_old_attr < 0) |
| 3693 | { |
| 3694 | feedback_col = 0; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3695 | feedback_old_attr = wlv.char_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3696 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3697 | wlv.char_attr = im_get_feedback_attr(feedback_col); |
| 3698 | if (wlv.char_attr < 0) |
| 3699 | wlv.char_attr = feedback_old_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3700 | feedback_col++; |
| 3701 | } |
| 3702 | else if (feedback_old_attr >= 0) |
| 3703 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3704 | wlv.char_attr = feedback_old_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3705 | feedback_old_attr = -1; |
| 3706 | feedback_col = 0; |
| 3707 | } |
| 3708 | } |
| 3709 | #endif |
| 3710 | // Handle the case where we are in column 0 but not on the first |
| 3711 | // character of the line and the user wants us to show us a |
| 3712 | // special character (via 'listchars' option "precedes:<char>". |
| 3713 | if (lcs_prec_todo != NUL |
| 3714 | && wp->w_p_list |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 3715 | && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0) |
| 3716 | : wp->w_leftcol > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3717 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 3718 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3719 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3720 | && wlv.draw_state > WL_NR |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3721 | && c != NUL) |
| 3722 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3723 | c = wp->w_lcs_chars.prec; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3724 | lcs_prec_todo = NUL; |
| 3725 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 3726 | { |
| 3727 | // Double-width character being overwritten by the "precedes" |
| 3728 | // character, need to fill up half the character. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3729 | wlv.c_extra = MB_FILLER_CHAR; |
| 3730 | wlv.c_final = NUL; |
| 3731 | wlv.n_extra = 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3732 | n_attr = 2; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3733 | wlv.extra_attr = |
| 3734 | hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3735 | } |
| 3736 | mb_c = c; |
| 3737 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3738 | { |
| 3739 | mb_utf8 = TRUE; |
| 3740 | u8cc[0] = 0; |
| 3741 | c = 0xc0; |
| 3742 | } |
| 3743 | else |
| 3744 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 3745 | if (!attr_pri) |
| 3746 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3747 | saved_attr3 = wlv.char_attr; // save current attr |
| 3748 | wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3749 | n_attr3 = 1; |
| 3750 | } |
| 3751 | } |
| 3752 | |
| 3753 | // At end of the text line or just after the last character. |
| 3754 | if ((c == NUL |
| 3755 | #if defined(LINE_ATTR) |
| 3756 | || did_line_attr == 1 |
| 3757 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3758 | ) && wlv.eol_hl_off == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3759 | { |
| 3760 | #ifdef FEAT_SEARCH_EXTRA |
| 3761 | // flag to indicate whether prevcol equals startcol of search_hl or |
| 3762 | // one of the matches |
| 3763 | int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl, |
| 3764 | (long)(ptr - line) - (c == NUL)); |
| 3765 | #endif |
| 3766 | // Invert at least one char, used for Visual and empty line or |
| 3767 | // highlight match at end of line. If it's beyond the last |
| 3768 | // char on the screen, just overwrite that one (tricky!) Not |
| 3769 | // needed when a '$' was displayed for 'list'. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3770 | if (wp->w_lcs_chars.eol == lcs_eol_one |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 3771 | && ((area_attr != 0 && wlv.vcol == wlv.fromcol |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3772 | && (VIsual_mode != Ctrl_V |
| 3773 | || lnum == VIsual.lnum |
| 3774 | || lnum == curwin->w_cursor.lnum) |
| 3775 | && c == NUL) |
| 3776 | #ifdef FEAT_SEARCH_EXTRA |
| 3777 | // highlight 'hlsearch' match at end of line |
| 3778 | || (prevcol_hl_flag |
| 3779 | # ifdef FEAT_SYN_HL |
| 3780 | && !(wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 3781 | && !(wp == curwin && VIsual_active)) |
| 3782 | # endif |
| 3783 | # ifdef FEAT_DIFF |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3784 | && wlv.diff_hlf == (hlf_T)0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3785 | # endif |
| 3786 | # if defined(LINE_ATTR) |
| 3787 | && did_line_attr <= 1 |
| 3788 | # endif |
| 3789 | ) |
| 3790 | #endif |
| 3791 | )) |
| 3792 | { |
| 3793 | int n = 0; |
| 3794 | |
| 3795 | #ifdef FEAT_RIGHTLEFT |
| 3796 | if (wp->w_p_rl) |
| 3797 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3798 | if (wlv.col < 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3799 | n = 1; |
| 3800 | } |
| 3801 | else |
| 3802 | #endif |
| 3803 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3804 | if (wlv.col >= wp->w_width) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3805 | n = -1; |
| 3806 | } |
| 3807 | if (n != 0) |
| 3808 | { |
| 3809 | // At the window boundary, highlight the last character |
| 3810 | // instead (better than nothing). |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3811 | wlv.off += n; |
| 3812 | wlv.col += n; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3813 | } |
| 3814 | else |
| 3815 | { |
| 3816 | // Add a blank character to highlight. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3817 | ScreenLines[wlv.off] = ' '; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3818 | if (enc_utf8) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3819 | ScreenLinesUC[wlv.off] = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3820 | } |
| 3821 | #ifdef FEAT_SEARCH_EXTRA |
| 3822 | if (area_attr == 0) |
| 3823 | { |
| 3824 | // Use attributes from match with highest priority among |
| 3825 | // 'search_hl' and the match list. |
| 3826 | get_search_match_hl(wp, &screen_search_hl, |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3827 | (long)(ptr - line), &wlv.char_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3828 | } |
| 3829 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3830 | ScreenAttrs[wlv.off] = wlv.char_attr; |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 3831 | ScreenCols[wlv.off] = wlv.vcol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3832 | #ifdef FEAT_RIGHTLEFT |
| 3833 | if (wp->w_p_rl) |
| 3834 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3835 | --wlv.col; |
| 3836 | --wlv.off; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3837 | } |
| 3838 | else |
| 3839 | #endif |
| 3840 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3841 | ++wlv.col; |
| 3842 | ++wlv.off; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3843 | } |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3844 | ++wlv.vcol; |
| 3845 | wlv.eol_hl_off = 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3846 | } |
| 3847 | } |
| 3848 | |
| 3849 | // At end of the text line. |
| 3850 | if (c == NUL) |
| 3851 | { |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3852 | #ifdef FEAT_PROP_POPUP |
| 3853 | if (text_prop_follows) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3854 | { |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3855 | // Put the pointer back to the NUL. |
| 3856 | --ptr; |
| 3857 | c = ' '; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3858 | } |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3859 | else |
| 3860 | #endif |
| 3861 | { |
| 3862 | draw_screen_line(wp, &wlv); |
| 3863 | |
| 3864 | // Update w_cline_height and w_cline_folded if the cursor line |
| 3865 | // was updated (saves a call to plines() later). |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 3866 | if (in_curline) |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3867 | { |
| 3868 | curwin->w_cline_row = startrow; |
| 3869 | curwin->w_cline_height = wlv.row - startrow; |
| 3870 | #ifdef FEAT_FOLDING |
| 3871 | curwin->w_cline_folded = FALSE; |
| 3872 | #endif |
| 3873 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 3874 | } |
| 3875 | break; |
| 3876 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | // Show "extends" character from 'listchars' if beyond the line end and |
| 3880 | // 'list' is set. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3881 | if (wp->w_lcs_chars.ext != NUL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3882 | && wlv.draw_state == WL_LINE |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3883 | && wp->w_p_list |
| 3884 | && !wp->w_p_wrap |
| 3885 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 3886 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3887 | #endif |
| 3888 | && ( |
| 3889 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3890 | wp->w_p_rl ? wlv.col == 0 : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3891 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3892 | wlv.col == wp->w_width - 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3893 | && (*ptr != NUL |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 3894 | || lcs_eol_one > 0 |
| 3895 | || (wlv.n_extra > 0 && (wlv.c_extra != NUL |
zeertzjq | 6a38972 | 2023-08-27 19:04:14 +0200 | [diff] [blame] | 3896 | || *wlv.p_extra != NUL)) |
| 3897 | #ifdef FEAT_PROP_POPUP |
zeertzjq | 4e26a9a | 2023-12-03 17:50:47 +0100 | [diff] [blame] | 3898 | || text_prop_next <= last_textprop_text_idx |
zeertzjq | 6a38972 | 2023-08-27 19:04:14 +0200 | [diff] [blame] | 3899 | #endif |
| 3900 | )) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3901 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3902 | c = wp->w_lcs_chars.ext; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3903 | wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3904 | mb_c = c; |
| 3905 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3906 | { |
| 3907 | mb_utf8 = TRUE; |
| 3908 | u8cc[0] = 0; |
| 3909 | c = 0xc0; |
| 3910 | } |
| 3911 | else |
| 3912 | mb_utf8 = FALSE; |
| 3913 | } |
| 3914 | |
| 3915 | #ifdef FEAT_SYN_HL |
| 3916 | // advance to the next 'colorcolumn' |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3917 | if (wlv.draw_color_col) |
| 3918 | wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3919 | |
| 3920 | // Highlight the cursor column if 'cursorcolumn' is set. But don't |
| 3921 | // highlight the cursor position itself. |
| 3922 | // Also highlight the 'colorcolumn' if it is different than |
| 3923 | // 'cursorcolumn' |
Bram Moolenaar | ad5e563 | 2020-09-15 20:52:26 +0200 | [diff] [blame] | 3924 | // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak' |
| 3925 | // options are set |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3926 | vcol_save_attr = -1; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3927 | if (((wlv.draw_state == WL_LINE |
| 3928 | || wlv.draw_state == WL_BRI |
| 3929 | || wlv.draw_state == WL_SBR) |
| 3930 | && !lnum_in_visual_area |
| 3931 | && search_attr == 0 |
| 3932 | && area_attr == 0) |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 3933 | # ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 3934 | && wlv.filler_todo <= 0 |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 3935 | # endif |
| 3936 | ) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3937 | { |
| 3938 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
| 3939 | && lnum != wp->w_cursor.lnum) |
| 3940 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3941 | vcol_save_attr = wlv.char_attr; |
| 3942 | wlv.char_attr = hl_combine_attr(wlv.char_attr, |
| 3943 | HL_ATTR(HLF_CUC)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3944 | } |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3945 | else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3946 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3947 | vcol_save_attr = wlv.char_attr; |
| 3948 | wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3949 | } |
| 3950 | } |
| 3951 | #endif |
| 3952 | |
zeertzjq | 8fc6a1d | 2023-08-20 18:12:54 +0200 | [diff] [blame] | 3953 | if (wlv.draw_state == WL_LINE) |
| 3954 | vcol_prev = wlv.vcol; |
| 3955 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3956 | // Store character to be displayed. |
| 3957 | // Skip characters that are left of the screen for 'nowrap'. |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 3958 | if (wlv.draw_state < WL_LINE || skip_cells <= 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3959 | { |
| 3960 | // Store the character. |
| 3961 | #if defined(FEAT_RIGHTLEFT) |
| 3962 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 3963 | { |
Dominique Pelle | af4a61a | 2021-12-27 17:21:41 +0000 | [diff] [blame] | 3964 | // A double-wide character is: put first half in left cell. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3965 | --wlv.off; |
| 3966 | --wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3967 | } |
| 3968 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3969 | ScreenLines[wlv.off] = c; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3970 | if (enc_dbcs == DBCS_JPNU) |
| 3971 | { |
| 3972 | if ((mb_c & 0xff00) == 0x8e00) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3973 | ScreenLines[wlv.off] = 0x8e; |
| 3974 | ScreenLines2[wlv.off] = mb_c & 0xff; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3975 | } |
| 3976 | else if (enc_utf8) |
| 3977 | { |
| 3978 | if (mb_utf8) |
| 3979 | { |
| 3980 | int i; |
| 3981 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3982 | ScreenLinesUC[wlv.off] = mb_c; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3983 | if ((c & 0xff) == 0) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3984 | ScreenLines[wlv.off] = 0x80; // avoid storing zero |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3985 | for (i = 0; i < Screen_mco; ++i) |
| 3986 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3987 | ScreenLinesC[i][wlv.off] = u8cc[i]; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3988 | if (u8cc[i] == 0) |
| 3989 | break; |
| 3990 | } |
| 3991 | } |
| 3992 | else |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3993 | ScreenLinesUC[wlv.off] = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3994 | } |
| 3995 | if (multi_attr) |
| 3996 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3997 | ScreenAttrs[wlv.off] = multi_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3998 | multi_attr = 0; |
| 3999 | } |
| 4000 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4001 | ScreenAttrs[wlv.off] = wlv.char_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4002 | |
zeertzjq | db54e98 | 2023-09-21 16:33:09 +0200 | [diff] [blame] | 4003 | if (wlv.draw_state > WL_NR |
| 4004 | #ifdef FEAT_DIFF |
| 4005 | && wlv.filler_todo <= 0 |
| 4006 | #endif |
| 4007 | ) |
| 4008 | ScreenCols[wlv.off] = wlv.vcol; |
| 4009 | else |
| 4010 | ScreenCols[wlv.off] = -1; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 4011 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4012 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 4013 | { |
| 4014 | // Need to fill two screen columns. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4015 | ++wlv.off; |
| 4016 | ++wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4017 | if (enc_utf8) |
| 4018 | // UTF-8: Put a 0 in the second screen char. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4019 | ScreenLines[wlv.off] = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4020 | else |
| 4021 | // DBCS: Put second byte in the second screen char. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4022 | ScreenLines[wlv.off] = mb_c & 0xff; |
zeertzjq | db54e98 | 2023-09-21 16:33:09 +0200 | [diff] [blame] | 4023 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4024 | if (wlv.draw_state > WL_NR |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4025 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4026 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4027 | #endif |
| 4028 | ) |
zeertzjq | db54e98 | 2023-09-21 16:33:09 +0200 | [diff] [blame] | 4029 | ScreenCols[wlv.off] = ++wlv.vcol; |
| 4030 | else |
| 4031 | ScreenCols[wlv.off] = -1; |
| 4032 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 4033 | // When "wlv.tocol" is halfway a character, set it to the end |
| 4034 | // of the character, otherwise highlighting won't stop. |
| 4035 | if (wlv.tocol == wlv.vcol) |
| 4036 | ++wlv.tocol; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 4037 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4038 | #ifdef FEAT_RIGHTLEFT |
| 4039 | if (wp->w_p_rl) |
| 4040 | { |
| 4041 | // now it's time to backup one cell |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4042 | --wlv.off; |
| 4043 | --wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4044 | } |
| 4045 | #endif |
| 4046 | } |
| 4047 | #ifdef FEAT_RIGHTLEFT |
| 4048 | if (wp->w_p_rl) |
| 4049 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4050 | --wlv.off; |
| 4051 | --wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4052 | } |
| 4053 | else |
| 4054 | #endif |
| 4055 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4056 | ++wlv.off; |
| 4057 | ++wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4058 | } |
| 4059 | } |
| 4060 | #ifdef FEAT_CONCEAL |
| 4061 | else if (wp->w_p_cole > 0 && is_concealing) |
| 4062 | { |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 4063 | int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1; |
| 4064 | |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 4065 | --skip_cells; |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 4066 | ++wlv.vcol_off_co; |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 4067 | if (concealed_wide) |
| 4068 | { |
| 4069 | // When a double-width char is concealed, |
| 4070 | // need to advance one more virtual column. |
| 4071 | ++wlv.vcol; |
| 4072 | ++wlv.vcol_off_co; |
| 4073 | } |
| 4074 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4075 | if (wlv.n_extra > 0) |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 4076 | wlv.vcol_off_co += wlv.n_extra; |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 4077 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4078 | if (wp->w_p_wrap) |
| 4079 | { |
| 4080 | // Special voodoo required if 'wrap' is on. |
| 4081 | // |
| 4082 | // Advance the column indicator to force the line |
| 4083 | // drawing to wrap early. This will make the line |
| 4084 | // take up the same screen space when parts are concealed, |
| 4085 | // so that cursor line computations aren't messed up. |
| 4086 | // |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4087 | // To avoid the fictitious advance of 'wlv.col' causing |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4088 | // trailing junk to be written out of the screen line |
| 4089 | // we are building, 'boguscols' keeps track of the number |
| 4090 | // of bad columns we have advanced. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4091 | if (wlv.n_extra > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4092 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4093 | wlv.vcol += wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4094 | # ifdef FEAT_RIGHTLEFT |
| 4095 | if (wp->w_p_rl) |
| 4096 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4097 | wlv.col -= wlv.n_extra; |
| 4098 | wlv.boguscols -= wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4099 | } |
| 4100 | else |
| 4101 | # endif |
| 4102 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4103 | wlv.col += wlv.n_extra; |
| 4104 | wlv.boguscols += wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4105 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4106 | wlv.n_extra = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4107 | n_attr = 0; |
| 4108 | } |
| 4109 | |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 4110 | if (concealed_wide) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4111 | { |
| 4112 | // Need to fill two screen columns. |
| 4113 | # ifdef FEAT_RIGHTLEFT |
| 4114 | if (wp->w_p_rl) |
| 4115 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4116 | --wlv.boguscols; |
| 4117 | --wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4118 | } |
| 4119 | else |
| 4120 | # endif |
| 4121 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4122 | ++wlv.boguscols; |
| 4123 | ++wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | # ifdef FEAT_RIGHTLEFT |
| 4128 | if (wp->w_p_rl) |
| 4129 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4130 | --wlv.boguscols; |
| 4131 | --wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4132 | } |
| 4133 | else |
| 4134 | # endif |
| 4135 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4136 | ++wlv.boguscols; |
| 4137 | ++wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4138 | } |
| 4139 | } |
| 4140 | else |
| 4141 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4142 | if (wlv.n_extra > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4143 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4144 | wlv.vcol += wlv.n_extra; |
| 4145 | wlv.n_extra = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4146 | n_attr = 0; |
| 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | } |
| 4151 | #endif // FEAT_CONCEAL |
| 4152 | else |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 4153 | --skip_cells; |
| 4154 | |
| 4155 | if (wlv.draw_state > WL_NR && skipped_cells > 0) |
| 4156 | { |
| 4157 | wlv.vcol += skipped_cells; |
| 4158 | skipped_cells = 0; |
| 4159 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4160 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4161 | // Only advance the "wlv.vcol" when after the 'number' or |
| 4162 | // 'relativenumber' column. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4163 | if (wlv.draw_state > WL_NR |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4164 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4165 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4166 | #endif |
| 4167 | ) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4168 | ++wlv.vcol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4169 | |
| 4170 | #ifdef FEAT_SYN_HL |
| 4171 | if (vcol_save_attr >= 0) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4172 | wlv.char_attr = vcol_save_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4173 | #endif |
| 4174 | |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 4175 | // restore attributes after "precedes" in 'listchars' |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4176 | if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 4177 | wlv.char_attr = saved_attr3; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4178 | |
| 4179 | // restore attributes after last 'listchars' or 'number' char |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4180 | if (n_attr > 0 && wlv.draw_state == WL_LINE |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 4181 | && wlv.n_attr_skip == 0 && --n_attr == 0) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4182 | wlv.char_attr = saved_attr2; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 4183 | if (wlv.n_attr_skip > 0) |
| 4184 | --wlv.n_attr_skip; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4185 | |
| 4186 | // At end of screen line and there is more to come: Display the line |
| 4187 | // so far. If there is no more to display it is caught above. |
| 4188 | if (( |
| 4189 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4190 | wp->w_p_rl ? (wlv.col < 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4191 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4192 | (wlv.col >= wp->w_width)) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4193 | && (wlv.draw_state != WL_LINE |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 4194 | || *ptr != NUL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4195 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4196 | || wlv.filler_todo > 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4197 | #endif |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 4198 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 4199 | || text_prop_above || text_prop_follows |
zeertzjq | 4e26a9a | 2023-12-03 17:50:47 +0100 | [diff] [blame] | 4200 | || text_prop_next <= last_textprop_text_idx |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 4201 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 4202 | || (wp->w_p_list && wp->w_lcs_chars.eol != NUL |
Dylan Thacker-Smith | f548ae7 | 2024-02-24 10:17:11 +0100 | [diff] [blame] | 4203 | && lcs_eol_one != -1) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4204 | || (wlv.n_extra != 0 && (wlv.c_extra != NUL |
| 4205 | || *wlv.p_extra != NUL))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4206 | ) |
| 4207 | { |
| 4208 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 4209 | wlv.col -= wlv.boguscols; |
zeertzjq | 21b0a3d | 2024-03-13 20:06:34 +0100 | [diff] [blame] | 4210 | // Apply 'cursorline' and 'wincolor' highlight. |
| 4211 | if (wlv.boguscols != 0 && ( |
| 4212 | # ifdef LINE_ATTR |
| 4213 | wlv.line_attr != 0 || |
| 4214 | # endif |
| 4215 | wlv.win_attr != 0 |
| 4216 | ) |
| 4217 | ) |
| 4218 | { |
| 4219 | int attr = wlv.win_attr; |
| 4220 | # ifdef LINE_ATTR |
| 4221 | if (wlv.line_attr != 0) |
| 4222 | attr = hl_combine_attr(attr, wlv.line_attr); |
| 4223 | # endif |
| 4224 | while (( |
| 4225 | # ifdef FEAT_RIGHTLEFT |
| 4226 | wp->w_p_rl ? wlv.col >= 0 : |
| 4227 | # endif |
| 4228 | wlv.col < wp->w_width)) |
| 4229 | { |
| 4230 | ScreenLines[wlv.off] = ' '; |
| 4231 | if (enc_utf8) |
| 4232 | ScreenLinesUC[wlv.off] = 0; |
| 4233 | ScreenAttrs[wlv.off] = attr; |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 4234 | ScreenCols[wlv.off] = wlv.vcol - 1; |
zeertzjq | 21b0a3d | 2024-03-13 20:06:34 +0100 | [diff] [blame] | 4235 | # ifdef FEAT_RIGHTLEFT |
| 4236 | if (wp->w_p_rl) |
| 4237 | { |
| 4238 | wlv.off--; |
| 4239 | wlv.col--; |
| 4240 | wlv.boguscols++; |
| 4241 | } |
| 4242 | else |
| 4243 | # endif |
| 4244 | { |
| 4245 | wlv.off++; |
| 4246 | wlv.col++; |
| 4247 | wlv.boguscols--; |
| 4248 | } |
| 4249 | } |
| 4250 | } |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 4251 | wlv_screen_line(wp, &wlv, TRUE); |
Bram Moolenaar | 7500866 | 2022-10-04 22:40:56 +0100 | [diff] [blame] | 4252 | wlv.col += wlv.boguscols; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4253 | wlv.boguscols = 0; |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 4254 | wlv.vcol_off_co = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4255 | #else |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 4256 | wlv_screen_line(wp, &wlv, TRUE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4257 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4258 | ++wlv.row; |
| 4259 | ++wlv.screen_row; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4260 | |
Dylan Thacker-Smith | f548ae7 | 2024-02-24 10:17:11 +0100 | [diff] [blame] | 4261 | // When not wrapping and finished diff lines, break here. |
| 4262 | if (!wp->w_p_wrap |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4263 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4264 | && wlv.filler_todo <= 0 |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 4265 | #endif |
| 4266 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 877151b | 2022-10-11 15:29:50 +0100 | [diff] [blame] | 4267 | && !text_prop_above |
Dylan Thacker-Smith | f548ae7 | 2024-02-24 10:17:11 +0100 | [diff] [blame] | 4268 | && !text_prop_follows |
Bram Moolenaar | 877151b | 2022-10-11 15:29:50 +0100 | [diff] [blame] | 4269 | #endif |
| 4270 | ) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4271 | break; |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 4272 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 4273 | if (!wp->w_p_wrap && text_prop_follows && !text_prop_above) |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 4274 | { |
| 4275 | // do not output more of the line, only the "below" prop |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 4276 | ptr = line + (size_t)ml_get_buf_len(wp->w_buffer, lnum); |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 4277 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 4278 | wlv.dont_use_showbreak = TRUE; |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 4279 | # endif |
| 4280 | } |
| 4281 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4282 | |
| 4283 | // When the window is too narrow draw all "@" lines. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4284 | if (wlv.draw_state != WL_LINE |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4285 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4286 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4287 | #endif |
| 4288 | ) |
| 4289 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4290 | win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT); |
| 4291 | draw_vsep_win(wp, wlv.row); |
| 4292 | wlv.row = endrow; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4293 | } |
| 4294 | |
| 4295 | // When line got too long for screen break here. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4296 | if (wlv.row == endrow) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4297 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4298 | ++wlv.row; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4299 | break; |
| 4300 | } |
| 4301 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4302 | if (screen_cur_row == wlv.screen_row - 1 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4303 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4304 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4305 | #endif |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 4306 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 4307 | && !text_prop_above && !text_prop_follows |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 4308 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4309 | && wp->w_width == Columns) |
| 4310 | { |
| 4311 | // Remember that the line wraps, used for modeless copy. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4312 | LineWraps[wlv.screen_row - 1] = TRUE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4313 | |
| 4314 | // Special trick to make copy/paste of wrapped lines work with |
| 4315 | // xterm/screen: write an extra character beyond the end of |
| 4316 | // the line. This will work with all terminal types |
| 4317 | // (regardless of the xn,am settings). |
| 4318 | // Only do this on a fast tty. |
| 4319 | // Only do this if the cursor is on the current line |
| 4320 | // (something has been written in it). |
| 4321 | // Don't do this for the GUI. |
| 4322 | // Don't do this for double-width characters. |
| 4323 | // Don't do this for a window not at the right screen border. |
| 4324 | if (p_tf |
| 4325 | #ifdef FEAT_GUI |
| 4326 | && !gui.in_use |
| 4327 | #endif |
| 4328 | && !(has_mbyte |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4329 | && ((*mb_off2cells)(LineOffset[wlv.screen_row], |
| 4330 | LineOffset[wlv.screen_row] + screen_Columns) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4331 | == 2 |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4332 | || (*mb_off2cells)( |
| 4333 | LineOffset[wlv.screen_row - 1] |
| 4334 | + (int)Columns - 2, |
| 4335 | LineOffset[wlv.screen_row] |
| 4336 | + screen_Columns) == 2))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4337 | { |
| 4338 | // First make sure we are at the end of the screen line, |
| 4339 | // then output the same character again to let the |
| 4340 | // terminal know about the wrap. If the terminal doesn't |
| 4341 | // auto-wrap, we overwrite the character. |
| 4342 | if (screen_cur_col != wp->w_width) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4343 | screen_char(LineOffset[wlv.screen_row - 1] |
| 4344 | + (unsigned)Columns - 1, |
| 4345 | wlv.screen_row - 1, (int)(Columns - 1)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4346 | |
| 4347 | // When there is a multi-byte character, just output a |
| 4348 | // space to keep it simple. |
| 4349 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4350 | wlv.screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4351 | out_char(' '); |
| 4352 | else |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4353 | out_char(ScreenLines[LineOffset[wlv.screen_row - 1] |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4354 | + (Columns - 1)]); |
| 4355 | // force a redraw of the first char on the next line |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4356 | ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4357 | screen_start(); // don't know where cursor is now |
| 4358 | } |
| 4359 | } |
| 4360 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4361 | win_line_start(wp, &wlv, TRUE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4362 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 4363 | lcs_prec_todo = wp->w_lcs_chars.prec; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4364 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 4365 | if (!wlv.dont_use_showbreak |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4366 | # ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4367 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4368 | # endif |
Bram Moolenaar | 3ec3b8e | 2022-08-05 21:39:30 +0100 | [diff] [blame] | 4369 | ) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 4370 | wlv.need_showbreak = TRUE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4371 | #endif |
| 4372 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4373 | --wlv.filler_todo; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4374 | // When the filler lines are actually below the last line of the |
| 4375 | // file, don't draw the line itself, break here. |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4376 | if (wlv.filler_todo == 0 && wp->w_botfill) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4377 | break; |
| 4378 | #endif |
| 4379 | } |
| 4380 | |
| 4381 | } // for every character in the line |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 4382 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4383 | vim_free(text_props); |
| 4384 | vim_free(text_prop_idxs); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4385 | vim_free(p_extra_free2); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4386 | #endif |
| 4387 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 4388 | vim_free(wlv.p_extra_free); |
zeertzjq | 58e1e01 | 2023-06-04 18:46:28 +0100 | [diff] [blame] | 4389 | vim_free(wlv.saved_p_extra_free); |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4390 | return wlv.row; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4391 | } |