]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0214: splitting a line may duplicate virtual text v9.0.0214
authorBram Moolenaar <Bram@vim.org>
Mon, 15 Aug 2022 14:55:10 +0000 (15:55 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 15 Aug 2022 14:55:10 +0000 (15:55 +0100)
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)

12 files changed:
src/testdir/dumps/Test_prop_insert_start_incl_1.dump
src/testdir/dumps/Test_prop_insert_start_incl_2.dump
src/testdir/dumps/Test_prop_insert_start_incl_3.dump
src/testdir/dumps/Test_prop_insert_start_incl_4.dump
src/testdir/dumps/Test_prop_insert_start_incl_5.dump
src/testdir/dumps/Test_prop_insert_start_incl_6.dump [new file with mode: 0644]
src/testdir/dumps/Test_prop_insert_start_incl_7.dump [new file with mode: 0644]
src/testdir/dumps/Test_prop_insert_start_incl_8.dump [new file with mode: 0644]
src/testdir/test_textprop.vim
src/textprop.c
src/version.c
src/vim.h

index deb67d50be94ef859a61e23e2b99e2d53db8c8ec..de1f3d479751767a8adaaf2c26e60f2561f38023 100644 (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
+@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| 
index 73cf64881d16fd715871ce7a4884900f7e326e63..f0c9ac076815568f8e8e8121f7700a8c9661c8fd 100644 (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
+@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| 
index cc4de01c7584010c82cac932a0a863165dc71473..5a8578b49be5b80e0ed186f605f2ddb2cd19c43c 100644 (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
+@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| 
index 75e2580238395250fd240ec7fb17626d30b384be..bf67a1e08c129b32d9e9b418b5522f8bc8170efe 100644 (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
+@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| 
index 5cbee12e318ea3dfe37e763910bdc2e49de9d0c1..270c8a085ce6dd304bd8f333fa27eb86adfd977d 100644 (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
+@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 (file)
index 0000000..96156a8
--- /dev/null
@@ -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 (file)
index 0000000..43545a8
--- /dev/null
@@ -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 (file)
index 0000000..9d46839
--- /dev/null
@@ -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| 
index c3802103cdb2fb43e75e443a4017ff0d36f932f9..496e73836ef11cedd79ea91672820cb79e8d803f 100644 (file)
@@ -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\<Esc>")
   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 delete('XscriptPropsStartIncl')
 endfunc
index 1df4840f207e2ae07b49608c1de46bed7bce6bfd..d90d57fac36a95d487291cf395eed3e209e9d0cc 100644 (file)
@@ -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)
        {
index ec63c24b06f8b3e477f5bf6f1e5cdf8c3f908b47..e8b4c9f02760fee006d5a33d51a81108ab6a8b8a 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    214,
 /**/
     213,
 /**/
index 6db48185c961c1ad3600237235520b9cee9bb7fd..9445fa2da94173867da3848cf05caa263288ef4e 100644 (file)
--- 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