mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(spell): splice extmarks on :spellrepall (#23929)
This commit is contained in:
		| @@ -2604,9 +2604,11 @@ void ex_spellrepall(exarg_T *eap) | |||||||
|     emsg(_("E752: No previous spell replacement")); |     emsg(_("E752: No previous spell replacement")); | ||||||
|     return; |     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); |   char *frompat = xmalloc(frompatlen); | ||||||
|   snprintf(frompat, frompatlen, "\\V\\<%s\\>", repl_from); |   snprintf(frompat, frompatlen, "\\V\\<%s\\>", repl_from); | ||||||
|   p_ws = false; |   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 |     // Only replace when the right word isn't there yet.  This happens | ||||||
|     // when changing "etc" to "etc.". |     // when changing "etc" to "etc.". | ||||||
|     char *line = get_cursor_line_ptr(); |     char *line = get_cursor_line_ptr(); | ||||||
|     if (addlen <= 0 || strncmp(line + curwin->w_cursor.col, |     if (addlen <= 0 | ||||||
|                                repl_to, strlen(repl_to)) != 0) { |         || strncmp(line + curwin->w_cursor.col, repl_to, repl_to_len) != 0) { | ||||||
|       char *p = xmalloc(strlen(line) + (size_t)addlen + 1); |       char *p = xmalloc(strlen(line) + (size_t)addlen + 1); | ||||||
|       memmove(p, line, (size_t)curwin->w_cursor.col); |       memmove(p, line, (size_t)curwin->w_cursor.col); | ||||||
|       STRCPY(p + curwin->w_cursor.col, repl_to); |       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); |       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) { |       if (curwin->w_cursor.lnum != prev_lnum) { | ||||||
|         sub_nlines++; |         sub_nlines++; | ||||||
| @@ -2638,7 +2641,7 @@ void ex_spellrepall(exarg_T *eap) | |||||||
|       } |       } | ||||||
|       sub_nsubs++; |       sub_nsubs++; | ||||||
|     } |     } | ||||||
|     curwin->w_cursor.col += (colnr_T)strlen(repl_to); |     curwin->w_cursor.col += (colnr_T)repl_to_len; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   p_ws = save_ws; |   p_ws = save_ws; | ||||||
|   | |||||||
| @@ -1164,12 +1164,17 @@ describe('lua: nvim_buf_attach on_bytes', function() | |||||||
|     end) |     end) | ||||||
|  |  | ||||||
|     it("works with accepting spell suggestions", function() |     it("works with accepting spell suggestions", function() | ||||||
|       local check_events = setup_eventcheck(verify, {"hallo"}) |       local check_events = setup_eventcheck(verify, {"hallo world", "hallo world"}) | ||||||
|  |  | ||||||
|       feed("gg0z=4<cr><cr>") -- accepts 'Hello' |       feed("gg0z=4<cr><cr>") -- accepts 'Hello' | ||||||
|       check_events { |       check_events { | ||||||
|         { "test1", "bytes", 1, 3, 0, 0, 0, 0, 2, 2, 0, 2, 2 }; |         { "test1", "bytes", 1, 3, 0, 0, 0, 0, 2, 2, 0, 2, 2 }; | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  |       command("spellrepall") -- replaces whole words | ||||||
|  |       check_events { | ||||||
|  |         { "test1", "bytes", 1, 4, 1, 0, 12, 0, 5, 5, 0, 5, 5 }; | ||||||
|  |       } | ||||||
|     end) |     end) | ||||||
|  |  | ||||||
|     it('works with :diffput and :diffget', function() |     it('works with :diffput and :diffget', function() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 zeertzjq
					zeertzjq