From eceb2dffce3908507092ffe425b1ceef5baeb1ab Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Jun 2023 10:32:30 +0800 Subject: fix(spell): splice extmarks on :spellrepall (#23929) --- src/nvim/spell.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 778266e5ac..9ae2036ee0 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2604,9 +2604,11 @@ void ex_spellrepall(exarg_T *eap) emsg(_("E752: No previous spell replacement")); return; } - int addlen = (int)(strlen(repl_to) - strlen(repl_from)); + const size_t repl_from_len = strlen(repl_from); + const size_t repl_to_len = strlen(repl_to); + int addlen = (int)(repl_to_len - repl_from_len); - size_t frompatlen = strlen(repl_from) + 7; + const size_t frompatlen = repl_from_len + 7; char *frompat = xmalloc(frompatlen); snprintf(frompat, frompatlen, "\\V\\<%s\\>", repl_from); p_ws = false; @@ -2623,14 +2625,15 @@ void ex_spellrepall(exarg_T *eap) // Only replace when the right word isn't there yet. This happens // when changing "etc" to "etc.". char *line = get_cursor_line_ptr(); - if (addlen <= 0 || strncmp(line + curwin->w_cursor.col, - repl_to, strlen(repl_to)) != 0) { + if (addlen <= 0 + || strncmp(line + curwin->w_cursor.col, repl_to, repl_to_len) != 0) { char *p = xmalloc(strlen(line) + (size_t)addlen + 1); memmove(p, line, (size_t)curwin->w_cursor.col); STRCPY(p + curwin->w_cursor.col, repl_to); - STRCAT(p, line + curwin->w_cursor.col + strlen(repl_from)); + STRCAT(p, line + curwin->w_cursor.col + repl_from_len); ml_replace(curwin->w_cursor.lnum, p, false); - changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); + inserted_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col, + (int)repl_from_len, (int)repl_to_len); if (curwin->w_cursor.lnum != prev_lnum) { sub_nlines++; @@ -2638,7 +2641,7 @@ void ex_spellrepall(exarg_T *eap) } sub_nsubs++; } - curwin->w_cursor.col += (colnr_T)strlen(repl_to); + curwin->w_cursor.col += (colnr_T)repl_to_len; } p_ws = save_ws; -- cgit