@@ -109,6 +109,7 @@ static match_T search_hl; /* used for 'hlsearch' highlight matching */
109109
110110#ifdef FEAT_FOLDING
111111static foldinfo_T win_foldinfo ; /* info for 'foldcolumn' */
112+ static int compute_foldcolumn __ARGS ((win_T * wp , int col ));
112113#endif
113114
114115/*
@@ -1202,7 +1203,7 @@ win_update(wp)
12021203 lnumb = wp -> w_lines [i ].wl_lnum ;
12031204 /* When there is a fold column it might need updating
12041205 * in the next line ("J" just above an open fold). */
1205- if (wp -> w_p_fdc > 0 )
1206+ if (compute_foldcolumn ( wp , 0 ) > 0 )
12061207 ++ lnumb ;
12071208 }
12081209 }
@@ -2238,13 +2239,16 @@ win_draw_end(wp, c1, c2, row, endrow, hl)
22382239#else
22392240# define FDC_OFF 0
22402241#endif
2242+ #ifdef FEAT_FOLDING
2243+ int fdc = compute_foldcolumn (wp , 0 );
2244+ #endif
22412245
22422246#ifdef FEAT_RIGHTLEFT
22432247 if (wp -> w_p_rl )
22442248 {
22452249 /* No check for cmdline window: should never be right-left. */
22462250# ifdef FEAT_FOLDING
2247- n = wp -> w_p_fdc ;
2251+ n = fdc ;
22482252
22492253 if (n > 0 )
22502254 {
@@ -2293,9 +2297,9 @@ win_draw_end(wp, c1, c2, row, endrow, hl)
22932297 }
22942298#endif
22952299#ifdef FEAT_FOLDING
2296- if (wp -> w_p_fdc > 0 )
2300+ if (fdc > 0 )
22972301 {
2298- int nn = n + wp -> w_p_fdc ;
2302+ int nn = n + fdc ;
22992303
23002304 /* draw the fold column at the left */
23012305 if (nn > W_WIDTH (wp ))
@@ -2345,6 +2349,24 @@ advance_color_col(vcol, color_cols)
23452349#endif
23462350
23472351#ifdef FEAT_FOLDING
2352+ /*
2353+ * Compute the width of the foldcolumn. Based on 'foldcolumn' and how much
2354+ * space is available for window "wp", minus "col".
2355+ */
2356+ static int
2357+ compute_foldcolumn (wp , col )
2358+ win_T * wp ;
2359+ int col ;
2360+ {
2361+ int fdc = wp -> w_p_fdc ;
2362+ int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw ;
2363+ int wwidth = W_WIDTH (wp );
2364+
2365+ if (fdc > wwidth - (col + wmw ))
2366+ fdc = wwidth - (col + wmw );
2367+ return fdc ;
2368+ }
2369+
23482370/*
23492371 * Display one folded line.
23502372 */
@@ -2396,10 +2418,9 @@ fold_line(wp, fold_count, foldinfo, lnum, row)
23962418
23972419 /*
23982420 * 2. Add the 'foldcolumn'
2421+ * Reduce the width when there is not enough space.
23992422 */
2400- fdc = wp -> w_p_fdc ;
2401- if (fdc > W_WIDTH (wp ) - col )
2402- fdc = W_WIDTH (wp ) - col ;
2423+ fdc = compute_foldcolumn (wp , col );
24032424 if (fdc > 0 )
24042425 {
24052426 fill_foldcolumn (buf , wp , TRUE, lnum );
@@ -2787,23 +2808,24 @@ fill_foldcolumn(p, wp, closed, lnum)
27872808 int level ;
27882809 int first_level ;
27892810 int empty ;
2811+ int fdc = compute_foldcolumn (wp , 0 );
27902812
27912813 /* Init to all spaces. */
2792- copy_spaces (p , (size_t )wp -> w_p_fdc );
2814+ copy_spaces (p , (size_t )fdc );
27932815
27942816 level = win_foldinfo .fi_level ;
27952817 if (level > 0 )
27962818 {
27972819 /* If there is only one column put more info in it. */
2798- empty = (wp -> w_p_fdc == 1 ) ? 0 : 1 ;
2820+ empty = (fdc == 1 ) ? 0 : 1 ;
27992821
28002822 /* If the column is too narrow, we start at the lowest level that
28012823 * fits and use numbers to indicated the depth. */
2802- first_level = level - wp -> w_p_fdc - closed + 1 + empty ;
2824+ first_level = level - fdc - closed + 1 + empty ;
28032825 if (first_level < 1 )
28042826 first_level = 1 ;
28052827
2806- for (i = 0 ; i + empty < wp -> w_p_fdc ; ++ i )
2828+ for (i = 0 ; i + empty < fdc ; ++ i )
28072829 {
28082830 if (win_foldinfo .fi_lnum == lnum
28092831 && first_level + i >= win_foldinfo .fi_low_level )
@@ -2819,7 +2841,7 @@ fill_foldcolumn(p, wp, closed, lnum)
28192841 }
28202842 }
28212843 if (closed )
2822- p [i >= wp -> w_p_fdc ? i - 1 : i ] = '+' ;
2844+ p [i >= fdc ? i - 1 : i ] = '+' ;
28232845}
28242846#endif /* FEAT_FOLDING */
28252847
@@ -3556,12 +3578,14 @@ win_line(wp, lnum, startrow, endrow, nochange)
35563578#ifdef FEAT_FOLDING
35573579 if (draw_state == WL_FOLD - 1 && n_extra == 0 )
35583580 {
3581+ int fdc = compute_foldcolumn (wp , 0 );
3582+
35593583 draw_state = WL_FOLD ;
3560- if (wp -> w_p_fdc > 0 )
3584+ if (fdc > 0 )
35613585 {
35623586 /* Draw the 'foldcolumn'. */
35633587 fill_foldcolumn (extra , wp , FALSE, lnum );
3564- n_extra = wp -> w_p_fdc ;
3588+ n_extra = fdc ;
35653589 p_extra = extra ;
35663590 p_extra [n_extra ] = NUL ;
35673591 c_extra = NUL ;
0 commit comments