# HG changeset patch # User Bram Moolenaar # Date 1660575606 -7200 # Node ID 7e2321707fea8364380a3e98f33e716e0faeff88 # Parent 5a91d76d181344f57218258af251ae5899fc951d patch 9.0.0214: splitting a line may duplicate virtual text Commit: https://github.com/vim/vim/commit/d8d4cfcb393123fa19640be0806091d47935407f Author: Bram Moolenaar Date: Mon Aug 15 15:55:10 2022 +0100 patch 9.0.0214: splitting a line may duplicate virtual text Problem: Splitting a line may duplicate virtual text. (Ben Jackson) Solution: Don't duplicate a text property with virtual text. Make auto-indenting work better. (closes #10919) diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_1.dump b/src/testdir/dumps/Test_prop_insert_start_incl_1.dump --- a/src/testdir/dumps/Test_prop_insert_start_incl_1.dump +++ b/src/testdir/dumps/Test_prop_insert_start_incl_1.dump @@ -1,8 +1,8 @@ |t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| >o+0#0000000&|n|e| |t|e|x|t| |b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @29 +@60 +|f|u|n|c|t|i|o|n|(|a+0&#ffd7ff255|r|g|:| |a+0&#ffffff0|r|g|)| @41 |~+0#4040ff13&| @58 |~| @58 |~| @58 |~| @58 -|~| @58 -|~| @58 | +0#0000000&@41|1|,|6|-|1|2| @7|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_2.dump b/src/testdir/dumps/Test_prop_insert_start_incl_2.dump --- a/src/testdir/dumps/Test_prop_insert_start_incl_2.dump +++ b/src/testdir/dumps/Test_prop_insert_start_incl_2.dump @@ -1,8 +1,8 @@ |t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| >o+0#0000000&|n|e| |t|e|x|t| |b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @29 +@60 +|f|u|n|c|t|i|o|n|(|a+0&#ffd7ff255|r|g|:| |a+0&#ffffff0|r|g|)| @41 |~+0#4040ff13&| @58 |~| @58 |~| @58 |~| @58 -|~| @58 -|~| @58 |-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@29|1|,|6|-|1|2| @7|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_3.dump b/src/testdir/dumps/Test_prop_insert_start_incl_3.dump --- a/src/testdir/dumps/Test_prop_insert_start_incl_3.dump +++ b/src/testdir/dumps/Test_prop_insert_start_incl_3.dump @@ -1,8 +1,8 @@ |t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| |x+0#0000000&>x|o|n|e| |t|e|x|t| |b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @27 +@60 +|f|u|n|c|t|i|o|n|(|a+0&#ffd7ff255|r|g|:| |a+0&#ffffff0|r|g|)| @41 |~+0#4040ff13&| @58 |~| @58 |~| @58 |~| @58 -|~| @58 -|~| @58 | +0#0000000&@41|1|,|7|-|1|3| @7|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_4.dump b/src/testdir/dumps/Test_prop_insert_start_incl_4.dump --- a/src/testdir/dumps/Test_prop_insert_start_incl_4.dump +++ b/src/testdir/dumps/Test_prop_insert_start_incl_4.dump @@ -1,8 +1,8 @@ |t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| |x+0#0000000&@1|o|n|e| |t|e|x|t| >b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @27 +@60 +|f|u|n|c|t|i|o|n|(|a+0&#ffd7ff255|r|g|:| |a+0&#ffffff0|r|g|)| @41 |~+0#4040ff13&| @58 |~| @58 |~| @58 |~| @58 -|~| @58 -|~| @58 |-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@29|1|,|1|7|-|2|3| @6|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_5.dump b/src/testdir/dumps/Test_prop_insert_start_incl_5.dump --- a/src/testdir/dumps/Test_prop_insert_start_incl_5.dump +++ b/src/testdir/dumps/Test_prop_insert_start_incl_5.dump @@ -1,8 +1,8 @@ |t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| |x+0#0000000&@1|o|n|e| |t|e|x|t| |y>y|b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @25 +@60 +|f|u|n|c|t|i|o|n|(|a+0&#ffd7ff255|r|g|:| |a+0&#ffffff0|r|g|)| @41 |~+0#4040ff13&| @58 |~| @58 |~| @58 |~| @58 -|~| @58 -|~| @58 | +0#0000000&@41|1|,|1|8|-|2|4| @6|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_6.dump b/src/testdir/dumps/Test_prop_insert_start_incl_6.dump new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_prop_insert_start_incl_6.dump @@ -0,0 +1,8 @@ +|t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| |x+0#0000000&@1|o|n|e| |t|e|x|t| |y@1|b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @25 +@60 +|f|u|n|c|t|i|o|n|(| @50 +@7> |a+0&#ffd7ff255|r|g|:| |a+0&#ffffff0|r|g|)| @42 +|~+0#4040ff13&| @58 +|~| @58 +|~| @58 +| +0#0000000&@41|4|,|1|-|8| @8|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_7.dump b/src/testdir/dumps/Test_prop_insert_start_incl_7.dump new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_prop_insert_start_incl_7.dump @@ -0,0 +1,8 @@ +|t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| |x+0#0000000&@1|o|n|e| |t|e|x|t| |y@1|b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @25 +@60 +|f|u|n|c|t|i|o|n|(| @50 +@12|a+0&#ffd7ff255|r|g|:| >a+0&#ffffff0|r|g|)| @38 +|~+0#4040ff13&| @58 +|~| @58 +|~| @58 +| +0#0000000&@41|4|,|6|-|1|8| @7|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_8.dump b/src/testdir/dumps/Test_prop_insert_start_incl_8.dump new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_prop_insert_start_incl_8.dump @@ -0,0 +1,8 @@ +|t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| |x+0#0000000&@1|o|n|e| |t|e|x|t| |y@1|b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @25 +@60 +|f|u|n|c|t|i|o|n|(| @50 +@4|a+0&#ffd7ff255|r|g|:| >a+0&#ffffff0|r|g|)| @46 +|~+0#4040ff13&| @58 +|~| @58 +|~| @58 +| +0#0000000&@41|4|,|5|-|1|0| @7|A|l@1| diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim --- a/src/testdir/test_textprop.vim +++ b/src/testdir/test_textprop.vim @@ -2943,13 +2943,17 @@ func Test_insert_text_start_incl() let lines =<< trim END vim9script - setline(1, 'text one text two') + setline(1, ['text one text two', '', 'function(arg)']) prop_type_add('propincl', {highlight: 'NonText', start_incl: true}) prop_add(1, 6, {type: 'propincl', text: 'after '}) cursor(1, 6) prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false}) prop_add(1, 15, {type: 'propnotincl', text: 'before '}) + + set cindent sw=4 + prop_type_add('argname', {highlight: 'DiffChange', start_incl: true}) + prop_add(3, 10, {type: 'argname', text: 'arg: '}) END call writefile(lines, 'XscriptPropsStartIncl') let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60}) @@ -2965,6 +2969,13 @@ func Test_insert_text_start_incl() call term_sendkeys(buf, "yy\") call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {}) + call term_sendkeys(buf, "3Gfai\\") + call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_6', {}) + call term_sendkeys(buf, ">>") + call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_7', {}) + call term_sendkeys(buf, "<<<<") + call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_8', {}) + call StopVimInTerminal(buf) call delete('XscriptPropsStartIncl') endfunc diff --git a/src/textprop.c b/src/textprop.c --- a/src/textprop.c +++ b/src/textprop.c @@ -1906,6 +1906,7 @@ typedef struct * Only for the current buffer. * "flags" can have: * APC_SUBSTITUTE: Text is replaced, not inserted. + * APC_INDENT: Text is inserted before virtual text prop */ static adjustres_T adjust_prop( @@ -1931,6 +1932,10 @@ adjust_prop( start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)) || (flags & APC_SUBSTITUTE) || (prop->tp_flags & TP_FLAG_CONT_PREV); + if (prop->tp_id < 0 && (flags & APC_INDENT)) + // when inserting indent just before a character with virtual text + // shift the text property + start_incl = FALSE; end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL)) || (prop->tp_flags & TP_FLAG_CONT_NEXT); // do not drop zero-width props if they later can increase in size @@ -1982,6 +1987,7 @@ adjust_prop( * "flags" can have: * APC_SAVE_FOR_UNDO: Call u_savesub() before making changes to the line. * APC_SUBSTITUTE: Text is replaced, not inserted. + * APC_INDENT: Text is inserted before virtual text prop * Caller is expected to check b_has_textprop and "bytes_added" being non-zero. * Returns TRUE when props were changed. */ @@ -2097,6 +2103,9 @@ adjust_props_for_split( cont_prev = prop.tp_col != MAXCOL && prop.tp_col + !start_incl <= kept; cont_next = prop.tp_col != MAXCOL && skipped <= prop.tp_col + prop.tp_len - !end_incl; + // when a prop has text it is never copied + if (prop.tp_id < 0 && cont_next) + cont_prev = FALSE; if (cont_prev && ga_grow(&prevprop, 1) == OK) { diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -736,6 +736,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 214, +/**/ 213, /**/ 212, diff --git a/src/vim.h b/src/vim.h --- a/src/vim.h +++ b/src/vim.h @@ -2778,6 +2778,7 @@ long elapsed(DWORD start_tick); // Flags for adjust_prop_columns() #define APC_SAVE_FOR_UNDO 1 // call u_savesub() before making changes #define APC_SUBSTITUTE 2 // text is replaced, not inserted +#define APC_INDENT 4 // changing indent #define CLIP_ZINDEX 32000