comparison src/misc1.c @ 15138:9df130fd5e0d v8.1.0579

patch 8.1.0579: cannot attach properties to text commit https://github.com/vim/vim/commit/98aefe7c3250bb5d4153b994f878594d1745424e Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 13 22:20:09 2018 +0100 patch 8.1.0579: cannot attach properties to text Problem: Cannot attach properties to text. Solution: First part of adding text properties.
author Bram Moolenaar <Bram@vim.org>
date Thu, 13 Dec 2018 22:30:08 +0100
parents 31a0127813cb
children d7a8f390f6d2
comparison
equal deleted inserted replaced
15137:44f47a35a3f4 15138:9df130fd5e0d
2629 int fixpos_arg, 2629 int fixpos_arg,
2630 int use_delcombine UNUSED) /* 'delcombine' option applies */ 2630 int use_delcombine UNUSED) /* 'delcombine' option applies */
2631 { 2631 {
2632 char_u *oldp, *newp; 2632 char_u *oldp, *newp;
2633 colnr_T oldlen; 2633 colnr_T oldlen;
2634 colnr_T newlen;
2634 linenr_T lnum = curwin->w_cursor.lnum; 2635 linenr_T lnum = curwin->w_cursor.lnum;
2635 colnr_T col = curwin->w_cursor.col; 2636 colnr_T col = curwin->w_cursor.col;
2636 int was_alloced; 2637 int alloc_newp;
2637 long movelen; 2638 long movelen;
2638 int fixpos = fixpos_arg; 2639 int fixpos = fixpos_arg;
2639 2640
2640 oldp = ml_get(lnum); 2641 oldp = ml_get(lnum);
2641 oldlen = (int)STRLEN(oldp); 2642 oldlen = (int)STRLEN(oldp);
2708 #endif 2709 #endif
2709 } 2710 }
2710 count = oldlen - col; 2711 count = oldlen - col;
2711 movelen = 1; 2712 movelen = 1;
2712 } 2713 }
2714 newlen = oldlen - count;
2713 2715
2714 /* 2716 /*
2715 * If the old line has been allocated the deletion can be done in the 2717 * If the old line has been allocated the deletion can be done in the
2716 * existing line. Otherwise a new line has to be allocated 2718 * existing line. Otherwise a new line has to be allocated
2717 * Can't do this when using Netbeans, because we would need to invoke 2719 * Can't do this when using Netbeans, because we would need to invoke
2718 * netbeans_removed(), which deallocates the line. Let ml_replace() take 2720 * netbeans_removed(), which deallocates the line. Let ml_replace() take
2719 * care of notifying Netbeans. 2721 * care of notifying Netbeans.
2720 */ 2722 */
2721 #ifdef FEAT_NETBEANS_INTG 2723 #ifdef FEAT_NETBEANS_INTG
2722 if (netbeans_active()) 2724 if (netbeans_active())
2723 was_alloced = FALSE; 2725 alloc_newp = TRUE;
2724 else 2726 else
2725 #endif 2727 #endif
2726 was_alloced = ml_line_alloced(); /* check if oldp was allocated */ 2728 alloc_newp = !ml_line_alloced(); // check if oldp was allocated
2727 if (was_alloced) 2729 if (!alloc_newp)
2728 newp = oldp; /* use same allocated memory */ 2730 newp = oldp; // use same allocated memory
2729 else 2731 else
2730 { /* need to allocate a new line */ 2732 { // need to allocate a new line
2731 newp = alloc((unsigned)(oldlen + 1 - count)); 2733 newp = alloc((unsigned)(newlen + 1));
2732 if (newp == NULL) 2734 if (newp == NULL)
2733 return FAIL; 2735 return FAIL;
2734 mch_memmove(newp, oldp, (size_t)col); 2736 mch_memmove(newp, oldp, (size_t)col);
2735 } 2737 }
2736 mch_memmove(newp + col, oldp + col + count, (size_t)movelen); 2738 mch_memmove(newp + col, oldp + col + count, (size_t)movelen);
2737 if (!was_alloced) 2739 if (alloc_newp)
2738 ml_replace(lnum, newp, FALSE); 2740 ml_replace(lnum, newp, FALSE);
2739 2741 #ifdef FEAT_TEXT_PROP
2740 /* mark the buffer as changed and prepare for displaying */ 2742 else
2743 {
2744 // Also move any following text properties.
2745 if (oldlen + 1 < curbuf->b_ml.ml_line_len)
2746 mch_memmove(newp + newlen + 1, oldp + oldlen + 1,
2747 (size_t)curbuf->b_ml.ml_line_len - oldlen - 1);
2748 curbuf->b_ml.ml_line_len -= count;
2749 }
2750 #endif
2751
2752 // mark the buffer as changed and prepare for displaying
2741 changed_bytes(lnum, curwin->w_cursor.col); 2753 changed_bytes(lnum, curwin->w_cursor.col);
2742 2754
2743 return OK; 2755 return OK;
2744 } 2756 }
2745 2757