mirror of
https://github.com/neovim/neovim.git
synced 2025-01-01 17:23:36 -07:00
vim-patch:9.0.0858: "!!sort" in a closed fold sorts too many lines (#21022)
Problem: "!!sort" in a closed fold sorts too many lines. Solution: Round to end of fold after adding the line count. (closes vim/vim#11487)f00112d558
N/A patches for version.c: vim-patch:9.0.0855: comment not located above the code it refers to Problem: Comment not located above the code it refers to. Solution: Move the comment. (closes vim/vim#11527)09a93e3e66
vim-patch:9.0.0859: compiler warning for unused variable Problem: Compiler warning for unused variable. Solution: Add #ifdef.fd3084b6e2
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
69507c0204
commit
ae67706535
@ -3224,6 +3224,8 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
|
|||||||
char *cmd = skipwhite(*ptr);
|
char *cmd = skipwhite(*ptr);
|
||||||
linenr_T lnum = MAXLNUM;
|
linenr_T lnum = MAXLNUM;
|
||||||
do {
|
do {
|
||||||
|
const int base_char = (uint8_t)(*cmd);
|
||||||
|
|
||||||
switch (*cmd) {
|
switch (*cmd) {
|
||||||
case '.': // '.' - Cursor position
|
case '.': // '.' - Cursor position
|
||||||
cmd++;
|
cmd++;
|
||||||
@ -3482,9 +3484,10 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
|
|||||||
} else {
|
} else {
|
||||||
i = (char_u)(*cmd++);
|
i = (char_u)(*cmd++);
|
||||||
}
|
}
|
||||||
if (!ascii_isdigit(*cmd)) { // '+' is '+1', but '+0' is not '+1'
|
if (!ascii_isdigit(*cmd)) { // '+' is '+1'
|
||||||
n = 1;
|
n = 1;
|
||||||
} else {
|
} else {
|
||||||
|
// "number", "+number" or "-number"
|
||||||
n = getdigits_int32(&cmd, false, MAXLNUM);
|
n = getdigits_int32(&cmd, false, MAXLNUM);
|
||||||
if (n == MAXLNUM) {
|
if (n == MAXLNUM) {
|
||||||
emsg(_(e_line_number_out_of_range));
|
emsg(_(e_line_number_out_of_range));
|
||||||
@ -3499,10 +3502,16 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
|
|||||||
} else if (addr_type == ADDR_LOADED_BUFFERS || addr_type == ADDR_BUFFERS) {
|
} else if (addr_type == ADDR_LOADED_BUFFERS || addr_type == ADDR_BUFFERS) {
|
||||||
lnum = compute_buffer_local_count(addr_type, lnum, (i == '-') ? -1 * n : n);
|
lnum = compute_buffer_local_count(addr_type, lnum, (i == '-') ? -1 * n : n);
|
||||||
} else {
|
} else {
|
||||||
// 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.
|
||||||
|
bool 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);
|
||||||
}
|
}
|
||||||
if (i == '-') {
|
if (i == '-') {
|
||||||
@ -3513,6 +3522,11 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
lnum += n;
|
lnum += n;
|
||||||
|
// ".+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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -986,4 +986,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
|
||||||
|
Loading…
Reference in New Issue
Block a user