summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0678
blob: 97ea5d0fd8653b1e6f0927e5f08a8b38de83929e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0678
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.0678
Problem:    Text properties as not adjusted for inserted text.
Solution:   Adjust text properties when inserting text.
Files:	    src/misc1.c, src/proto/misc1.pro, src/textprop.c,
            src/testdir/test_textprop.vim,
            src/testdir/dumps/Test_textprop_01.dump


*** ../vim-8.1.0677/src/misc1.c	2018-12-31 23:58:20.246887218 +0100
--- src/misc1.c	2019-01-01 23:58:07.685325391 +0100
***************
*** 2322,2328 ****
  	for (i = 0; i < len; i += n)
  	{
  	    if (enc_utf8)
! 		/* avoid reading past p[len] */
  		n = utfc_ptr2len_len(p + i, len - i);
  	    else
  		n = (*mb_ptr2len)(p + i);
--- 2322,2328 ----
  	for (i = 0; i < len; i += n)
  	{
  	    if (enc_utf8)
! 		// avoid reading past p[len]
  		n = utfc_ptr2len_len(p + i, len - i);
  	    else
  		n = (*mb_ptr2len)(p + i);
***************
*** 2365,2376 ****
  ins_char_bytes(char_u *buf, int charlen)
  {
      int		c = buf[0];
!     int		newlen;		/* nr of bytes inserted */
!     int		oldlen;		/* nr of bytes deleted (0 when not replacing) */
      char_u	*p;
      char_u	*newp;
      char_u	*oldp;
!     int		linelen;	/* length of old line including NUL */
      colnr_T	col;
      linenr_T	lnum = curwin->w_cursor.lnum;
      int		i;
--- 2365,2376 ----
  ins_char_bytes(char_u *buf, int charlen)
  {
      int		c = buf[0];
!     int		newlen;		// nr of bytes inserted
!     int		oldlen;		// nr of bytes deleted (0 when not replacing)
      char_u	*p;
      char_u	*newp;
      char_u	*oldp;
!     int		linelen;	// length of old line including NUL
      colnr_T	col;
      linenr_T	lnum = curwin->w_cursor.lnum;
      int		i;
***************
*** 2439,2446 ****
  	    }
  	    curwin->w_p_list = old_list;
  	}
! 	else
! 	    if (oldp[col] != NUL)
  	{
  	    /* normal replace */
  #ifdef FEAT_MBYTE
--- 2439,2445 ----
  	    }
  	    curwin->w_p_list = old_list;
  	}
! 	else if (oldp[col] != NUL)
  	{
  	    /* normal replace */
  #ifdef FEAT_MBYTE
***************
*** 2494,2504 ****
      while (i < newlen)
  	p[i++] = ' ';
  
!     /* Replace the line in the buffer. */
      ml_replace(lnum, newp, FALSE);
  
!     /* mark the buffer as changed and prepare for displaying */
!     changed_bytes(lnum, col);
  
      /*
       * If we're in Insert or Replace mode and 'showmatch' is set, then briefly
--- 2493,2503 ----
      while (i < newlen)
  	p[i++] = ' ';
  
!     // Replace the line in the buffer.
      ml_replace(lnum, newp, FALSE);
  
!     // mark the buffer as changed and prepare for displaying
!     inserted_bytes(lnum, col, newlen - oldlen);
  
      /*
       * If we're in Insert or Replace mode and 'showmatch' is set, then briefly
***************
*** 2566,2572 ****
      mch_memmove(newp + col, s, (size_t)newlen);
      mch_memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1));
      ml_replace(lnum, newp, FALSE);
!     changed_bytes(lnum, col);
      curwin->w_cursor.col += newlen;
  }
  
--- 2565,2571 ----
      mch_memmove(newp + col, s, (size_t)newlen);
      mch_memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1));
      ml_replace(lnum, newp, FALSE);
!     inserted_bytes(lnum, col, newlen);
      curwin->w_cursor.col += newlen;
  }
  
***************
*** 3016,3021 ****
--- 3015,3035 ----
  #endif
  }
  
+ /*
+  * Like changed_bytes() but also adjust text properties for "added" bytes.
+  * When "added" is negative text was deleted.
+  */
+     void
+ inserted_bytes(linenr_T lnum, colnr_T col, int added)
+ {
+     changed_bytes(lnum, col);
+ 
+ #ifdef FEAT_TEXT_PROP
+     if (curbuf->b_has_textprop && added != 0)
+ 	adjust_prop_columns(lnum, col, added);
+ #endif
+ }
+ 
      static void
  changedOneline(buf_T *buf, linenr_T lnum)
  {
*** ../vim-8.1.0677/src/proto/misc1.pro	2018-06-23 19:22:45.614486258 +0200
--- src/proto/misc1.pro	2019-01-01 23:01:52.739596275 +0100
***************
*** 35,40 ****
--- 35,41 ----
  void changed(void);
  void changed_int(void);
  void changed_bytes(linenr_T lnum, colnr_T col);
+ void inserted_bytes(linenr_T lnum, colnr_T col, int added);
  void appended_lines(linenr_T lnum, long count);
  void appended_lines_mark(linenr_T lnum, long count);
  void deleted_lines(linenr_T lnum, long count);
*** ../vim-8.1.0677/src/textprop.c	2019-01-01 19:47:17.854123944 +0100
--- src/textprop.c	2019-01-01 23:30:08.638101345 +0100
***************
*** 915,925 ****
  /*
   * Adjust the columns of text properties in line "lnum" after position "col" to
   * shift by "bytes_added" (can be negative).
   */
      void
! adjust_prop_columns(linenr_T lnum UNUSED, colnr_T col UNUSED, int bytes_added UNUSED)
  {
!     // TODO
  }
  
  #endif // FEAT_TEXT_PROP
--- 915,961 ----
  /*
   * Adjust the columns of text properties in line "lnum" after position "col" to
   * shift by "bytes_added" (can be negative).
+  * Note that "col" is zero-based, while tp_col is one-based.
+  * Only for the current buffer.
+  * Called is expected to check b_has_textprop and "bytes_added" being non-zero.
   */
      void
! adjust_prop_columns(linenr_T lnum, colnr_T col, int bytes_added)
  {
!     int		proplen;
!     char_u	*props;
!     textprop_T	tmp_prop;
!     proptype_T  *pt;
!     int		dirty = FALSE;
!     int		i;
! 
!     proplen = get_text_props(curbuf, lnum, &props, TRUE);
!     if (proplen == 0)
! 	return;
! 
!     for (i = 0; i < proplen; ++i)
!     {
! 	mch_memmove(&tmp_prop, props + i * sizeof(textprop_T),
! 							   sizeof(textprop_T));
! 	pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type);
! 
! 	if (tmp_prop.tp_col >= col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL) ? 2 : 1))
! 	{
! 	    tmp_prop.tp_col += bytes_added;
! 	    dirty = TRUE;
! 	}
! 	else if (tmp_prop.tp_col + tmp_prop.tp_len > col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL) ? 0 : 1))
! 	{
! 	    tmp_prop.tp_len += bytes_added;
! 	    dirty = TRUE;
! 	}
! 	if (dirty)
! 	{
! 	    curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
! 	    mch_memmove(props + i * sizeof(textprop_T), &tmp_prop,
! 							   sizeof(textprop_T));
! 	}
!     }
  }
  
  #endif // FEAT_TEXT_PROP
