summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0654
blob: 53efd08dc95555a67204952a576ec6956e6f0ab1 (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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0654
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.0654
Problem:    When deleting a line text property flags are not adjusted.
Solution:   Adjust text property flags in preceding and following lines.
Files:	    src/memline.c, src/misc2.c, src/proto/misc2.pro,
            src/testdir/test_textprop.vim


*** ../vim-8.1.0653/src/memline.c	2018-12-26 23:42:05.331769359 +0100
--- src/memline.c	2018-12-28 21:43:27.380673476 +0100
***************
*** 3214,3219 ****
--- 3214,3317 ----
      return OK;
  }
  
+ #ifdef FEAT_TEXT_PROP
+ /*
+  * Adjust text properties in line "lnum" for a deleted line.
+  * When "above" is true this is the line above the deleted line.
+  * "del_props" are the properties of the deleted line.
+  */
+     static void
+ adjust_text_props_for_delete(
+ 	buf_T	    *buf,
+ 	linenr_T    lnum,
+ 	char_u	    *del_props,
+ 	int	    del_props_len,
+ 	int	    above)
+ {
+     int		did_get_line = FALSE;
+     int		done_del;
+     int		done_this;
+     textprop_T	prop_del;
+     textprop_T	prop_this;
+     bhdr_T	*hp;
+     DATA_BL	*dp;
+     int		idx;
+     int		line_start;
+     long	line_size;
+     int		this_props_len;
+     char_u	*text;
+     size_t	textlen;
+     int		found;
+ 
+     for (done_del = 0; done_del < del_props_len; done_del += sizeof(textprop_T))
+     {
+ 	mch_memmove(&prop_del, del_props + done_del, sizeof(textprop_T));
+ 	if ((above && (prop_del.tp_flags & TP_FLAG_CONT_PREV)
+ 		    && !(prop_del.tp_flags & TP_FLAG_CONT_NEXT))
+ 		|| (!above && (prop_del.tp_flags & TP_FLAG_CONT_NEXT)
+ 		    && !(prop_del.tp_flags & TP_FLAG_CONT_PREV)))
+ 	{
+ 	    if (!did_get_line)
+ 	    {
+ 		did_get_line = TRUE;
+ 		if ((hp = ml_find_line(buf, lnum, ML_FIND)) == NULL)
+ 		    return;
+ 
+ 		dp = (DATA_BL *)(hp->bh_data);
+ 		idx = lnum - buf->b_ml.ml_locked_low;
+ 		line_start = ((dp->db_index[idx]) & DB_INDEX_MASK);
+ 		if (idx == 0)		// first line in block, text at the end
+ 		    line_size = dp->db_txt_end - line_start;
+ 		else
+ 		    line_size = ((dp->db_index[idx - 1]) & DB_INDEX_MASK) - line_start;
+ 		text = (char_u *)dp + line_start;
+ 		textlen = STRLEN(text) + 1;
+ 		if ((long)textlen >= line_size)
+ 		{
+ 		    if (above)
+ 			internal_error("no text property above deleted line");
+ 		    else
+ 			internal_error("no text property below deleted line");
+ 		    return;
+ 		}
+ 		this_props_len = line_size - textlen;
+ 	    }
+ 
+ 	    found = FALSE;
+ 	    for (done_this = 0; done_this < this_props_len; done_this += sizeof(textprop_T))
+ 	    {
+ 		mch_memmove(&prop_this, text + textlen + done_del, sizeof(textprop_T));
+ 		if (prop_del.tp_id == prop_this.tp_id
+ 			&& prop_del.tp_type == prop_this.tp_type)
+ 		{
+ 		    int flag = above ? TP_FLAG_CONT_NEXT : TP_FLAG_CONT_PREV;
+ 
+ 		    found = TRUE;
+ 		    if (prop_this.tp_flags & flag)
+ 		    {
+ 			prop_this.tp_flags &= ~flag;
+ 			mch_memmove(text + textlen + done_del, &prop_this, sizeof(textprop_T));
+ 		    }
+ 		    else if (above)
+ 			internal_error("text property above deleted line does not continue");
+ 		    else
+ 			internal_error("text property below deleted line does not continue");
+ 		}
+ 	    }
+ 	    if (!found)
+ 	    {
+ 		if (above)
+ 		    internal_error("text property above deleted line not found");
+ 		else
+ 		    internal_error("text property below deleted line not found");
+ 	    }
+ 
+ 	    buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS);
+ 	}
+     }
+ }
+ #endif
+ 
  /*
   * Delete line "lnum" in the current buffer.
   * When "message" is TRUE may give a "No lines in buffer" message.
***************
*** 3245,3250 ****
--- 3343,3353 ----
      int		line_start;
      long	line_size;
      int		i;
+     int		ret = FAIL;
+ #ifdef FEAT_TEXT_PROP
+     char_u	*textprop_save = NULL;
+     int		textprop_save_len;
+ #endif
  
      if (lnum < 1 || lnum > buf->b_ml.ml_line_count)
  	return FAIL;
***************
*** 3272,3280 ****
      }
  
  /*
!  * find the data block containing the line
!  * This also fills the stack with the blocks from the root to the data block
!  * This also releases any locked block.
   */
      mfp = buf->b_ml.ml_mfp;
      if (mfp == NULL)
