Patch 9.0.0205
Problem:    Cursor in wrong position when inserting after virtual text. (Ben
            Jackson)
Solution:   Put the cursor after the virtual text, where the text will be
            inserted. (closes #10914)
Files:      src/charset.c, src/structs.h, src/textprop.c,
            src/testdir/test_textprop.vim,
            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


*** ../vim-9.0.0204/src/charset.c       2022-08-13 16:40:51.732717696 +0100
--- src/charset.c       2022-08-14 13:09:25.478969378 +0100
***************
*** 1212,1217 ****
--- 1212,1218 ----
  #endif
                    }
                    cts->cts_cur_text_width += cells;
+                   cts->cts_start_incl = tp->tp_flags & TP_FLAG_START_INCL;
                    size += cells;
                    if (*s == TAB)
                    {
***************
*** 1585,1591 ****
        else
        {
  #ifdef FEAT_PROP_POPUP
!           if ((State & MODE_INSERT) == 0 && !on_NUL)
                // cursor is after inserted text, unless on the NUL
                vcol += cts.cts_cur_text_width;
  #endif
--- 1586,1594 ----
        else
        {
  #ifdef FEAT_PROP_POPUP
!           // in Insert mode, if "start_incl" is true the text gets inserted
!           // after the virtual text, thus add its width
!           if (((State & MODE_INSERT) == 0 || cts.cts_start_incl) && !on_NUL)
                // cursor is after inserted text, unless on the NUL
                vcol += cts.cts_cur_text_width;
  #endif
*** ../vim-9.0.0204/src/structs.h       2022-08-07 18:20:03.212214747 +0100
--- src/structs.h       2022-08-14 13:08:10.527385858 +0100
***************
*** 815,820 ****
--- 815,822 ----
  
  #define TP_FLAG_WRAP          0x40    // virtual text wraps - when missing
                                        // text is truncated
+ #define TP_FLAG_START_INCL    0x80    // "start_incl" copied from proptype
+ 
  #define PROP_TEXT_MIN_CELLS   4       // minimun number of cells to use for
                                        // the text, even when truncating
  
***************
*** 4587,4592 ****
--- 4589,4595 ----
      int         cts_cur_text_width;     // width of current inserted text
      int               cts_with_trailing;      // include size of trailing 
props with
                                        // last character
+     int               cts_start_incl;         // prop has true "start_incl" 
arg
  #endif
      int               cts_vcol;           // virtual column at current 
position
  } chartabsize_T;
*** ../vim-9.0.0204/src/textprop.c      2022-08-13 19:34:46.359984058 +0100
--- src/textprop.c      2022-08-14 13:07:11.151746119 +0100
***************
*** 294,300 ****
        tmp_prop.tp_type = type->pt_id;
        tmp_prop.tp_flags = text_flags
                            | (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0)
!                           | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0);
        mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop,
                                                           sizeof(textprop_T));
  
--- 294,302 ----
        tmp_prop.tp_type = type->pt_id;
        tmp_prop.tp_flags = text_flags
                            | (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0)
!                           | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0)
!                           | ((type->pt_flags & PT_FLAG_INS_START_INCL)
!                                                    ? TP_FLAG_START_INCL : 0);
        mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop,
                                                           sizeof(textprop_T));
  
*** ../vim-9.0.0204/src/testdir/test_textprop.vim       2022-08-13 
20:17:31.250884273 +0100
--- src/testdir/test_textprop.vim       2022-08-14 13:23:04.396024211 +0100
***************
*** 2914,2917 ****
--- 2914,2948 ----
    bwipe!
  enddef
  
+ func Test_insert_text_start_incl()
+   CheckRunVimInTerminal
+ 
+   let lines =<< trim END
+       vim9script
+       setline(1, 'text one text two')
+ 
+       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 '})
+   END
+   call writefile(lines, 'XscriptPropsStartIncl')
+   let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60})
+   call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_1', {})
+ 
+   call term_sendkeys(buf, "i")
+   call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_2', {})
+   call term_sendkeys(buf, "xx\<Esc>")
+   call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_3', {})
+ 
+   call term_sendkeys(buf, "2wi")
+   call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_4', {})
+   call term_sendkeys(buf, "yy\<Esc>")
+   call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {})
+ 
+   call StopVimInTerminal(buf)
+   call delete('XscriptPropsStartIncl')
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.0204/src/testdir/dumps/Test_prop_insert_start_incl_1.dump        
2022-08-14 13:28:12.323279031 +0100
--- src/testdir/dumps/Test_prop_insert_start_incl_1.dump        2022-08-14 
13:23:07.284016736 +0100
***************
*** 0 ****
--- 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
+ |~+0#4040ff13&| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ | +0#0000000&@41|1|,|6|-|1|2| @7|A|l@1| 
*** ../vim-9.0.0204/src/testdir/dumps/Test_prop_insert_start_incl_2.dump        
2022-08-14 13:28:12.331279012 +0100
--- src/testdir/dumps/Test_prop_insert_start_incl_2.dump        2022-08-14 
13:23:08.432013769 +0100
***************
*** 0 ****
--- 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
+ |~+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| 
*** ../vim-9.0.0204/src/testdir/dumps/Test_prop_insert_start_incl_3.dump        
2022-08-14 13:28:12.335279003 +0100
--- src/testdir/dumps/Test_prop_insert_start_incl_3.dump        2022-08-14 
13:23:09.584010791 +0100
***************
*** 0 ****
--- 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
+ |~+0#4040ff13&| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ | +0#0000000&@41|1|,|7|-|1|3| @7|A|l@1| 
*** ../vim-9.0.0204/src/testdir/dumps/Test_prop_insert_start_incl_4.dump        
2022-08-14 13:28:12.339278994 +0100
--- src/testdir/dumps/Test_prop_insert_start_incl_4.dump        2022-08-14 
13:23:10.736007817 +0100
***************
*** 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| 
>b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @27
+ |~+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| 
*** ../vim-9.0.0204/src/testdir/dumps/Test_prop_insert_start_incl_5.dump        
2022-08-14 13:28:12.343278985 +0100
--- src/testdir/dumps/Test_prop_insert_start_incl_5.dump        2022-08-14 
13:23:11.888004843 +0100
***************
*** 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>y|b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @25
+ |~+0#4040ff13&| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ | +0#0000000&@41|1|,|1|8|-|2|4| @6|A|l@1| 
*** ../vim-9.0.0204/src/version.c       2022-08-14 12:07:06.918862666 +0100
--- src/version.c       2022-08-14 13:25:26.075669519 +0100
***************
*** 737,738 ****
--- 737,740 ----
  {   /* Add new patch number below this line */
+ /**/
+     205,
  /**/

-- 
   LAUNCELOT leaps into SHOT with a mighty cry and runs the GUARD through and
   hacks him to the floor.  Blood.  Swashbuckling music (perhaps).
   LAUNCELOT races through into the castle screaming.
SECOND SENTRY: Hey!
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220814123027.B3FFB1C04B1%40moolenaar.net.

Raspunde prin e-mail lui