*** ../vim-8.1.0677/src/testdir/test_textprop.vim	2019-01-01 19:47:17.854123944 +0100
--- src/testdir/test_textprop.vim	2019-01-01 23:44:18.167348741 +0100
***************
*** 300,316 ****
      return
    endif
    call writefile([
! 	\ "call setline(1, ['One two', 'Numbér 123 änd thœn 4¾7.', 'Three'])",
  	\ "hi NumberProp ctermfg=blue",
  	\ "hi LongProp ctermbg=yellow",
  	\ "call prop_type_add('number', {'highlight': 'NumberProp'})",
  	\ "call prop_type_add('long', {'highlight': 'LongProp'})",
  	\ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
  	\ "call prop_add(2, 9, {'length': 3, 'type': 'number'})",
  	\ "call prop_add(2, 24, {'length': 4, 'type': 'number'})",
  	\ "set number",
  	\ "hi clear SpellBad",
  	\ "set spell",
  	\], 'XtestProp')
    let buf = RunVimInTerminal('-S XtestProp', {'rows': 6})
    call VerifyScreenDump(buf, 'Test_textprop_01', {})
--- 300,324 ----
      return
    endif
    call writefile([
! 	\ "call setline(1, ['One two', 'Numbér 123 änd thœn 4¾7.', '--aa--bb--cc--dd--'])",
  	\ "hi NumberProp ctermfg=blue",
  	\ "hi LongProp ctermbg=yellow",
  	\ "call prop_type_add('number', {'highlight': 'NumberProp'})",
  	\ "call prop_type_add('long', {'highlight': 'LongProp'})",
+ 	\ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})",
+ 	\ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})",
+ 	\ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})",
  	\ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
  	\ "call prop_add(2, 9, {'length': 3, 'type': 'number'})",
  	\ "call prop_add(2, 24, {'length': 4, 'type': 'number'})",
