comparison src/edit.c @ 34674:bfd2c0032686 v9.1.0218

patch 9.1.0218: Unnecessary multiplications in backspace code Commit: https://github.com/vim/vim/commit/8ede7a069419e0e01368c65a2d0c79d6332aa6cd Author: zeertzjq <zeertzjq@outlook.com> Date: Thu Mar 28 10:30:08 2024 +0100 patch 9.1.0218: Unnecessary multiplications in backspace code Problem: Unnecessary multiplications in backspace code, as "col / ts * ts" is the same as "col - col % ts". Solution: Change "col / ts * ts" to "col - col % ts". Adjust the loop and the comments ins_bs() to be easier to understand. Update tests to reset 'smarttab' properly. (zeertzjq) closes: #14308 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 28 Mar 2024 10:45:04 +0100
parents ca2da8e8fb53
children d432af20fe54
comparison
equal deleted inserted replaced
34673:62e99aaa4fcf 34674:bfd2c0032686
4208 && (*(ml_get_cursor() - 1) == TAB 4208 && (*(ml_get_cursor() - 1) == TAB
4209 || (*(ml_get_cursor() - 1) == ' ' 4209 || (*(ml_get_cursor() - 1) == ' '
4210 && (!*inserted_space_p 4210 && (!*inserted_space_p
4211 || arrow_used)))))) 4211 || arrow_used))))))
4212 { 4212 {
4213 int ts;
4214 colnr_T vcol = 0; 4213 colnr_T vcol = 0;
4215 colnr_T want_vcol; 4214 colnr_T want_vcol;
4216 char_u *line; 4215 char_u *line;
4217 char_u *ptr; 4216 char_u *ptr;
4218 char_u *end_ptr; 4217 char_u *cursor_ptr;
4219 char_u *space_ptr; 4218 char_u *space_ptr;
4220 colnr_T space_vcol = 0; 4219 colnr_T space_vcol = 0;
4221 int prev_space = FALSE; 4220 int prev_space = FALSE;
4222 colnr_T want_col; 4221 colnr_T want_col;
4223 4222
4224 *inserted_space_p = FALSE; 4223 *inserted_space_p = FALSE;
4225 4224
4226 space_ptr = ptr = line = ml_get_curline(); 4225 space_ptr = ptr = line = ml_get_curline();
4227 end_ptr = line + curwin->w_cursor.col; 4226 cursor_ptr = line + curwin->w_cursor.col;
4228 4227
4229 // Find the last whitespace that is preceded by non-whitespace. 4228 // Compute virtual column of cursor position, and find the last
4229 // whitespace before cursor that is preceded by non-whitespace.
4230 // Use chartabsize() so that virtual text and wrapping are ignored. 4230 // Use chartabsize() so that virtual text and wrapping are ignored.
4231 do { 4231 while (ptr < cursor_ptr)
4232 {
4232 int cur_space = VIM_ISWHITE(*ptr); 4233 int cur_space = VIM_ISWHITE(*ptr);
4233 4234
4234 if (!prev_space && cur_space) 4235 if (!prev_space && cur_space)
4235 { 4236 {
4236 space_ptr = ptr; 4237 space_ptr = ptr;
4237 space_vcol = vcol; 4238 space_vcol = vcol;
4238 } 4239 }
4239 vcol += chartabsize(ptr, vcol); 4240 vcol += chartabsize(ptr, vcol);
4240 MB_PTR_ADV(ptr); 4241 MB_PTR_ADV(ptr);
4241 prev_space = cur_space; 4242 prev_space = cur_space;
4242 } while (ptr < end_ptr); 4243 }
4243 4244
4244 // Compute the virtual column where we want to be. 4245 // Compute the virtual column where we want to be.
4245 want_vcol = vcol - 1; 4246 want_vcol = vcol > 0 ? vcol - 1 : 0;
4247 if (p_sta && in_indent)
4248 want_vcol -= want_vcol % (int)get_sw_value(curbuf);
4249 else
4246 #ifdef FEAT_VARTABS 4250 #ifdef FEAT_VARTABS
4247 if (p_sta && in_indent)
4248 {
4249 ts = (int)get_sw_value(curbuf);
4250 want_vcol = (want_vcol / ts) * ts;
4251 }
4252 else
4253 want_vcol = tabstop_start(want_vcol, get_sts_value(), 4251 want_vcol = tabstop_start(want_vcol, get_sts_value(),
4254 curbuf->b_p_vsts_array); 4252 curbuf->b_p_vsts_array);
4255 #else 4253 #else
4256 if (p_sta && in_indent) 4254 want_vcol -= want_vcol % (int)get_sts_value();
4257 ts = (int)get_sw_value(curbuf);
4258 else
4259 ts = (int)get_sts_value();
4260 want_vcol = (want_vcol / ts) * ts;
4261 #endif 4255 #endif
4262 4256
4263 // Find the position to stop backspacing. 4257 // Find the position to stop backspacing.
4264 // Use chartabsize() so that virtual text and wrapping are ignored. 4258 // Use chartabsize() so that virtual text and wrapping are ignored.
4265 while (TRUE) 4259 while (TRUE)