mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 08:56:29 +00:00
Merge pull request #13807 from spywhere/min-size-auto-sign
Auto sign column with minimum size support
This commit is contained in:
@@ -5536,6 +5536,12 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
"auto" only when there is a sign to display
|
"auto" only when there is a sign to display
|
||||||
"auto:[1-9]" resize to accommodate multiple signs up to the
|
"auto:[1-9]" resize to accommodate multiple signs up to the
|
||||||
given number (maximum 9), e.g. "auto:4"
|
given number (maximum 9), e.g. "auto:4"
|
||||||
|
"auto:[1-8]-[2-9]"
|
||||||
|
resize to accommodate multiple signs up to the
|
||||||
|
given maximum number (maximum 9) while keeping
|
||||||
|
at least the given minimum (maximum 8) fixed
|
||||||
|
space. The minimum number should always be less
|
||||||
|
than the maximum number, e.g. "auto:2-5"
|
||||||
"no" never
|
"no" never
|
||||||
"yes" always
|
"yes" always
|
||||||
"yes:[1-9]" always, with fixed space for signs up to the given
|
"yes:[1-9]" always, with fixed space for signs up to the given
|
||||||
|
@@ -2913,7 +2913,7 @@ ambw_end:
|
|||||||
#endif
|
#endif
|
||||||
} else if (varp == &curwin->w_p_scl) {
|
} else if (varp == &curwin->w_p_scl) {
|
||||||
// 'signcolumn'
|
// 'signcolumn'
|
||||||
if (check_opt_strings(*varp, p_scl_values, false) != OK) {
|
if (check_signcolumn(*varp) != OK) {
|
||||||
errmsg = e_invarg;
|
errmsg = e_invarg;
|
||||||
}
|
}
|
||||||
// When changing the 'signcolumn' to or from 'number', recompute the
|
// When changing the 'signcolumn' to or from 'number', recompute the
|
||||||
@@ -3232,6 +3232,34 @@ static int int_cmp(const void *a, const void *b)
|
|||||||
return *(const int *)a - *(const int *)b;
|
return *(const int *)a - *(const int *)b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handle setting 'signcolumn' for value 'val'
|
||||||
|
///
|
||||||
|
/// @return OK when the value is valid, FAIL otherwise
|
||||||
|
int check_signcolumn(char_u *val)
|
||||||
|
{
|
||||||
|
// check for basic match
|
||||||
|
if (check_opt_strings(val, p_scl_values, false) == OK) {
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for 'auto:<NUMBER>-<NUMBER>'
|
||||||
|
if (STRLEN(val) == 8
|
||||||
|
&& !STRNCMP(val, "auto:", 5)
|
||||||
|
&& ascii_isdigit(val[5])
|
||||||
|
&& val[6] == '-'
|
||||||
|
&& ascii_isdigit(val[7])
|
||||||
|
) {
|
||||||
|
int min = val[5] - '0';
|
||||||
|
int max = val[7] - '0';
|
||||||
|
if (min < 1 || max < 2 || min > 8 || max > 9 || min >= max) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle setting 'colorcolumn' or 'textwidth' in window "wp".
|
/// Handle setting 'colorcolumn' or 'textwidth' in window "wp".
|
||||||
///
|
///
|
||||||
/// @return error message, NULL if it's OK.
|
/// @return error message, NULL if it's OK.
|
||||||
@@ -7095,7 +7123,7 @@ int csh_like_shell(void)
|
|||||||
/// buffer signs and on user configuration.
|
/// buffer signs and on user configuration.
|
||||||
int win_signcol_count(win_T *wp)
|
int win_signcol_count(win_T *wp)
|
||||||
{
|
{
|
||||||
int maximum = 1, needed_signcols;
|
int minimum = 0, maximum = 1, needed_signcols;
|
||||||
const char *scl = (const char *)wp->w_p_scl;
|
const char *scl = (const char *)wp->w_p_scl;
|
||||||
|
|
||||||
// Note: It checks "no" or "number" in 'signcolumn' option
|
// Note: It checks "no" or "number" in 'signcolumn' option
|
||||||
@@ -7119,9 +7147,14 @@ int win_signcol_count(win_T *wp)
|
|||||||
if (!strncmp(scl, "auto:", 5)) {
|
if (!strncmp(scl, "auto:", 5)) {
|
||||||
// Variable depending on a configuration
|
// Variable depending on a configuration
|
||||||
maximum = scl[5] - '0';
|
maximum = scl[5] - '0';
|
||||||
|
// auto:<NUM>-<NUM>
|
||||||
|
if (strlen(scl) == 8 && *(scl + 6) == '-') {
|
||||||
|
minimum = maximum;
|
||||||
|
maximum = scl[7] - '0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MIN(maximum, needed_signcols);
|
return MAX(minimum, MIN(maximum, needed_signcols));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get window or buffer local options
|
/// Get window or buffer local options
|
||||||
|
@@ -266,6 +266,111 @@ describe('Signs', function()
|
|||||||
]]}
|
]]}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('auto-resize sign column with minimum size (#13783)', function()
|
||||||
|
feed('ia<cr>b<cr>c<cr><esc>')
|
||||||
|
command('set number')
|
||||||
|
-- sign column should always accommodate at the minimum size
|
||||||
|
command('set signcolumn=auto:1-3')
|
||||||
|
screen:expect([[
|
||||||
|
{2: }{6: 1 }a |
|
||||||
|
{2: }{6: 2 }b |
|
||||||
|
{2: }{6: 3 }c |
|
||||||
|
{2: }{6: 4 }^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
-- should support up to 8 signs at minimum
|
||||||
|
command('set signcolumn=auto:8-9')
|
||||||
|
screen:expect([[
|
||||||
|
{2: }{6: 1 }a |
|
||||||
|
{2: }{6: 2 }b |
|
||||||
|
{2: }{6: 3 }c |
|
||||||
|
{2: }{6: 4 }^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
-- should keep the same sign size when signs are not exceeding
|
||||||
|
-- the minimum
|
||||||
|
command('set signcolumn=auto:2-5')
|
||||||
|
command('sign define pietSearch text=>> texthl=Search')
|
||||||
|
command('sign place 1 line=1 name=pietSearch buffer=1')
|
||||||
|
screen:expect([[
|
||||||
|
{1:>>}{2: }{6: 1 }a |
|
||||||
|
{2: }{6: 2 }b |
|
||||||
|
{2: }{6: 3 }c |
|
||||||
|
{2: }{6: 4 }^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
-- should resize itself when signs are exceeding minimum but
|
||||||
|
-- not over the maximum
|
||||||
|
command('sign place 2 line=1 name=pietSearch buffer=1')
|
||||||
|
command('sign place 3 line=1 name=pietSearch buffer=1')
|
||||||
|
command('sign place 4 line=1 name=pietSearch buffer=1')
|
||||||
|
screen:expect([[
|
||||||
|
{1:>>>>>>>>}{6: 1 }a |
|
||||||
|
{2: }{6: 2 }b |
|
||||||
|
{2: }{6: 3 }c |
|
||||||
|
{2: }{6:^ 4 } |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
-- should keep the column at maximum size when signs are
|
||||||
|
-- exceeding the maximum
|
||||||
|
command('sign place 5 line=1 name=pietSearch buffer=1')
|
||||||
|
command('sign place 6 line=1 name=pietSearch buffer=1')
|
||||||
|
command('sign place 7 line=1 name=pietSearch buffer=1')
|
||||||
|
command('sign place 8 line=1 name=pietSearch buffer=1')
|
||||||
|
screen:expect([[
|
||||||
|
{1:>>>>>>>>>>}{6: 1 }a |
|
||||||
|
{2: }{6: 2 }b |
|
||||||
|
{2: }{6: 3 }c |
|
||||||
|
{2: ^ }{6: 4 } |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
it('ignores signs with no icon and text when calculting the signcolumn width', function()
|
it('ignores signs with no icon and text when calculting the signcolumn width', function()
|
||||||
feed('ia<cr>b<cr>c<cr><esc>')
|
feed('ia<cr>b<cr>c<cr><esc>')
|
||||||
command('set number')
|
command('set number')
|
||||||
|
Reference in New Issue
Block a user