+ 	\ "call prop_add(3, 3, {'length': 2, 'type': 'number'})",
+ 	\ "call prop_add(3, 7, {'length': 2, 'type': 'start'})",
+ 	\ "call prop_add(3, 11, {'length': 2, 'type': 'end'})",
+ 	\ "call prop_add(3, 15, {'length': 2, 'type': 'both'})",
  	\ "set number",
  	\ "hi clear SpellBad",
  	\ "set spell",
+ 	\ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>",
  	\], 'XtestProp')
    let buf = RunVimInTerminal('-S XtestProp', {'rows': 6})
    call VerifyScreenDump(buf, 'Test_textprop_01', {})
*** ../vim-8.1.0677/src/testdir/dumps/Test_textprop_01.dump	2019-01-01 19:47:17.854123944 +0100
--- src/testdir/dumps/Test_textprop_01.dump	2019-01-01 23:59:16.492821920 +0100
***************
*** 1,6 ****
! | +0#af5f00255#ffffff0@1|1| >O+0#0000000&|n|e| +0&#ffff4012|t|w|o| +0&#ffffff0@63
  | +0#af5f00255&@1|2| |N+0#0000000#ffff4012|u|m|b|é|r| |1+0#4040ff13&|2|3| +0#0000000&|ä|n|d| |t|h|œ|n| |4+0#4040ff13&|¾|7|.+0#0000000&| +0&#ffffff0@46
! | +0#af5f00255&@1|3| |T+0#0000000#ffff4012|h|r+0&#ffffff0|e@1| @65
  |~+0#4040ff13&| @73
  |~| @73
! | +0#0000000&@56|1|,|1| @10|A|l@1| 
--- 1,6 ----
! | +0#af5f00255#ffffff0@1|1| |O+0#0000000&|n|e| +0&#ffff4012|t|w|o| +0&#ffffff0@63
  | +0#af5f00255&@1|2| |N+0#0000000#ffff4012|u|m|b|é|r| |1+0#4040ff13&|2|3| +0#0000000&|ä|n|d| |t|h|œ|n| |4+0#4040ff13&|¾|7|.+0#0000000&| +0&#ffffff0@46
! | +0#af5f00255&@1|3| |-+0#0000000#ffff4012@1|x+0&#ffffff0|a+0#4040ff13&@1|x+0#0000000&|-@1|x+0#4040ff13&|b@1|x+0#0000000&|-@1|x|c+0#4040ff13&@1|x|-+0#0000000&@1|x+0#4040ff13&|d@1>x|-+0#0000000&@1| @44
  |~+0#4040ff13&| @73
  |~| @73
! | +0#0000000&@56|3|,|2|4| @9|A|l@1| 
*** ../vim-8.1.0677/src/version.c	2019-01-01 22:18:59.808136916 +0100
--- src/version.c	2019-01-02 00:00:20.584349916 +0100
***************
*** 801,802 ****
--- 801,804 ----
  {   /* Add new patch number below this line */
+ /**/
+     678,
  /**/

-- 
I AM THANKFUL...
...for a lawn that needs mowing, windows that need cleaning
and gutters that need fixing because it means I have a home.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- 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    ///