Patch 8.2.0115
Problem:    Byte2line() does not work correctly with text properties. (Billie
            Cleek)
Solution:   Take the bytes of the text properties into account.
            (closes #5334)
Files:      src/testdir/test_textprop.vim, src/memline.c


*** ../vim-8.2.0114/src/testdir/test_textprop.vim       2020-01-10 
19:56:42.774995632 +0100
--- src/testdir/test_textprop.vim       2020-01-13 19:42:34.666294453 +0100
***************
*** 664,670 ****
    call prop_type_delete('comment')
  endfunc
  
! func Test_prop_byteoff()
    call prop_type_add('comment', {'highlight': 'Directory'})
    new
    call setline(1, ['line1', 'second line', ''])
--- 664,670 ----
    call prop_type_delete('comment')
  endfunc
  
! func Test_prop_line2byte()
    call prop_type_add('comment', {'highlight': 'Directory'})
    new
    call setline(1, ['line1', 'second line', ''])
***************
*** 677,682 ****
--- 677,698 ----
    call prop_type_delete('comment')
  endfunc
  
+ func Test_prop_byte2line()
+   new
+   set ff=unix
+   call setline(1, ['one one', 'two two', 'three three', 'four four', 'five'])
+   call assert_equal(4, byte2line(line2byte(4)))
+   call assert_equal(5, byte2line(line2byte(5)))
+ 
+   call prop_type_add('prop', {'highlight': 'Directory'})
+   call prop_add(3, 1, {'length': 5, 'type': 'prop'})
+   call assert_equal(4, byte2line(line2byte(4)))
+   call assert_equal(5, byte2line(line2byte(5)))
+ 
+   bwipe!
+   call prop_type_delete('prop')
+ endfunc
+ 
  func Test_prop_undo()
    new
    call prop_type_add('comment', {'highlight': 'Directory'})
*** ../vim-8.2.0114/src/memline.c       2019-12-04 21:54:42.000000000 +0100
--- src/memline.c       2020-01-13 20:35:23.688039980 +0100
***************
*** 5738,5744 ****
        count = (long)(buf->b_ml.ml_locked_high) -
                (long)(buf->b_ml.ml_locked_low) + 1;
        start_idx = idx = curline - buf->b_ml.ml_locked_low;
!       if (idx == 0)// first line in block, text at the end
            text_end = dp->db_txt_end;
        else
            text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
--- 5738,5744 ----
        count = (long)(buf->b_ml.ml_locked_high) -
                (long)(buf->b_ml.ml_locked_low) + 1;
        start_idx = idx = curline - buf->b_ml.ml_locked_low;
!       if (idx == 0)  // first line in block, text at the end
            text_end = dp->db_txt_end;
        else
            text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
***************
*** 5752,5764 ****
        }
        else
        {
            extra = 0;
!           while (offset >= size
!                      + text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK)
!                                                                     + ffdos)
            {
                if (ffdos)
                    size++;
                if (idx == count - 1)
                {
                    extra = 1;
--- 5752,5789 ----
        }
        else
        {
+ #ifdef FEAT_PROP_POPUP
+           long textprop_total = 0;
+           long textprop_size = 0;
+           char_u *l1, *l2;
+ #endif
+ 
            extra = 0;
!           for (;;)
            {
+ #ifdef FEAT_PROP_POPUP
+               if (buf->b_has_textprop)
+               {
+                   // compensate for the extra bytes taken by textprops
+                   l1 = (char_u *)dp + ((dp->db_index[idx]) & DB_INDEX_MASK);
+                   l2 = (char_u *)dp + (idx == 0 ? dp->db_txt_end
+                                 : ((dp->db_index[idx - 1]) & DB_INDEX_MASK));
+                   textprop_size = (l2 - l1) - (STRLEN(l1) + 1);
+               }
+ #endif
+               if (!(offset >= size
+                       + text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK)
+ #ifdef FEAT_PROP_POPUP
+                       - textprop_total - textprop_size
+ #endif
+                       + ffdos))
+                   break;
+ 
                if (ffdos)
                    size++;
+ #ifdef FEAT_PROP_POPUP
+               textprop_total += textprop_size;
+ #endif
                if (idx == count - 1)
                {
                    extra = 1;
***************
*** 5776,5782 ****
            // lengths.
            len = 0;
            for (i = start_idx; i <= idx; ++i)
!               len += (int)STRLEN((char_u *)dp + ((dp->db_index[i]) & 
DB_INDEX_MASK)) + 1;
        }
        else
  #endif
--- 5801,5808 ----
            // lengths.
            len = 0;
            for (i = start_idx; i <= idx; ++i)
!               len += (int)STRLEN((char_u *)dp
!                                   + ((dp->db_index[i]) & DB_INDEX_MASK)) + 1;
        }
        else
  #endif
*** ../vim-8.2.0114/src/version.c       2020-01-12 17:42:52.410413873 +0100
--- src/version.c       2020-01-13 19:37:33.775552307 +0100
***************
*** 744,745 ****
--- 744,747 ----
  {   /* Add new patch number below this line */
+ /**/
+     115,
  /**/

-- 
JOHN CLEESE PLAYED: SECOND SOLDIER WITH A KEEN INTEREST IN BIRDS, LARGE MAN
                    WITH DEAD BODY, BLACK KNIGHT, MR NEWT (A VILLAGE
                    BLACKSMITH INTERESTED IN BURNING WITCHES), A QUITE
                    EXTRAORDINARILY RUDE FRENCHMAN, TIM THE WIZARD, SIR
                    LAUNCELOT
                 "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/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202001131941.00DJfLLC023059%40masaka.moolenaar.net.

Raspunde prin e-mail lui