To: vim_dev@googlegroups.com Subject: Patch 8.1.2216 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2216 Problem: Text property in wrong place after :substitute. Solution: Pass the new column instead of the old one. (Christian Brabandt, closes #4427) Files: src/ex_cmds.c, src/testdir/test_textprop.vim *** ../vim-8.1.2215/src/ex_cmds.c 2019-10-21 23:08:54.692802253 +0200 --- src/ex_cmds.c 2019-10-25 22:04:07.455027571 +0200 *************** *** 3856,3861 **** --- 3856,3862 ---- colnr_T matchcol; colnr_T prev_matchcol = MAXCOL; char_u *new_end, *new_start = NULL; + colnr_T total_added = 0; unsigned new_start_len = 0; char_u *p1; int did_sub = FALSE; *************** *** 4279,4291 **** #ifdef FEAT_TEXT_PROP if (curbuf->b_has_textprop) { // When text properties are changed, need to save for // undo first, unless done already. ! if (adjust_prop_columns(lnum, regmatch.startpos[0].col, ! sublen - 1 - (regmatch.endpos[0].col ! - regmatch.startpos[0].col), ! apc_flags)) apc_flags &= ~APC_SAVE_FOR_UNDO; } #endif } --- 4280,4297 ---- #ifdef FEAT_TEXT_PROP if (curbuf->b_has_textprop) { + int bytes_added = sublen - 1 - (regmatch.endpos[0].col + - regmatch.startpos[0].col); + // When text properties are changed, need to save for // undo first, unless done already. ! if (adjust_prop_columns(lnum, ! total_added + regmatch.startpos[0].col, ! bytes_added, apc_flags)) apc_flags &= ~APC_SAVE_FOR_UNDO; + // Offset for column byte number of the text property + // in the resulting buffer afterwards. + total_added += bytes_added; } #endif } *** ../vim-8.1.2215/src/testdir/test_textprop.vim 2019-10-16 14:38:01.916048915 +0200 --- src/testdir/test_textprop.vim 2019-10-25 22:11:20.497813312 +0200 *************** *** 866,868 **** --- 866,896 ---- cal delete('Xaaa') cal delete('Xbbb') endfunc + + func Test_proptype_substitute2() + new + " text_prop.vim + call setline(1, [ + \ 'The num 123 is smaller than 4567.', + \ '123 The number 123 is smaller than 4567.', + \ '123 The number 123 is smaller than 4567.']) + + call prop_type_add('number', {'highlight': 'ErrorMsg'}) + + call prop_add(1, 12, {'length': 3, 'type': 'number'}) + call prop_add(2, 1, {'length': 3, 'type': 'number'}) + call prop_add(3, 36, {'length': 4, 'type': 'number'}) + set ul& + let expected = [{'id': 0, 'col': 13, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}, + \ {'id': 0, 'col': 1, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}, + \ {'id': 0, 'col': 50, 'end': 1, 'type': 'number', 'length': 4, 'start': 1}] + " Add some text in between + %s/\s\+/ /g + call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3)) + + " remove some text + :1s/[a-z]\{3\}//g + let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}] + call assert_equal(expected, prop_list(1)) + bwipe! + endfunc *** ../vim-8.1.2215/src/version.c 2019-10-25 21:49:35.765964704 +0200 --- src/version.c 2019-10-25 21:56:36.808248129 +0200 *************** *** 743,744 **** --- 743,746 ---- { /* Add new patch number below this line */ + /**/ + 2216, /**/ -- The budget process was invented by an alien race of sadistic beings who resemble large cats. (Scott Adams - The Dilbert principle) /// 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 ///