To: vim_dev@googlegroups.com Subject: Patch 9.0.1077 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1077 Problem: Can add text property with negative ID before virtual text property. Solution: Remember that a text property with a negative ID was used and give an appropriate error message. (closes #11725) Fix index computation. Files: src/textprop.c, src/errors.h, src/charset.c, src/testdir/test_textprop.vim, src/testdir/dumps/Test_prop_negative_error_1.dump, src/testdir/dumps/Test_prop_negative_error_2.dump *** ../vim-9.0.1076/src/textprop.c 2022-12-02 20:46:01.936019457 +0000 --- src/textprop.c 2022-12-19 12:56:46.432201033 +0000 *************** *** 424,429 **** --- 424,433 ---- return -(buf->b_textprop_text.ga_len + 1); } + // Flag that is set when a negative ID isused for a normal text property. + // It is then impossible to use virtual text properties. + static int did_use_negative_pop_id = FALSE; + /* * Shared between prop_add() and popup_create(). * "dict_arg" is the function argument of a dict containing "bufnr". *************** *** 576,588 **** if (dict_arg != NULL && get_bufnr_from_arg(dict_arg, &buf) == FAIL) goto theend; ! if (id < 0 && buf->b_textprop_text.ga_len > 0) { ! emsg(_(e_cannot_use_negative_id_after_adding_textprop_with_text)); ! goto theend; } if (text != NULL) id = get_textprop_id(buf); // This must be done _before_ we add the property because property changes // trigger buffer (memline) reorganisation, which needs this flag to be --- 580,604 ---- if (dict_arg != NULL && get_bufnr_from_arg(dict_arg, &buf) == FAIL) goto theend; ! if (id < 0) { ! if (buf->b_textprop_text.ga_len > 0) ! { ! emsg(_(e_cannot_use_negative_id_after_adding_textprop_with_text)); ! goto theend; ! } ! did_use_negative_pop_id = TRUE; } + if (text != NULL) + { + if (did_use_negative_pop_id) + { + emsg(_(e_cannot_add_textprop_with_text_after_using_textprop_with_negative_id)); + goto theend; + } id = get_textprop_id(buf); + } // This must be done _before_ we add the property because property changes // trigger buffer (memline) reorganisation, which needs this flag to be *** ../vim-9.0.1076/src/errors.h 2022-12-18 21:42:49.010716927 +0000 --- src/errors.h 2022-12-19 13:05:03.482436969 +0000 *************** *** 3397,3399 **** --- 3397,3403 ---- EXTERN char e_member_not_found_on_class_str_str[] INIT(= N_("E1338: Member not found on class \"%s\": %s")); #endif + #ifdef FEAT_PROP_POPUP + EXTERN char e_cannot_add_textprop_with_text_after_using_textprop_with_negative_id[] + INIT(= N_("E1339: Cannot add a textprop with text after using a textprop with a negative id")); + #endif *** ../vim-9.0.1076/src/charset.c 2022-12-06 14:17:32.178527467 +0000 --- src/charset.c 2022-12-19 13:03:10.186757558 +0000 *************** *** 1181,1187 **** ? col == 0 : (s[0] == NUL || s[1] == NUL) && cts->cts_with_trailing))) ! && tp->tp_id - 1 < gap->ga_len) { char_u *p = ((char_u **)gap->ga_data)[-tp->tp_id - 1]; --- 1181,1187 ---- ? col == 0 : (s[0] == NUL || s[1] == NUL) && cts->cts_with_trailing))) ! && -tp->tp_id - 1 < gap->ga_len) { char_u *p = ((char_u **)gap->ga_data)[-tp->tp_id - 1]; *** ../vim-9.0.1076/src/testdir/test_textprop.vim 2022-12-17 11:32:37.918855670 +0000 --- src/testdir/test_textprop.vim 2022-12-19 13:28:03.439879237 +0000 *************** *** 3725,3730 **** --- 3725,3774 ---- call StopVimInTerminal(buf) endfunc + + func Test_error_when_using_negative_id() + call prop_type_add('test1', #{highlight: 'ErrorMsg'}) + call prop_add(1, 1, #{type: 'test1', text: 'virtual'}) + call assert_fails("call prop_add(1, 1, #{type: 'test1', length: 1, id: -1})", 'E1293:') + + call prop_type_delete('test1') + endfunc + + func Test_error_after_using_negative_id() + " This needs to run a separate Vim instance because the + " "did_use_negative_pop_id" will be set. + CheckRunVimInTerminal + + let lines =<< trim END + vim9script + + setline(1, ['one', 'two', 'three']) + prop_type_add('test_1', {highlight: 'Error'}) + prop_type_add('test_2', {highlight: 'WildMenu'}) + + prop_add(3, 1, { + type: 'test_1', + length: 5, + id: -1 + }) + + def g:AddTextprop() + prop_add(1, 0, { + type: 'test_2', + text: 'The quick fox', + text_padding_left: 2 + }) + enddef + END + call writefile(lines, 'XtextPropError', 'D') + let buf = RunVimInTerminal('-S XtextPropError', #{rows: 8, cols: 60}) + call VerifyScreenDump(buf, 'Test_prop_negative_error_1', {}) + + call term_sendkeys(buf, ":call AddTextprop()\") + call VerifyScreenDump(buf, 'Test_prop_negative_error_2', {}) + + call StopVimInTerminal(buf) + endfunc " vim: shiftwidth=2 sts=2 expandtab *** ../vim-9.0.1076/src/testdir/dumps/Test_prop_negative_error_1.dump 2022-12-19 13:30:20.239758277 +0000 --- src/testdir/dumps/Test_prop_negative_error_1.dump 2022-12-19 13:24:11.528232977 +0000 *************** *** 0 **** --- 1,8 ---- + >o+0&#ffffff0|n|e| @56 + |t|w|o| @56 + |t+0#ffffff16#ff404010|h|r|e@1| +0#0000000#ffffff0@54 + |~+0#4040ff13&| @58 + |~| @58 + |~| @58 + |~| @58 + | +0#0000000&@41|1|,|1| @10|A|l@1| *** ../vim-9.0.1076/src/testdir/dumps/Test_prop_negative_error_2.dump 2022-12-19 13:30:20.243758279 +0000 --- src/testdir/dumps/Test_prop_negative_error_2.dump 2022-12-19 13:24:12.680231189 +0000 *************** *** 0 **** --- 1,8 ---- + |~+0#4040ff13#ffffff0| @58 + |~| @58 + |~| @58 + |E+0#ffffff16#e000002|r@1|o|r| |d|e|t|e|c|t|e|d| |w|h|i|l|e| |p|r|o|c|e|s@1|i|n|g| |f|u|n|c|t|i|o|n| |A|d@1|T|e|x|t|p|r|o|p|:| +0#0000000#ffffff0@6 + |l+0#af5f00255&|i|n|e| @3|5|:| +0#0000000&@49 + |E+0#ffffff16#e000002|1|3@1|9|:| |C|a|n@1|o|t| |a|d@1| |a| |t|e|x|t|p|r|o|p| |w|i|t|h| |t|e|x|t| |a|f|t|e|r| |u|s|i|n|g| |a| |t|e|x|t|p|r|o + |p| |w|i|t|h| |a| |n|e|g|a|t|i|v|e| |i|d| +0#0000000#ffffff0@39 + |P+0#00e0003&|r|e|s@1| |E|N|T|E|R| |o|r| |t|y|p|e| |c|o|m@1|a|n|d| |t|o| |c|o|n|t|i|n|u|e> +0#0000000&@20 *** ../vim-9.0.1076/src/version.c 2022-12-19 12:18:06.404218717 +0000 --- src/version.c 2022-12-19 12:53:18.288620594 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1077, /**/ -- ARTHUR: Well, I can't just call you `Man'. DENNIS: Well, you could say `Dennis'. ARTHUR: Well, I didn't know you were called `Dennis.' DENNIS: Well, you didn't bother to find out, did you? The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///