1
0
forked from aniani/vim

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)
This commit is contained in:
Bram Moolenaar
2022-08-15 15:55:10 +01:00
parent 249e1b903a
commit d8d4cfcb39
12 changed files with 58 additions and 11 deletions

View File

@@ -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 |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 |~+0#4040ff13&| @58
|~| @58 |~| @58
|~| @58 |~| @58
|~| @58 |~| @58
|~| @58
|~| @58
| +0#0000000&@41|1|,|6|-|1|2| @7|A|l@1| | +0#0000000&@41|1|,|6|-|1|2| @7|A|l@1|

View File

@@ -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 |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 |~+0#4040ff13&| @58
|~| @58 |~| @58
|~| @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| |-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@29|1|,|6|-|1|2| @7|A|l@1|

View File

@@ -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 |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 |~+0#4040ff13&| @58
|~| @58 |~| @58
|~| @58 |~| @58
|~| @58 |~| @58
|~| @58
|~| @58
| +0#0000000&@41|1|,|7|-|1|3| @7|A|l@1| | +0#0000000&@41|1|,|7|-|1|3| @7|A|l@1|

View File

@@ -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 |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 |~+0#4040ff13&| @58
|~| @58 |~| @58
|~| @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| |-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@29|1|,|1|7|-|2|3| @6|A|l@1|

View File

@@ -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 |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 |~+0#4040ff13&| @58
|~| @58 |~| @58
|~| @58 |~| @58
|~| @58 |~| @58
|~| @58
|~| @58
| +0#0000000&@41|1|,|1|8|-|2|4| @6|A|l@1| | +0#0000000&@41|1|,|1|8|-|2|4| @6|A|l@1|

View File

@@ -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|

View File

@@ -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|

View File

@@ -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|

View File

@@ -2943,13 +2943,17 @@ func Test_insert_text_start_incl()
let lines =<< trim END let lines =<< trim END
vim9script 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_type_add('propincl', {highlight: 'NonText', start_incl: true})
prop_add(1, 6, {type: 'propincl', text: 'after '}) prop_add(1, 6, {type: 'propincl', text: 'after '})
cursor(1, 6) cursor(1, 6)
prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false}) prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false})
prop_add(1, 15, {type: 'propnotincl', text: 'before '}) 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 END
call writefile(lines, 'XscriptPropsStartIncl') call writefile(lines, 'XscriptPropsStartIncl')
let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60}) let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60})
@@ -2965,6 +2969,13 @@ func Test_insert_text_start_incl()
call term_sendkeys(buf, "yy\<Esc>") call term_sendkeys(buf, "yy\<Esc>")
call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {}) call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {})
call term_sendkeys(buf, "3Gfai\<CR>\<Esc>")
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 StopVimInTerminal(buf)
call delete('XscriptPropsStartIncl') call delete('XscriptPropsStartIncl')
endfunc endfunc

View File

@@ -1906,6 +1906,7 @@ typedef struct
* Only for the current buffer. * Only for the current buffer.
* "flags" can have: * "flags" can have:
* APC_SUBSTITUTE: Text is replaced, not inserted. * APC_SUBSTITUTE: Text is replaced, not inserted.
* APC_INDENT: Text is inserted before virtual text prop
*/ */
static adjustres_T static adjustres_T
adjust_prop( adjust_prop(
@@ -1931,6 +1932,10 @@ adjust_prop(
start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)) start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL))
|| (flags & APC_SUBSTITUTE) || (flags & APC_SUBSTITUTE)
|| (prop->tp_flags & TP_FLAG_CONT_PREV); || (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)) end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL))
|| (prop->tp_flags & TP_FLAG_CONT_NEXT); || (prop->tp_flags & TP_FLAG_CONT_NEXT);
// do not drop zero-width props if they later can increase in size // do not drop zero-width props if they later can increase in size
@@ -1982,6 +1987,7 @@ adjust_prop(
* "flags" can have: * "flags" can have:
* APC_SAVE_FOR_UNDO: Call u_savesub() before making changes to the line. * APC_SAVE_FOR_UNDO: Call u_savesub() before making changes to the line.
* APC_SUBSTITUTE: Text is replaced, not inserted. * 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. * Caller is expected to check b_has_textprop and "bytes_added" being non-zero.
* Returns TRUE when props were changed. * 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_prev = prop.tp_col != MAXCOL && prop.tp_col + !start_incl <= kept;
cont_next = prop.tp_col != MAXCOL cont_next = prop.tp_col != MAXCOL
&& skipped <= prop.tp_col + prop.tp_len - !end_incl; && 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) if (cont_prev && ga_grow(&prevprop, 1) == OK)
{ {

View File

@@ -735,6 +735,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
214,
/**/ /**/
213, 213,
/**/ /**/

View File

@@ -2778,6 +2778,7 @@ long elapsed(DWORD start_tick);
// Flags for adjust_prop_columns() // Flags for adjust_prop_columns()
#define APC_SAVE_FOR_UNDO 1 // call u_savesub() before making changes #define APC_SAVE_FOR_UNDO 1 // call u_savesub() before making changes
#define APC_SUBSTITUTE 2 // text is replaced, not inserted #define APC_SUBSTITUTE 2 // text is replaced, not inserted
#define APC_INDENT 4 // changing indent
#define CLIP_ZINDEX 32000 #define CLIP_ZINDEX 32000