To: vim_dev@googlegroups.com Subject: Patch 8.2.1688 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1688 Problem: Increment/decrement removes text property. Solution: Insert the new number before deleting the old one. (closes #6962) Files: src/ops.c, src/testdir/test_textprop.vim *** ../vim-8.2.1687/src/ops.c 2020-06-12 22:59:07.266097201 +0200 --- src/ops.c 2020-09-15 20:07:12.369804853 +0200 *************** *** 2636,2641 **** --- 2636,2644 ---- } else { + pos_T save_pos; + int i; + if (col > 0 && ptr[col - 1] == '-' && (!has_mbyte || !(*mb_head_off)(ptr, ptr + col - 1)) *************** *** 2734,2740 **** */ if (c == '-') --length; ! while (todel-- > 0) { if (c < 0x100 && isalpha(c)) { --- 2737,2745 ---- */ if (c == '-') --length; ! ! save_pos = curwin->w_cursor; ! for (i = 0; i < todel; ++i) { if (c < 0x100 && isalpha(c)) { *************** *** 2743,2752 **** else hexupper = FALSE; } ! // del_char() will mark line needing displaying ! (void)del_char(FALSE); c = gchar_cursor(); } /* * Prepare the leading characters in buf1[]. --- 2748,2757 ---- else hexupper = FALSE; } ! inc_cursor(); c = gchar_cursor(); } + curwin->w_cursor = save_pos; /* * Prepare the leading characters in buf1[]. *************** *** 2776,2782 **** */ if (pre == 'b' || pre == 'B') { - int i; int bit = 0; int bits = sizeof(uvarnumber_T) * 8; --- 2781,2786 ---- *************** *** 2809,2817 **** --- 2813,2845 ---- while (length-- > 0) *ptr++ = '0'; *ptr = NUL; + STRCAT(buf1, buf2); + + // Insert just after the first character to be removed, so that any + // text properties will be adjusted. Then delete the old number + // afterwards. + save_pos = curwin->w_cursor; + if (todel > 0) + inc_cursor(); ins_str(buf1); // insert the new number vim_free(buf1); + + // del_char() will also mark line needing displaying + if (todel > 0) + { + int bytes_after = (int)STRLEN(ml_get_curline()) + - curwin->w_cursor.col; + + // Delete the one character before the insert. + curwin->w_cursor = save_pos; + (void)del_char(FALSE); + curwin->w_cursor.col = STRLEN(ml_get_curline()) - bytes_after; + --todel; + } + while (todel-- > 0) + (void)del_char(FALSE); + endpos = curwin->w_cursor; if (did_change && curwin->w_cursor.col) --curwin->w_cursor.col; *** ../vim-8.2.1687/src/testdir/test_textprop.vim 2020-09-06 15:58:33.383154915 +0200 --- src/testdir/test_textprop.vim 2020-09-15 20:09:06.589417582 +0200 *************** *** 1273,1279 **** call assert_fails("call prop_type_list([])", 'E715:') endfunc ! func Test_split_join() new call prop_type_add('test', {'highlight': 'ErrorMsg'}) call setline(1, 'just some text') --- 1273,1279 ---- call assert_fails("call prop_type_list([])", 'E715:') endfunc ! func Test_prop_split_join() new call prop_type_add('test', {'highlight': 'ErrorMsg'}) call setline(1, 'just some text') *************** *** 1292,1297 **** --- 1292,1317 ---- bwipe! call prop_type_delete('test') + endfunc + + func Test_prop_increment_decrement() + new + call prop_type_add('test', {'highlight': 'ErrorMsg'}) + call setline(1, 'its 998 times') + call prop_add(1, 5, {'length': 3, 'type': 'test'}) + + exe "normal! 0f9\" + eval getline(1)->assert_equal('its 999 times') + eval prop_list(1)->assert_equal([ + \ #{id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}]) + + exe "normal! 0f9\" + eval getline(1)->assert_equal('its 1000 times') + eval prop_list(1)->assert_equal([ + \ #{id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}]) + + bwipe! + call prop_type_delete('test') endfunc " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.1687/src/version.c 2020-09-14 22:39:05.969192788 +0200 --- src/version.c 2020-09-15 19:40:01.335261096 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1688, /**/ -- ARTHUR: CHARGE! [The mighty ARMY charges. Thundering noise of feet. Clatter of coconuts. Shouts etc. Suddenly there is a wail of a siren and a couple of police cars roar round in front of the charging ARMY and the POLICE leap out and stop them. TWO POLICEMAN and the HISTORIAN'S WIFE. Black Marias skid up behind them.] HISTORIAN'S WIFE: They're the ones, I'm sure. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///