Mercurial > vim
diff src/drawline.c @ 32527:2a672d04c547 v9.0.1595
patch 9.0.1595: line pointer becomes invalid when using spell checking
Commit: https://github.com/vim/vim/commit/e84c773d42e8b6ef0f8ae9b6c7312e0fd47909af
Author: Luuk van Baal <luukvbaal@gmail.com>
Date: Wed May 31 18:57:36 2023 +0100
patch 9.0.1595: line pointer becomes invalid when using spell checking
Problem: Line pointer becomes invalid when using spell checking.
Solution: Call ml_get() at the right places. (Luuk van Baal, closes https://github.com/vim/vim/issues/12456)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 31 May 2023 20:00:07 +0200 |
parents | 2614026cd259 |
children | 75e56c94316d |
line wrap: on
line diff
--- a/src/drawline.c +++ b/src/drawline.c @@ -1449,9 +1449,6 @@ win_line( area_highlighting = TRUE; #endif - line = ml_get_buf(wp->w_buffer, lnum, FALSE); - ptr = line; - #ifdef FEAT_SPELL if (spv->spv_has_spell && !number_only) { @@ -1462,28 +1459,36 @@ win_line( // current line is valid. if (lnum == spv->spv_checked_lnum) cur_checked_col = spv->spv_checked_col; - if (lnum != spv->spv_capcol_lnum) + // Previous line was not spell checked, check for capital. This happens + // for the first line in an updated region or after a closed fold. + if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0)) + spv->spv_cap_col = 0; + else if (lnum != spv->spv_capcol_lnum) spv->spv_cap_col = -1; spv->spv_checked_lnum = 0; - // For checking first word with a capital skip white space. - if (spv->spv_cap_col == 0) - spv->spv_cap_col = getwhitecols(line); - // If current line is empty, check first word in next line for capital. - else if (*skipwhite(line) == NUL) - { - spv->spv_cap_col = 0; - spv->spv_capcol_lnum = lnum + 1; - } - - // Get the start of the next line, so that words that wrap to the // next line are found too: "et<line-break>al.". // Trick: skip a few chars for C/shell/Vim comments nextline[SPWORDLEN] = NUL; if (lnum < wp->w_buffer->b_ml.ml_line_count) - spell_cat_line(nextline + SPWORDLEN, - ml_get_buf(wp->w_buffer, lnum + 1, FALSE), SPWORDLEN); + { + line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); + spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); + } + line = ml_get_buf(wp->w_buffer, lnum, FALSE); + + // If current line is empty, check first word in next line for capital. + ptr = skipwhite(line); + if (*ptr == NUL) + { + spv->spv_cap_col = 0; + spv->spv_capcol_lnum = lnum + 1; + } + // For checking first word with a capital skip white space. + else if (spv->spv_cap_col == 0) + spv->spv_cap_col = ptr - line; + // Copy the end of the current line into nextline[]. if (nextline[SPWORDLEN] == NUL) { @@ -1514,6 +1519,9 @@ win_line( } #endif + line = ml_get_buf(wp->w_buffer, lnum, FALSE); + ptr = line; + if (wp->w_p_list) { if (wp->w_lcs_chars.space