• R/O
  • SSH

vim: 提交

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

修订版e40814841406ac55c973bf7e3384634d5821b474 (tree)
时间2020-01-14 04:45:03
作者Bram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.0115: byte2line() does not work correctly with text properties

Commit: https://github.com/vim/vim/commit/9df53b62de86f544b41bef5e964b7fc8ae5231e3
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 13 20:40:51 2020 +0100

patch 8.2.0115: byte2line() does not work correctly with text properties
Problem: Byte2line() does not work correctly with text properties. (Billie
Cleek)
Solution: Take the bytes of the text properties into account.
(closes #5334)

更改概述

差异

diff -r a25bb65cb6d8 -r e40814841406 src/memline.c
--- a/src/memline.c Sun Jan 12 17:45:04 2020 +0100
+++ b/src/memline.c Mon Jan 13 20:45:03 2020 +0100
@@ -5738,7 +5738,7 @@
57385738 count = (long)(buf->b_ml.ml_locked_high) -
57395739 (long)(buf->b_ml.ml_locked_low) + 1;
57405740 start_idx = idx = curline - buf->b_ml.ml_locked_low;
5741- if (idx == 0)// first line in block, text at the end
5741+ if (idx == 0) // first line in block, text at the end
57425742 text_end = dp->db_txt_end;
57435743 else
57445744 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
@@ -5752,13 +5752,38 @@
57525752 }
57535753 else
57545754 {
5755+#ifdef FEAT_PROP_POPUP
5756+ long textprop_total = 0;
5757+ long textprop_size = 0;
5758+ char_u *l1, *l2;
5759+#endif
5760+
57555761 extra = 0;
5756- while (offset >= size
5757- + text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK)
5758- + ffdos)
5762+ for (;;)
57595763 {
5764+#ifdef FEAT_PROP_POPUP
5765+ if (buf->b_has_textprop)
5766+ {
5767+ // compensate for the extra bytes taken by textprops
5768+ l1 = (char_u *)dp + ((dp->db_index[idx]) & DB_INDEX_MASK);
5769+ l2 = (char_u *)dp + (idx == 0 ? dp->db_txt_end
5770+ : ((dp->db_index[idx - 1]) & DB_INDEX_MASK));
5771+ textprop_size = (l2 - l1) - (STRLEN(l1) + 1);
5772+ }
5773+#endif
5774+ if (!(offset >= size
5775+ + text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK)
5776+#ifdef FEAT_PROP_POPUP
5777+ - textprop_total - textprop_size
5778+#endif
5779+ + ffdos))
5780+ break;
5781+
57605782 if (ffdos)
57615783 size++;
5784+#ifdef FEAT_PROP_POPUP
5785+ textprop_total += textprop_size;
5786+#endif
57625787 if (idx == count - 1)
57635788 {
57645789 extra = 1;
@@ -5776,7 +5801,8 @@
57765801 // lengths.
57775802 len = 0;
57785803 for (i = start_idx; i <= idx; ++i)
5779- len += (int)STRLEN((char_u *)dp + ((dp->db_index[i]) & DB_INDEX_MASK)) + 1;
5804+ len += (int)STRLEN((char_u *)dp
5805+ + ((dp->db_index[i]) & DB_INDEX_MASK)) + 1;
57805806 }
57815807 else
57825808 #endif
diff -r a25bb65cb6d8 -r e40814841406 src/testdir/test_textprop.vim
--- a/src/testdir/test_textprop.vim Sun Jan 12 17:45:04 2020 +0100
+++ b/src/testdir/test_textprop.vim Mon Jan 13 20:45:03 2020 +0100
@@ -664,7 +664,7 @@
664664 call prop_type_delete('comment')
665665 endfunc
666666
667-func Test_prop_byteoff()
667+func Test_prop_line2byte()
668668 call prop_type_add('comment', {'highlight': 'Directory'})
669669 new
670670 call setline(1, ['line1', 'second line', ''])
@@ -677,6 +677,22 @@
677677 call prop_type_delete('comment')
678678 endfunc
679679
680+func Test_prop_byte2line()
681+ new
682+ set ff=unix
683+ call setline(1, ['one one', 'two two', 'three three', 'four four', 'five'])
684+ call assert_equal(4, byte2line(line2byte(4)))
685+ call assert_equal(5, byte2line(line2byte(5)))
686+
687+ call prop_type_add('prop', {'highlight': 'Directory'})
688+ call prop_add(3, 1, {'length': 5, 'type': 'prop'})
689+ call assert_equal(4, byte2line(line2byte(4)))
690+ call assert_equal(5, byte2line(line2byte(5)))
691+
692+ bwipe!
693+ call prop_type_delete('prop')
694+endfunc
695+
680696 func Test_prop_undo()
681697 new
682698 call prop_type_add('comment', {'highlight': 'Directory'})
diff -r a25bb65cb6d8 -r e40814841406 src/version.c
--- a/src/version.c Sun Jan 12 17:45:04 2020 +0100
+++ b/src/version.c Mon Jan 13 20:45:03 2020 +0100
@@ -743,6 +743,8 @@
743743 static int included_patches[] =
744744 { /* Add new patch number below this line */
745745 /**/
746+ 115,
747+/**/
746748 114,
747749 /**/
748750 113,
Show on old repository browser