comparison src/ops.c @ 14216:12bdbf9f7e20 v8.1.0125

patch 8.1.0125: virtual edit replace with multi-byte fails at end of line commit https://github.com/vim/vim/commit/630afe889a2a02b367ea8eaaa48e66ed81e77ff3 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 28 19:26:28 2018 +0200 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line Problem: Virtual edit replace with multi-byte fails at end of line. (Lukas Werling) Solution: use ins_char() to add the character. (Christian Brabandt, closes #3114) Rename PCHAR() to PBYTE() to avoid mistakes like this.
author Christian Brabandt <cb@256bit.org>
date Thu, 28 Jun 2018 19:30:07 +0200
parents 51693b1a640e
children 3c80092eb211
comparison
equal deleted inserted replaced
14215:b0083bebf159 14216:12bdbf9f7e20
2144 } 2144 }
2145 } 2145 }
2146 #endif 2146 #endif
2147 2147
2148 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) 2148 #if defined(FEAT_VISUALEXTRA) || defined(PROTO)
2149
2150 # ifdef FEAT_MBYTE
2151 /*
2152 * Replace the character under the cursor with "c".
2153 * This takes care of multi-byte characters.
2154 */
2155 static void
2156 replace_character(int c)
2157 {
2158 int n = State;
2159
2160 State = REPLACE;
2161 ins_char(c);
2162 State = n;
2163 /* Backup to the replaced character. */
2164 dec_cursor();
2165 }
2166
2167 # endif
2149 /* 2168 /*
2150 * Replace a whole area with one character. 2169 * Replace a whole area with one character.
2151 */ 2170 */
2152 int 2171 int
2153 op_replace(oparg_T *oap, int c) 2172 op_replace(oparg_T *oap, int c)
2329 { 2348 {
2330 /* This is slow, but it handles replacing a single-byte 2349 /* This is slow, but it handles replacing a single-byte
2331 * with a multi-byte and the other way around. */ 2350 * with a multi-byte and the other way around. */
2332 if (curwin->w_cursor.lnum == oap->end.lnum) 2351 if (curwin->w_cursor.lnum == oap->end.lnum)
2333 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); 2352 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n);
2334 n = State; 2353 replace_character(c);
2335 State = REPLACE;
2336 ins_char(c);
2337 State = n;
2338 /* Backup to the replaced character. */
2339 dec_cursor();
2340 } 2354 }
2341 else 2355 else
2342 #endif 2356 #endif
2343 { 2357 {
2344 #ifdef FEAT_VIRTUALEDIT 2358 #ifdef FEAT_VIRTUALEDIT
2356 coladvance_force(getviscol()); 2370 coladvance_force(getviscol());
2357 if (curwin->w_cursor.lnum == oap->end.lnum) 2371 if (curwin->w_cursor.lnum == oap->end.lnum)
2358 getvpos(&oap->end, end_vcol); 2372 getvpos(&oap->end, end_vcol);
2359 } 2373 }
2360 #endif 2374 #endif
2361 PCHAR(curwin->w_cursor, c); 2375 PBYTE(curwin->w_cursor, c);
2362 } 2376 }
2363 } 2377 }
2364 #ifdef FEAT_VIRTUALEDIT 2378 #ifdef FEAT_VIRTUALEDIT
2365 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) 2379 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum)
2366 { 2380 {
2375 * trample the NUL byte. */ 2389 * trample the NUL byte. */
2376 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); 2390 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1);
2377 curwin->w_cursor.col -= (virtcols + 1); 2391 curwin->w_cursor.col -= (virtcols + 1);
2378 for (; virtcols >= 0; virtcols--) 2392 for (; virtcols >= 0; virtcols--)
2379 { 2393 {
2380 PCHAR(curwin->w_cursor, c); 2394 #ifdef FEAT_MBYTE
2381 if (inc(&curwin->w_cursor) == -1) 2395 if ((*mb_char2len)(c) > 1)
2382 break; 2396 replace_character(c);
2397 else
2398 #endif
2399 PBYTE(curwin->w_cursor, c);
2400 if (inc(&curwin->w_cursor) == -1)
2401 break;
2383 } 2402 }
2384 } 2403 }
2385 #endif 2404 #endif
2386 2405
2387 /* Advance to next character, stop at the end of the file. */ 2406 /* Advance to next character, stop at the end of the file. */
2617 ins_char(nc); 2636 ins_char(nc);
2618 curwin->w_cursor = sp; 2637 curwin->w_cursor = sp;
2619 } 2638 }
2620 else 2639 else
2621 #endif 2640 #endif
2622 PCHAR(*pos, nc); 2641 PBYTE(*pos, nc);
2623 return TRUE; 2642 return TRUE;
2624 } 2643 }
2625 return FALSE; 2644 return FALSE;
2626 } 2645 }
2627 2646