From 30805a1aba0067cf0087f9a0e5c184562433e2e7 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sat, 27 May 2023 22:22:10 +0100 Subject: patch 9.0.1585: weird use of static variables for spell checking Problem: Weird use of static variables for spell checking. Solution: Move the variables to a structure and pass them from win_update() to win_line(). (Luuk van Baal, closes #12448) --- src/drawscreen.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/drawscreen.c') diff --git a/src/drawscreen.c b/src/drawscreen.c index 0912d7a156..9676f1b0f0 100644 --- a/src/drawscreen.c +++ b/src/drawscreen.c @@ -2191,11 +2191,25 @@ win_update(win_T *wp) redraw_win_toolbar(wp); #endif + lnum = wp->w_topline; // first line shown in window + + spellvars_T spv; +#ifdef FEAT_SPELL + // Initialize spell related variables for the first drawn line. + CLEAR_FIELD(spv); + spv.spv_has_spell = spell_check_window(wp); + if (spv.spv_has_spell) + { + spv.spv_unchanged = mod_top == 0; + spv.spv_capcol_lnum = mod_top ? mod_top : lnum; + spv.spv_cap_col = check_need_cap(wp, spv.spv_capcol_lnum, 0) ? 0 : - 1; + } +#endif + // Update all the window rows. idx = 0; // first entry in w_lines[].wl_size row = 0; srow = 0; - lnum = wp->w_topline; // first line shown in window for (;;) { // stop updating when reached the end of the window (check for _past_ @@ -2450,10 +2464,19 @@ win_update(win_T *wp) fold_line(wp, fold_count, &win_foldinfo, lnum, row); ++row; --fold_count; + linenr_T lnume = lnum + fold_count; wp->w_lines[idx].wl_folded = TRUE; - wp->w_lines[idx].wl_lastlnum = lnum + fold_count; + wp->w_lines[idx].wl_lastlnum = lnume; # ifdef FEAT_SYN_HL did_update = DID_FOLD; +# endif +# ifdef FEAT_SPELL + // Check if the line after this fold requires a capital. + if (spv.spv_has_spell && check_need_cap(wp, lnume + 1, 0)) + { + spv.spv_cap_col = 0; + spv.spv_capcol_lnum = lnume + 1; + } # endif } else @@ -2487,7 +2510,7 @@ win_update(win_T *wp) #endif // Display one line. - row = win_line(wp, lnum, srow, wp->w_height, mod_top, FALSE); + row = win_line(wp, lnum, srow, wp->w_height, FALSE, &spv); #ifdef FEAT_FOLDING wp->w_lines[idx].wl_folded = FALSE; @@ -2534,7 +2557,7 @@ win_update(win_T *wp) fold_line(wp, fold_count, &win_foldinfo, lnum, row); else #endif - (void)win_line(wp, lnum, srow, wp->w_height, mod_top, TRUE); + (void)win_line(wp, lnum, srow, wp->w_height, TRUE, &spv); } // This line does not need to be drawn, advance to the next one. -- cgit v1.2.3