diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-07-07 06:32:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-07 06:32:54 +0800 |
commit | 5da9b49b19240bb00f338249fef84a2bf1212b49 (patch) | |
tree | 07a864275674601b81c5f77927b7f2b8794d8186 /src/nvim/ops.c | |
parent | 7a54d707fa6f32822b241140b31a348ad5ad0e6b (diff) | |
download | rneovim-5da9b49b19240bb00f338249fef84a2bf1212b49.tar.gz rneovim-5da9b49b19240bb00f338249fef84a2bf1212b49.tar.bz2 rneovim-5da9b49b19240bb00f338249fef84a2bf1212b49.zip |
vim-patch:9.1.0537: signed number detection for CTRL-X/A can be improved (#29590)
Problem: signed number detection for CTRL-X/A can be improved
(Chris Patuzzo)
Solution: Add the new "blank" value for the 'nrformat' setting. This
will make Vim assume a signed number only if there is a blank
in front of the sign.
(distobs)
fixes: vim/vim#15033
closes: vim/vim#15110
https://github.com/vim/vim/commit/25ac6d67d92e0adda53b8d44b81c15031643ca1e
Co-authored-by: distobs <cuppotatocake@gmail.com>
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r-- | src/nvim/ops.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 7bffb12412..f2f8708235 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4420,6 +4420,7 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) int pre; // 'X' or 'x': hex; '0': octal; 'B' or 'b': bin static bool hexupper = false; // 0xABC uvarnumber_T n; + bool blank_unsigned = false; // blank: treat as unsigned? bool negative = false; bool was_positive = true; bool visual = VIsual_active; @@ -4430,12 +4431,12 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) pos_T endpos; colnr_T save_coladd = 0; - const bool do_hex = vim_strchr(curbuf->b_p_nf, 'x') != NULL; // "heX" - const bool do_oct = vim_strchr(curbuf->b_p_nf, 'o') != NULL; // "Octal" - const bool do_bin = vim_strchr(curbuf->b_p_nf, 'b') != NULL; // "Bin" - const bool do_alpha = vim_strchr(curbuf->b_p_nf, 'p') != NULL; // "alPha" - // "Unsigned" - const bool do_unsigned = vim_strchr(curbuf->b_p_nf, 'u') != NULL; + const bool do_hex = vim_strchr(curbuf->b_p_nf, 'x') != NULL; // "heX" + const bool do_oct = vim_strchr(curbuf->b_p_nf, 'o') != NULL; // "Octal" + const bool do_bin = vim_strchr(curbuf->b_p_nf, 'b') != NULL; // "Bin" + const bool do_alpha = vim_strchr(curbuf->b_p_nf, 'p') != NULL; // "alPha" + const bool do_unsigned = vim_strchr(curbuf->b_p_nf, 'u') != NULL; // "Unsigned" + const bool do_blank = vim_strchr(curbuf->b_p_nf, 'k') != NULL; // "blanK" if (virtual_active(curwin)) { save_coladd = pos->coladd; @@ -4532,8 +4533,12 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if (col > pos->col && ptr[col - 1] == '-' && !utf_head_off(ptr, ptr + col - 1) && !do_unsigned) { - negative = true; - was_positive = false; + if (do_blank && col >= 2 && !ascii_iswhite(ptr[col - 2])) { + blank_unsigned = true; + } else { + negative = true; + was_positive = false; + } } } @@ -4579,9 +4584,13 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) && !utf_head_off(ptr, ptr + col - 1) && !visual && !do_unsigned) { - // negative number - col--; - negative = true; + if (do_blank && col >= 2 && !ascii_iswhite(ptr[col - 2])) { + blank_unsigned = true; + } else { + // negative number + col--; + negative = true; + } } // get the number value (unsigned) @@ -4638,7 +4647,7 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } } - if (do_unsigned && negative) { + if ((do_unsigned || blank_unsigned) && negative) { if (subtract) { // sticking at zero. n = 0; |