Mercurial > vim
comparison src/edit.c @ 34540:9e093c96dff6 v9.1.0172
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Commit: https://github.com/vim/vim/commit/94b7c3233ef534acc669b3083ed1fe59cf3a090b
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue Mar 12 21:50:32 2024 +0100
patch 9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Problem: More code can use ml_get_buf_len() instead of STRLEN().
Solution: Change more STRLEN() calls to ml_get_buf_len(). Also do not
set ml_line_textlen in ml_replace_len() if "has_props" is set,
because "len_arg" also includes the size of text properties in
that case. (zeertzjq)
closes: #14183
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 12 Mar 2024 22:00:04 +0100 |
parents | 64edf95a833a |
children | c94ef9458309 |
comparison
equal
deleted
inserted
replaced
34539:0dbb6f014f5e | 34540:9e093c96dff6 |
---|---|
3220 | 3220 |
3221 if (curbuf->b_has_textprop) | 3221 if (curbuf->b_has_textprop) |
3222 { | 3222 { |
3223 // Do not adjust text properties for individual delete and insert | 3223 // Do not adjust text properties for individual delete and insert |
3224 // operations, do it afterwards on the resulting text. | 3224 // operations, do it afterwards on the resulting text. |
3225 len_before = STRLEN(ml_get_curline()); | 3225 len_before = ml_get_curline_len(); |
3226 ++text_prop_frozen; | 3226 ++text_prop_frozen; |
3227 } | 3227 } |
3228 #endif | 3228 #endif |
3229 if (State & VREPLACE_FLAG) | 3229 if (State & VREPLACE_FLAG) |
3230 { | 3230 { |
3235 } | 3235 } |
3236 if (has_mbyte) | 3236 if (has_mbyte) |
3237 { | 3237 { |
3238 (void)del_char_after_col(limit_col); | 3238 (void)del_char_after_col(limit_col); |
3239 if (State & VREPLACE_FLAG) | 3239 if (State & VREPLACE_FLAG) |
3240 orig_len = (int)STRLEN(ml_get_cursor()); | 3240 orig_len = ml_get_cursor_len(); |
3241 replace_push(cc); | 3241 replace_push(cc); |
3242 } | 3242 } |
3243 else | 3243 else |
3244 { | 3244 { |
3245 pchar_cursor(cc); | 3245 pchar_cursor(cc); |
3246 if (State & VREPLACE_FLAG) | 3246 if (State & VREPLACE_FLAG) |
3247 orig_len = (int)STRLEN(ml_get_cursor()) - 1; | 3247 orig_len = ml_get_cursor_len() - 1; |
3248 } | 3248 } |
3249 replace_pop_ins(); | 3249 replace_pop_ins(); |
3250 | 3250 |
3251 if (State & VREPLACE_FLAG) | 3251 if (State & VREPLACE_FLAG) |
3252 { | 3252 { |
3253 // Get the number of screen cells used by the inserted characters | 3253 // Get the number of screen cells used by the inserted characters |
3254 p = ml_get_cursor(); | 3254 p = ml_get_cursor(); |
3255 ins_len = (int)STRLEN(p) - orig_len; | 3255 ins_len = ml_get_cursor_len() - orig_len; |
3256 vcol = start_vcol; | 3256 vcol = start_vcol; |
3257 for (i = 0; i < ins_len; ++i) | 3257 for (i = 0; i < ins_len; ++i) |
3258 { | 3258 { |
3259 vcol += chartabsize(p + i, vcol); | 3259 vcol += chartabsize(p + i, vcol); |
3260 i += (*mb_ptr2len)(p) - 1; | 3260 i += (*mb_ptr2len)(p) - 1; |
3276 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); | 3276 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); |
3277 | 3277 |
3278 #ifdef FEAT_PROP_POPUP | 3278 #ifdef FEAT_PROP_POPUP |
3279 if (curbuf->b_has_textprop) | 3279 if (curbuf->b_has_textprop) |
3280 { | 3280 { |
3281 size_t len_now = STRLEN(ml_get_curline()); | 3281 size_t len_now = ml_get_curline_len(); |
3282 | 3282 |
3283 --text_prop_frozen; | 3283 --text_prop_frozen; |
3284 adjust_prop_columns(curwin->w_cursor.lnum, curwin->w_cursor.col, | 3284 adjust_prop_columns(curwin->w_cursor.lnum, curwin->w_cursor.col, |
3285 (int)(len_now - len_before), 0); | 3285 (int)(len_now - len_before), 0); |
3286 } | 3286 } |
4066 { | 4066 { |
4067 if (u_save((linenr_T)(curwin->w_cursor.lnum - 2), | 4067 if (u_save((linenr_T)(curwin->w_cursor.lnum - 2), |
4068 (linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL) | 4068 (linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL) |
4069 return FALSE; | 4069 return FALSE; |
4070 --Insstart.lnum; | 4070 --Insstart.lnum; |
4071 Insstart.col = (colnr_T)STRLEN(ml_get(Insstart.lnum)); | 4071 Insstart.col = ml_get_len(Insstart.lnum); |
4072 } | 4072 } |
4073 /* | 4073 /* |
4074 * In replace mode: | 4074 * In replace mode: |
4075 * cc < 0: NL was inserted, delete it | 4075 * cc < 0: NL was inserted, delete it |
4076 * cc >= 0: NL was replaced, put original characters back | 4076 * cc >= 0: NL was replaced, put original characters back |
5172 | 5172 |
5173 #ifdef FEAT_RIGHTLEFT | 5173 #ifdef FEAT_RIGHTLEFT |
5174 // NL in reverse insert will always start in the end of | 5174 // NL in reverse insert will always start in the end of |
5175 // current line. | 5175 // current line. |
5176 if (revins_on) | 5176 if (revins_on) |
5177 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); | 5177 curwin->w_cursor.col += ml_get_cursor_len(); |
5178 #endif | 5178 #endif |
5179 | 5179 |
5180 AppendToRedobuff(NL_STR); | 5180 AppendToRedobuff(NL_STR); |
5181 i = open_line(FORWARD, | 5181 i = open_line(FORWARD, |
5182 has_format_option(FO_RET_COMS) ? OPENLINE_DO_COM : 0, old_indent, | 5182 has_format_option(FO_RET_COMS) ? OPENLINE_DO_COM : 0, old_indent, |