• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision966c87c579128ab22024d593384665e75b062908 (tree)
Time2022-12-19 22:45:04
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 9.0.1077: can add text property with negative ID before virtual text

Commit: https://github.com/vim/vim/commit/4ce1f99a2d58b809ab5a5c602bd031426f8527e8
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Dec 19 13:31:06 2022 +0000

patch 9.0.1077: can add text property with negative ID before virtual text
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.

Change Summary

Incremental Difference

diff -r c81f178ad433 -r 966c87c57912 src/charset.c
--- a/src/charset.c Mon Dec 19 13:30:09 2022 +0100
+++ b/src/charset.c Mon Dec 19 14:45:04 2022 +0100
@@ -1181,7 +1181,7 @@
11811181 ? col == 0
11821182 : (s[0] == NUL || s[1] == NUL)
11831183 && cts->cts_with_trailing)))
1184- && tp->tp_id - 1 < gap->ga_len)
1184+ && -tp->tp_id - 1 < gap->ga_len)
11851185 {
11861186 char_u *p = ((char_u **)gap->ga_data)[-tp->tp_id - 1];
11871187
diff -r c81f178ad433 -r 966c87c57912 src/errors.h
--- a/src/errors.h Mon Dec 19 13:30:09 2022 +0100
+++ b/src/errors.h Mon Dec 19 14:45:04 2022 +0100
@@ -3397,3 +3397,7 @@
33973397 EXTERN char e_member_not_found_on_class_str_str[]
33983398 INIT(= N_("E1338: Member not found on class \"%s\": %s"));
33993399 #endif
3400+#ifdef FEAT_PROP_POPUP
3401+EXTERN char e_cannot_add_textprop_with_text_after_using_textprop_with_negative_id[]
3402+ INIT(= N_("E1339: Cannot add a textprop with text after using a textprop with a negative id"));
3403+#endif
diff -r c81f178ad433 -r 966c87c57912 src/testdir/dumps/Test_prop_negative_error_1.dump
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testdir/dumps/Test_prop_negative_error_1.dump Mon Dec 19 14:45:04 2022 +0100
@@ -0,0 +1,8 @@
1+>o+0&#ffffff0|n|e| @56
2+|t|w|o| @56
3+|t+0#ffffff16#ff404010|h|r|e@1| +0#0000000#ffffff0@54
4+|~+0#4040ff13&| @58
5+|~| @58
6+|~| @58
7+|~| @58
8+| +0#0000000&@41|1|,|1| @10|A|l@1|
diff -r c81f178ad433 -r 966c87c57912 src/testdir/dumps/Test_prop_negative_error_2.dump
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testdir/dumps/Test_prop_negative_error_2.dump Mon Dec 19 14:45:04 2022 +0100
@@ -0,0 +1,8 @@
1+|~+0#4040ff13#ffffff0| @58
2+|~| @58
3+|~| @58
4+|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
5+|l+0#af5f00255&|i|n|e| @3|5|:| +0#0000000&@49
6+|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
7+|p| |w|i|t|h| |a| |n|e|g|a|t|i|v|e| |i|d| +0#0000000#ffffff0@39
8+|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
diff -r c81f178ad433 -r 966c87c57912 src/testdir/test_textprop.vim
--- a/src/testdir/test_textprop.vim Mon Dec 19 13:30:09 2022 +0100
+++ b/src/testdir/test_textprop.vim Mon Dec 19 14:45:04 2022 +0100
@@ -3725,6 +3725,50 @@
37253725
37263726 call StopVimInTerminal(buf)
37273727 endfunc
3728+
3729+func Test_error_when_using_negative_id()
3730+ call prop_type_add('test1', #{highlight: 'ErrorMsg'})
3731+ call prop_add(1, 1, #{type: 'test1', text: 'virtual'})
3732+ call assert_fails("call prop_add(1, 1, #{type: 'test1', length: 1, id: -1})", 'E1293:')
3733+
3734+ call prop_type_delete('test1')
3735+endfunc
3736+
3737+func Test_error_after_using_negative_id()
3738+ " This needs to run a separate Vim instance because the
3739+ " "did_use_negative_pop_id" will be set.
3740+ CheckRunVimInTerminal
3741+
3742+ let lines =<< trim END
3743+ vim9script
3744+
3745+ setline(1, ['one', 'two', 'three'])
3746+ prop_type_add('test_1', {highlight: 'Error'})
3747+ prop_type_add('test_2', {highlight: 'WildMenu'})
3748+
3749+ prop_add(3, 1, {
3750+ type: 'test_1',
3751+ length: 5,
3752+ id: -1
3753+ })
3754+
3755+ def g:AddTextprop()
3756+ prop_add(1, 0, {
3757+ type: 'test_2',
3758+ text: 'The quick fox',
3759+ text_padding_left: 2
3760+ })
3761+ enddef
3762+ END
3763+ call writefile(lines, 'XtextPropError', 'D')
3764+ let buf = RunVimInTerminal('-S XtextPropError', #{rows: 8, cols: 60})
3765+ call VerifyScreenDump(buf, 'Test_prop_negative_error_1', {})
3766+
3767+ call term_sendkeys(buf, ":call AddTextprop()\<CR>")
3768+ call VerifyScreenDump(buf, 'Test_prop_negative_error_2', {})
3769+
3770+ call StopVimInTerminal(buf)
3771+endfunc
37283772
37293773
37303774 " vim: shiftwidth=2 sts=2 expandtab
diff -r c81f178ad433 -r 966c87c57912 src/textprop.c
--- a/src/textprop.c Mon Dec 19 13:30:09 2022 +0100
+++ b/src/textprop.c Mon Dec 19 14:45:04 2022 +0100
@@ -424,6 +424,10 @@
424424 return -(buf->b_textprop_text.ga_len + 1);
425425 }
426426
427+// Flag that is set when a negative ID isused for a normal text property.
428+// It is then impossible to use virtual text properties.
429+static int did_use_negative_pop_id = FALSE;
430+
427431 /*
428432 * Shared between prop_add() and popup_create().
429433 * "dict_arg" is the function argument of a dict containing "bufnr".
@@ -576,13 +580,25 @@
576580 if (dict_arg != NULL && get_bufnr_from_arg(dict_arg, &buf) == FAIL)
577581 goto theend;
578582
579- if (id < 0 && buf->b_textprop_text.ga_len > 0)
583+ if (id < 0)
580584 {
581- emsg(_(e_cannot_use_negative_id_after_adding_textprop_with_text));
582- goto theend;
585+ if (buf->b_textprop_text.ga_len > 0)
586+ {
587+ emsg(_(e_cannot_use_negative_id_after_adding_textprop_with_text));
588+ goto theend;
589+ }
590+ did_use_negative_pop_id = TRUE;
583591 }
592+
584593 if (text != NULL)
594+ {
595+ if (did_use_negative_pop_id)
596+ {
597+ emsg(_(e_cannot_add_textprop_with_text_after_using_textprop_with_negative_id));
598+ goto theend;
599+ }
585600 id = get_textprop_id(buf);
601+ }
586602
587603 // This must be done _before_ we add the property because property changes
588604 // trigger buffer (memline) reorganisation, which needs this flag to be
diff -r c81f178ad433 -r 966c87c57912 src/version.c
--- a/src/version.c Mon Dec 19 13:30:09 2022 +0100
+++ b/src/version.c Mon Dec 19 14:45:04 2022 +0100
@@ -696,6 +696,8 @@
696696 static int included_patches[] =
697697 { /* Add new patch number below this line */
698698 /**/
699+ 1077,
700+/**/
699701 1076,
700702 /**/
701703 1075,
Show on old repository browser