--- 3375,3383 ----
      }
  
  /*
!  * Find the data block containing the line.
!  * This also fills the stack with the blocks from the root to the data block.
!  * This also releases any locked block..
   */
      mfp = buf->b_ml.ml_mfp;
      if (mfp == NULL)
***************
*** 3301,3306 ****
--- 3404,3424 ----
      if (netbeans_active())
  	netbeans_removed(buf, lnum, 0, (long)line_size);
  #endif
+ #ifdef FEAT_TEXT_PROP
+     // If there are text properties, make a copy, so that we can update
+     // properties in preceding and following lines.
+     if (buf->b_has_textprop)
+     {
+ 	size_t	textlen = STRLEN((char_u *)dp + line_start) + 1;
+ 
+ 	if ((long)textlen < line_size)
+ 	{
+ 	    textprop_save_len = line_size - textlen;
+ 	    textprop_save = vim_memsave((char_u *)dp + line_start + textlen,
+ 							  textprop_save_len);
+ 	}
+     }
+ #endif
  
  /*
   * special case: If there is only one line in the data block it becomes empty.
***************
*** 3322,3334 ****
  	    ip = &(buf->b_ml.ml_stack[stack_idx]);
  	    idx = ip->ip_index;
  	    if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
! 		return FAIL;
  	    pp = (PTR_BL *)(hp->bh_data);   /* must be pointer block */
  	    if (pp->pb_id != PTR_ID)
  	    {
  		IEMSG(_("E317: pointer block id wrong 4"));
  		mf_put(mfp, hp, FALSE, FALSE);
! 		return FAIL;
  	    }
  	    count = --(pp->pb_count);
  	    if (count == 0)	    /* the pointer block becomes empty! */
--- 3440,3452 ----
  	    ip = &(buf->b_ml.ml_stack[stack_idx]);
  	    idx = ip->ip_index;
  	    if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
! 		goto theend;
  	    pp = (PTR_BL *)(hp->bh_data);   /* must be pointer block */
  	    if (pp->pb_id != PTR_ID)
  	    {
  		IEMSG(_("E317: pointer block id wrong 4"));
  		mf_put(mfp, hp, FALSE, FALSE);
! 		goto theend;
  	    }
  	    count = --(pp->pb_count);
  	    if (count == 0)	    /* the pointer block becomes empty! */
***************
*** 3384,3394 ****
  #ifdef FEAT_BYTEOFF
      ml_updatechunk(buf, lnum, line_size, ML_CHNK_DELLINE);
  #endif
!     return OK;
  }
  
  /*
!  * set the B_MARKED flag for line 'lnum'
   */
      void
  ml_setmarked(linenr_T lnum)
--- 3502,3526 ----
  #ifdef FEAT_BYTEOFF
      ml_updatechunk(buf, lnum, line_size, ML_CHNK_DELLINE);
  #endif
!     ret = OK;
! 
! theend:
! #ifdef FEAT_TEXT_PROP
!     if (textprop_save != NULL)
!     {
! 	// Adjust text properties in the line above and below.
! 	if (lnum > 1)
! 	    adjust_text_props_for_delete(buf, lnum - 1, textprop_save, textprop_save_len, TRUE);
! 	if (lnum <= buf->b_ml.ml_line_count)
! 	    adjust_text_props_for_delete(buf, lnum, textprop_save, textprop_save_len, FALSE);
!     }
!     vim_free(textprop_save);
! #endif
!     return ret;
  }
  
  /*
!  * set the DB_MARKED flag for line 'lnum'
   */
      void
  ml_setmarked(linenr_T lnum)
***************
*** 3417,3423 ****
  }
  
  /*
!  * find the first line with its B_MARKED flag set
   */
      linenr_T
  ml_firstmarked(void)
--- 3549,3555 ----
  }
  
  /*
!  * find the first line with its DB_MARKED flag set
   */
      linenr_T
  ml_firstmarked(void)
