diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 6c42dd6739..e740a45bec 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -2438,7 +2438,7 @@ A jump table for the options with a short description can be found at |Q_op|. 'foldcolumn' 'fdc' string (default "0") local to window When and how to draw the foldcolumn. Valid values are: - "auto": resize to the maximum amount of folds to display. + "auto": resize to the minimum amount of folds to display. "auto:[1-9]": resize to accommodate multiple folds up to the selected level 0: to disable foldcolumn diff --git a/src/nvim/option.c b/src/nvim/option.c index 7cf8412269..bac289a959 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -320,7 +320,7 @@ static char *(p_scl_values[]) = { "yes", "no", "auto", "auto:1", "auto:2", "auto:3", "auto:4", "auto:5", "auto:6", "auto:7", "auto:8", "auto:9", "yes:1", "yes:2", "yes:3", "yes:4", "yes:5", "yes:6", "yes:7", "yes:8", "yes:9", "number", NULL }; -static char *(p_fdc_values[]) = { "auto:1", "auto:2", +static char *(p_fdc_values[]) = { "auto", "auto:1", "auto:2", "auto:3", "auto:4", "auto:5", "auto:6", "auto:7", "auto:8", "auto:9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; diff --git a/src/nvim/window.c b/src/nvim/window.c index 9eb16e67ec..0f17e2cb09 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -641,7 +641,7 @@ void win_set_minimal_style(win_T *wp) wp->w_p_scl = (char_u *)xstrdup("auto"); } - // foldcolumn: use 'auto' + // foldcolumn: use '0' if (wp->w_p_fdc[0] != '0') { xfree(wp->w_p_fdc); wp->w_p_fdc = (char_u *)xstrdup("0"); @@ -700,9 +700,10 @@ int win_fdccol_count(win_T *wp) const char *fdc = (const char *)wp->w_p_fdc; // auto: - if (strncmp(fdc, "auto:", 5) == 0) { + if (strncmp(fdc, "auto", 4) == 0) { + const int fdccol = fdc[4] == ':' ? fdc[5] - '0' : 1; int needed_fdccols = getDeepestNesting(wp); - return MIN(fdc[5] - '0', needed_fdccols); + return MIN(fdccol, needed_fdccols); } else { return fdc[0] - '0'; } diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua index 7b05e90459..6ce8b33a63 100644 --- a/test/functional/ui/fold_spec.lua +++ b/test/functional/ui/fold_spec.lua @@ -886,6 +886,41 @@ describe("folded lines", function() | ]]) end + command("set foldcolumn=auto") + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [3:---------------------------------------------]| + ## grid 2 + {7:+}{5:^+-- 2 lines: line 1························}| + {7: }line 3 | + {7: }line 4 | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + | + ]], unchanged=true} + else + screen:expect{grid=[[ + {7:+}{5:^+-- 2 lines: line 1························}| + {7: }line 3 | + {7: }line 4 | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]], unchanged=true} + end -- fdc should not change with a new fold as the maximum is 1 feed("zf3j") @@ -924,6 +959,41 @@ describe("folded lines", function() ]]) end + command("set foldcolumn=auto:1") + if multigrid then screen:expect{grid=[[ + ## grid 1 + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [3:---------------------------------------------]| + ## grid 2 + {7:+}{5:^+-- 4 lines: line 1························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + | + ]], unchanged=true} + else + screen:expect{grid=[[ + {7:+}{5:^+-- 4 lines: line 1························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]], unchanged=true} + end + -- relax the maximum fdc thus fdc should expand to -- accomodate the current number of folds command("set foldcolumn=auto:4")