comparison src/misc1.c @ 15341:03a7a9fdb792 v8.1.0678

patch 8.1.0678: text properties as not adjusted for inserted text commit https://github.com/vim/vim/commit/44746aa1eb506ebe6e8fc71f6e549a0dcb754526 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 2 00:02:11 2019 +0100 patch 8.1.0678: text properties as not adjusted for inserted text Problem: Text properties as not adjusted for inserted text. Solution: Adjust text properties when inserting text.
author Bram Moolenaar <Bram@vim.org>
date Wed, 02 Jan 2019 00:15:05 +0100
parents fe428bee74b3
children f6b522596993
comparison
equal deleted inserted replaced
15340:90d037c7fa06 15341:03a7a9fdb792
2320 2320
2321 if (has_mbyte) 2321 if (has_mbyte)
2322 for (i = 0; i < len; i += n) 2322 for (i = 0; i < len; i += n)
2323 { 2323 {
2324 if (enc_utf8) 2324 if (enc_utf8)
2325 /* avoid reading past p[len] */ 2325 // avoid reading past p[len]
2326 n = utfc_ptr2len_len(p + i, len - i); 2326 n = utfc_ptr2len_len(p + i, len - i);
2327 else 2327 else
2328 n = (*mb_ptr2len)(p + i); 2328 n = (*mb_ptr2len)(p + i);
2329 ins_char_bytes(p + i, n); 2329 ins_char_bytes(p + i, n);
2330 } 2330 }
2363 2363
2364 void 2364 void
2365 ins_char_bytes(char_u *buf, int charlen) 2365 ins_char_bytes(char_u *buf, int charlen)
2366 { 2366 {
2367 int c = buf[0]; 2367 int c = buf[0];
2368 int newlen; /* nr of bytes inserted */ 2368 int newlen; // nr of bytes inserted
2369 int oldlen; /* nr of bytes deleted (0 when not replacing) */ 2369 int oldlen; // nr of bytes deleted (0 when not replacing)
2370 char_u *p; 2370 char_u *p;
2371 char_u *newp; 2371 char_u *newp;
2372 char_u *oldp; 2372 char_u *oldp;
2373 int linelen; /* length of old line including NUL */ 2373 int linelen; // length of old line including NUL
2374 colnr_T col; 2374 colnr_T col;
2375 linenr_T lnum = curwin->w_cursor.lnum; 2375 linenr_T lnum = curwin->w_cursor.lnum;
2376 int i; 2376 int i;
2377 2377
2378 #ifdef FEAT_VIRTUALEDIT 2378 #ifdef FEAT_VIRTUALEDIT
2437 if (vcol > new_vcol) 2437 if (vcol > new_vcol)
2438 newlen += vcol - new_vcol; 2438 newlen += vcol - new_vcol;
2439 } 2439 }
2440 curwin->w_p_list = old_list; 2440 curwin->w_p_list = old_list;
2441 } 2441 }
2442 else 2442 else if (oldp[col] != NUL)
2443 if (oldp[col] != NUL)
2444 { 2443 {
2445 /* normal replace */ 2444 /* normal replace */
2446 #ifdef FEAT_MBYTE 2445 #ifdef FEAT_MBYTE
2447 oldlen = (*mb_ptr2len)(oldp + col); 2446 oldlen = (*mb_ptr2len)(oldp + col);
2448 #else 2447 #else
2492 2491
2493 /* Fill with spaces when necessary. */ 2492 /* Fill with spaces when necessary. */
2494 while (i < newlen) 2493 while (i < newlen)
2495 p[i++] = ' '; 2494 p[i++] = ' ';
2496 2495
2497 /* Replace the line in the buffer. */ 2496 // Replace the line in the buffer.
2498 ml_replace(lnum, newp, FALSE); 2497 ml_replace(lnum, newp, FALSE);
2499 2498
2500 /* mark the buffer as changed and prepare for displaying */ 2499 // mark the buffer as changed and prepare for displaying
2501 changed_bytes(lnum, col); 2500 inserted_bytes(lnum, col, newlen - oldlen);
2502 2501
2503 /* 2502 /*
2504 * If we're in Insert or Replace mode and 'showmatch' is set, then briefly 2503 * If we're in Insert or Replace mode and 'showmatch' is set, then briefly
2505 * show the match for right parens and braces. 2504 * show the match for right parens and braces.
2506 */ 2505 */
2564 if (col > 0) 2563 if (col > 0)
2565 mch_memmove(newp, oldp, (size_t)col); 2564 mch_memmove(newp, oldp, (size_t)col);
2566 mch_memmove(newp + col, s, (size_t)newlen); 2565 mch_memmove(newp + col, s, (size_t)newlen);
2567 mch_memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1)); 2566 mch_memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1));
2568 ml_replace(lnum, newp, FALSE); 2567 ml_replace(lnum, newp, FALSE);
2569 changed_bytes(lnum, col); 2568 inserted_bytes(lnum, col, newlen);
2570 curwin->w_cursor.col += newlen; 2569 curwin->w_cursor.col += newlen;
2571 } 2570 }
2572 2571
2573 /* 2572 /*
2574 * Delete one character under the cursor. 2573 * Delete one character under the cursor.
3011 wlnum = diff_lnum_win(lnum, wp); 3010 wlnum = diff_lnum_win(lnum, wp);
3012 if (wlnum > 0) 3011 if (wlnum > 0)
3013 changedOneline(wp->w_buffer, wlnum); 3012 changedOneline(wp->w_buffer, wlnum);
3014 } 3013 }
3015 } 3014 }
3015 #endif
3016 }
3017
3018 /*
3019 * Like changed_bytes() but also adjust text properties for "added" bytes.
3020 * When "added" is negative text was deleted.
3021 */
3022 void
3023 inserted_bytes(linenr_T lnum, colnr_T col, int added)
3024 {
3025 changed_bytes(lnum, col);
3026
3027 #ifdef FEAT_TEXT_PROP
3028 if (curbuf->b_has_textprop && added != 0)
3029 adjust_prop_columns(lnum, col, added);
3016 #endif 3030 #endif
3017 } 3031 }
3018 3032
3019 static void 3033 static void
3020 changedOneline(buf_T *buf, linenr_T lnum) 3034 changedOneline(buf_T *buf, linenr_T lnum)