comparison src/ops.c @ 22278:0416105e103b v8.2.1688

patch 8.2.1688: increment/decrement removes text property Commit: https://github.com/vim/vim/commit/c8f12c9856df58c760fe54d81b2ec5ed4dcaffd6 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Sep 15 20:34:10 2020 +0200 patch 8.2.1688: increment/decrement removes text property Problem: Increment/decrement removes text property. Solution: Insert the new number before deleting the old one. (closes https://github.com/vim/vim/issues/6962)
author Bram Moolenaar <Bram@vim.org>
date Tue, 15 Sep 2020 20:45:03 +0200
parents 9064044fd4f6
children 5adb97bf0b32
comparison
equal deleted inserted replaced
22277:4575b886c258 22278:0416105e103b
2634 endpos = curwin->w_cursor; 2634 endpos = curwin->w_cursor;
2635 curwin->w_cursor.col = col; 2635 curwin->w_cursor.col = col;
2636 } 2636 }
2637 else 2637 else
2638 { 2638 {
2639 pos_T save_pos;
2640 int i;
2641
2639 if (col > 0 && ptr[col - 1] == '-' 2642 if (col > 0 && ptr[col - 1] == '-'
2640 && (!has_mbyte || 2643 && (!has_mbyte ||
2641 !(*mb_head_off)(ptr, ptr + col - 1)) 2644 !(*mb_head_off)(ptr, ptr + col - 1))
2642 && !visual 2645 && !visual
2643 && !do_unsigned) 2646 && !do_unsigned)
2732 * Don't include the '-' in the length, only the length of the 2735 * Don't include the '-' in the length, only the length of the
2733 * part after it is kept the same. 2736 * part after it is kept the same.
2734 */ 2737 */
2735 if (c == '-') 2738 if (c == '-')
2736 --length; 2739 --length;
2737 while (todel-- > 0) 2740
2741 save_pos = curwin->w_cursor;
2742 for (i = 0; i < todel; ++i)
2738 { 2743 {
2739 if (c < 0x100 && isalpha(c)) 2744 if (c < 0x100 && isalpha(c))
2740 { 2745 {
2741 if (isupper(c)) 2746 if (isupper(c))
2742 hexupper = TRUE; 2747 hexupper = TRUE;
2743 else 2748 else
2744 hexupper = FALSE; 2749 hexupper = FALSE;
2745 } 2750 }
2746 // del_char() will mark line needing displaying 2751 inc_cursor();
2747 (void)del_char(FALSE);
2748 c = gchar_cursor(); 2752 c = gchar_cursor();
2749 } 2753 }
2754 curwin->w_cursor = save_pos;
2750 2755
2751 /* 2756 /*
2752 * Prepare the leading characters in buf1[]. 2757 * Prepare the leading characters in buf1[].
2753 * When there are many leading zeros it could be very long. 2758 * When there are many leading zeros it could be very long.
2754 * Allocate a bit too much. 2759 * Allocate a bit too much.
2774 /* 2779 /*
2775 * Put the number characters in buf2[]. 2780 * Put the number characters in buf2[].
2776 */ 2781 */
2777 if (pre == 'b' || pre == 'B') 2782 if (pre == 'b' || pre == 'B')
2778 { 2783 {
2779 int i;
2780 int bit = 0; 2784 int bit = 0;
2781 int bits = sizeof(uvarnumber_T) * 8; 2785 int bits = sizeof(uvarnumber_T) * 8;
2782 2786
2783 // leading zeros 2787 // leading zeros
2784 for (bit = bits; bit > 0; bit--) 2788 for (bit = bits; bit > 0; bit--)
2807 */ 2811 */
2808 if (firstdigit == '0' && !(do_oct && pre == 0)) 2812 if (firstdigit == '0' && !(do_oct && pre == 0))
2809 while (length-- > 0) 2813 while (length-- > 0)
2810 *ptr++ = '0'; 2814 *ptr++ = '0';
2811 *ptr = NUL; 2815 *ptr = NUL;
2816
2812 STRCAT(buf1, buf2); 2817 STRCAT(buf1, buf2);
2818
2819 // Insert just after the first character to be removed, so that any
2820 // text properties will be adjusted. Then delete the old number
2821 // afterwards.
2822 save_pos = curwin->w_cursor;
2823 if (todel > 0)
2824 inc_cursor();
2813 ins_str(buf1); // insert the new number 2825 ins_str(buf1); // insert the new number
2814 vim_free(buf1); 2826 vim_free(buf1);
2827
2828 // del_char() will also mark line needing displaying
2829 if (todel > 0)
2830 {
2831 int bytes_after = (int)STRLEN(ml_get_curline())
2832 - curwin->w_cursor.col;
2833
2834 // Delete the one character before the insert.
2835 curwin->w_cursor = save_pos;
2836 (void)del_char(FALSE);
2837 curwin->w_cursor.col = STRLEN(ml_get_curline()) - bytes_after;
2838 --todel;
2839 }
2840 while (todel-- > 0)
2841 (void)del_char(FALSE);
2842
2815 endpos = curwin->w_cursor; 2843 endpos = curwin->w_cursor;
2816 if (did_change && curwin->w_cursor.col) 2844 if (did_change && curwin->w_cursor.col)
2817 --curwin->w_cursor.col; 2845 --curwin->w_cursor.col;
2818 } 2846 }
2819 2847