***************
*** 3650,3656 ****
  }
  
  /*
!  * lookup line 'lnum' in a memline
   *
   *   action: if ML_DELETE or ML_INSERT the line count is updated while searching
   *	     if ML_FLUSH only flush a locked block
--- 3782,3788 ----
  }
  
  /*
!  * Lookup line 'lnum' in a memline.
   *
   *   action: if ML_DELETE or ML_INSERT the line count is updated while searching
   *	     if ML_FLUSH only flush a locked block
*** ../vim-8.1.0653/src/misc2.c	2018-12-21 16:04:16.324437435 +0100
--- src/misc2.c	2018-12-28 20:48:07.184432933 +0100
***************
*** 1351,1356 ****
--- 1351,1370 ----
  }
  
  /*
+  * Copy "p[len]" into allocated memory, ignoring NUL characters.
+  * Returns NULL when out of memory.
+  */
+     char_u *
+ vim_memsave(char_u *p, int len)
+ {
+     char_u *ret = alloc((unsigned)len);
+ 
+     if (ret != NULL)
+ 	mch_memmove(ret, p, (size_t)len);
+     return ret;
+ }
+ 
+ /*
   * Same as vim_strsave(), but any characters found in esc_chars are preceded
   * by a backslash.
   */
*** ../vim-8.1.0653/src/proto/misc2.pro	2018-12-21 15:16:57.483579762 +0100
--- src/proto/misc2.pro	2018-12-28 20:48:14.680374028 +0100
***************
*** 24,30 ****
  char_u *alloc(unsigned size);
  char_u *alloc_id(unsigned size, alloc_id_T id);
  char_u *alloc_clear(unsigned size);
! char_u * alloc_clear_id(unsigned size, alloc_id_T id);
  char_u *alloc_check(unsigned size);
  char_u *lalloc_clear(long_u size, int message);
  char_u *lalloc(long_u size, int message);
--- 24,30 ----
  char_u *alloc(unsigned size);
  char_u *alloc_id(unsigned size, alloc_id_T id);
  char_u *alloc_clear(unsigned size);
! char_u *alloc_clear_id(unsigned size, alloc_id_T id);
  char_u *alloc_check(unsigned size);
  char_u *lalloc_clear(long_u size, int message);
  char_u *lalloc(long_u size, int message);
***************
*** 34,39 ****
--- 34,40 ----
  void free_all_mem(void);
  char_u *vim_strsave(char_u *string);
  char_u *vim_strnsave(char_u *string, int len);
+ char_u *vim_memsave(char_u *p, int len);
  char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars);
  char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int bsl);
  int csh_like_shell(void);
*** ../vim-8.1.0653/src/testdir/test_textprop.vim	2018-12-26 23:42:05.331769359 +0100
--- src/testdir/test_textprop.vim	2018-12-28 21:56:36.550153919 +0100
***************
*** 197,202 ****
--- 197,212 ----
    bwipe!
  endfunc
  
+ " Setup a three line prop in lines 2 - 4.
+ " Add short props in line 1 and 5.
+ func Setup_three_line_prop()
+   new
+   call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five'])
+   call prop_add(1, 2, {'length': 1, 'type': 'comment'})
+   call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'})
+   call prop_add(5, 2, {'length': 1, 'type': 'comment'})
+ endfunc
+ 
  func Test_prop_multiline()
    call prop_type_add('comment', {'highlight': 'Directory'})
    new
***************
*** 223,228 ****
--- 233,262 ----
    call prop_clear(1, 3)
  
    bwipe!
+ 
+   " Test deleting the first line with a prop.
+   call Setup_three_line_prop()
+   let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0}
+   call assert_equal([expect2], prop_list(2))
+   2del
+   let expect_short = {'col': 2, 'length': 1, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0}
+   call assert_equal([expect_short], prop_list(1))
+   let expect2 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0}
+   call assert_equal([expect2], prop_list(2))
+   bwipe!
+ 
+   " Test deleting the last line with a prop.
+   call Setup_three_line_prop()
+   let expect3 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0}
+   call assert_equal([expect3], prop_list(3))
+   let expect4 = {'col': 1, 'length': 5, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0}
+   call assert_equal([expect4], prop_list(4))
+   4del
+   let expect3 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0}
+   call assert_equal([expect3], prop_list(3))
+   call assert_equal([expect_short], prop_list(4))
+   bwipe!
+ 
    call prop_type_delete('comment')
  endfunc
  
*** ../vim-8.1.0653/src/version.c	2018-12-28 19:29:31.743633958 +0100
--- src/version.c	2018-12-28 20:47:21.172793725 +0100
***************
*** 801,802 ****
--- 801,804 ----
  {   /* Add new patch number below this line */
+ /**/
+     654,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
69. Yahoo welcomes you with your own start page

 /// 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    ///