Mirror of the Vim source from https://github.com/vim/vim
Revision | 966c87c579128ab22024d593384665e75b062908 (tree) |
---|---|
Time | 2022-12-19 22:45:04 |
Author | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
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
@@ -1181,7 +1181,7 @@ | ||
1181 | 1181 | ? col == 0 |
1182 | 1182 | : (s[0] == NUL || s[1] == NUL) |
1183 | 1183 | && cts->cts_with_trailing))) |
1184 | - && tp->tp_id - 1 < gap->ga_len) | |
1184 | + && -tp->tp_id - 1 < gap->ga_len) | |
1185 | 1185 | { |
1186 | 1186 | char_u *p = ((char_u **)gap->ga_data)[-tp->tp_id - 1]; |
1187 | 1187 |
@@ -3397,3 +3397,7 @@ | ||
3397 | 3397 | EXTERN char e_member_not_found_on_class_str_str[] |
3398 | 3398 | INIT(= N_("E1338: Member not found on class \"%s\": %s")); |
3399 | 3399 | #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 |
@@ -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| |
@@ -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 |
@@ -3725,6 +3725,50 @@ | ||
3725 | 3725 | |
3726 | 3726 | call StopVimInTerminal(buf) |
3727 | 3727 | 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 | |
3728 | 3772 | |
3729 | 3773 | |
3730 | 3774 | " vim: shiftwidth=2 sts=2 expandtab |
@@ -424,6 +424,10 @@ | ||
424 | 424 | return -(buf->b_textprop_text.ga_len + 1); |
425 | 425 | } |
426 | 426 | |
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 | + | |
427 | 431 | /* |
428 | 432 | * Shared between prop_add() and popup_create(). |
429 | 433 | * "dict_arg" is the function argument of a dict containing "bufnr". |
@@ -576,13 +580,25 @@ | ||
576 | 580 | if (dict_arg != NULL && get_bufnr_from_arg(dict_arg, &buf) == FAIL) |
577 | 581 | goto theend; |
578 | 582 | |
579 | - if (id < 0 && buf->b_textprop_text.ga_len > 0) | |
583 | + if (id < 0) | |
580 | 584 | { |
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; | |
583 | 591 | } |
592 | + | |
584 | 593 | 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 | + } | |
585 | 600 | id = get_textprop_id(buf); |
601 | + } | |
586 | 602 | |
587 | 603 | // This must be done _before_ we add the property because property changes |
588 | 604 | // trigger buffer (memline) reorganisation, which needs this flag to be |
@@ -696,6 +696,8 @@ | ||
696 | 696 | static int included_patches[] = |
697 | 697 | { /* Add new patch number below this line */ |
698 | 698 | /**/ |
699 | + 1077, | |
700 | +/**/ | |
699 | 701 | 1076, |
700 | 702 | /**/ |
701 | 703 | 1075, |