mirror of
https://github.com/vim/vim.git
synced 2025-10-02 05:04:20 -04:00
patch 9.0.0858: "!!sort" in a closed fold sorts too many lines
Problem: "!!sort" in a closed fold sorts too many lines. Solution: Round to end of fold after adding the line count. (closes #11487)
This commit is contained in:
@@ -4308,6 +4308,8 @@ get_address(
|
|||||||
lnum = MAXLNUM;
|
lnum = MAXLNUM;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
int base_char = *cmd;
|
||||||
|
|
||||||
switch (*cmd)
|
switch (*cmd)
|
||||||
{
|
{
|
||||||
case '.': // '.' - Cursor position
|
case '.': // '.' - Cursor position
|
||||||
@@ -4602,10 +4604,11 @@ get_address(
|
|||||||
i = '+'; // "number" is same as "+number"
|
i = '+'; // "number" is same as "+number"
|
||||||
else
|
else
|
||||||
i = *cmd++;
|
i = *cmd++;
|
||||||
if (!VIM_ISDIGIT(*cmd)) // '+' is '+1', but '+0' is not '+1'
|
if (!VIM_ISDIGIT(*cmd)) // '+' is '+1'
|
||||||
n = 1;
|
n = 1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// "number", "+number" or "-number"
|
||||||
n = getdigits(&cmd);
|
n = getdigits(&cmd);
|
||||||
if (n == MAXLNUM)
|
if (n == MAXLNUM)
|
||||||
{
|
{
|
||||||
@@ -4627,10 +4630,16 @@ get_address(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef FEAT_FOLDING
|
#ifdef FEAT_FOLDING
|
||||||
// Relative line addressing, need to adjust for folded lines
|
// Relative line addressing: need to adjust for closed folds
|
||||||
// now, but only do it after the first address.
|
// after the first address.
|
||||||
if (addr_type == ADDR_LINES && (i == '-' || i == '+')
|
// Subtle difference: "number,+number" and "number,-number"
|
||||||
&& address_count >= 2)
|
// adjusts to end of closed fold before adding/subtracting,
|
||||||
|
// while "number,.+number" adjusts to end of closed fold after
|
||||||
|
// adding to make "!!" expanded into ".,.+N" work correctly.
|
||||||
|
int adjust_for_folding = addr_type == ADDR_LINES
|
||||||
|
&& (i == '-' || i == '+')
|
||||||
|
&& address_count >= 2;
|
||||||
|
if (adjust_for_folding && (i == '-' || base_char != '.'))
|
||||||
(void)hasFolding(lnum, NULL, &lnum);
|
(void)hasFolding(lnum, NULL, &lnum);
|
||||||
#endif
|
#endif
|
||||||
if (i == '-')
|
if (i == '-')
|
||||||
@@ -4643,6 +4652,12 @@ get_address(
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
lnum += n;
|
lnum += n;
|
||||||
|
#ifdef FEAT_FOLDING
|
||||||
|
// ".+number" rounds up to the end of a closed fold after
|
||||||
|
// adding, so that ":!!sort" sorts one closed fold.
|
||||||
|
if (adjust_for_folding && base_char == '.')
|
||||||
|
(void)hasFolding(lnum, NULL, &lnum);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1570,4 +1570,40 @@ func Test_indent_append_blank_small_fold_close()
|
|||||||
bw!
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_sort_closed_fold()
|
||||||
|
CheckExecutable sort
|
||||||
|
|
||||||
|
call setline(1, [
|
||||||
|
\ 'Section 1',
|
||||||
|
\ ' how',
|
||||||
|
\ ' now',
|
||||||
|
\ ' brown',
|
||||||
|
\ ' cow',
|
||||||
|
\ 'Section 2',
|
||||||
|
\ ' how',
|
||||||
|
\ ' now',
|
||||||
|
\ ' brown',
|
||||||
|
\ ' cow',
|
||||||
|
\])
|
||||||
|
setlocal foldmethod=indent sw=3
|
||||||
|
normal 2G
|
||||||
|
|
||||||
|
" The "!!" expands to ".,.+3" and must only sort four lines
|
||||||
|
call feedkeys("!!sort\<CR>", 'xt')
|
||||||
|
call assert_equal([
|
||||||
|
\ 'Section 1',
|
||||||
|
\ ' brown',
|
||||||
|
\ ' cow',
|
||||||
|
\ ' how',
|
||||||
|
\ ' now',
|
||||||
|
\ 'Section 2',
|
||||||
|
\ ' how',
|
||||||
|
\ ' now',
|
||||||
|
\ ' brown',
|
||||||
|
\ ' cow',
|
||||||
|
\ ], getline(1, 10))
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -695,6 +695,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
858,
|
||||||
/**/
|
/**/
|
||||||
857,
|
857,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user