summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0018
blob: 998587b8cee5d346dad04d8bd78eecc322e215e4 (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
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0018
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.0018
Problem:    Using "gn" may select wrong text when wrapping.
Solution:   Avoid wrapping when searching forward. (Christian Brabandt)
Files:	    src/search.c, src/testdir/test_gn.vim


*** ../vim-8.1.0017/src/search.c	2018-04-27 22:44:25.000000000 +0200
--- src/search.c	2018-05-22 17:45:10.884137772 +0200
***************
*** 4665,4670 ****
--- 4665,4671 ----
  {
      pos_T	start_pos;	/* position before the pattern */
      pos_T	orig_pos;	/* position of the cursor at beginning */
+     pos_T	first_match;	/* position of first match */
      pos_T	pos;		/* position after the pattern */
      int		i;
      int		dir;
***************
*** 4758,4763 ****
--- 4759,4766 ----
  				ml_get(curwin->w_buffer->b_ml.ml_line_count));
  	    }
  	}
+ 	if (i == 0)
+ 	    first_match = pos;
  	p_ws = old_p_ws;
      }
  
***************
*** 4774,4782 ****
      /* move to match, except for zero-width matches, in which case, we are
       * already on the next match */
      if (!one_char)
! 	result = searchit(curwin, curbuf, &pos, direction,
  		    spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0,
  								   NULL, NULL);
  
      if (!VIsual_active)
  	VIsual = start_pos;
--- 4777,4801 ----
      /* move to match, except for zero-width matches, in which case, we are
       * already on the next match */
      if (!one_char)
!     {
! 	p_ws = FALSE;
! 	for (i = 0; i < 2; i++)
! 	{
! 	    result = searchit(curwin, curbuf, &pos, direction,
  		    spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0,
  								   NULL, NULL);
+ 	    /* Search successfull, break out from the loop */
+ 	    if (result)
+ 		break;
+ 	    /* search failed, try again from the last search position match */
+ 	    pos = first_match;
+ 	}
+     }
+ 
+     p_ws = old_p_ws;
+     /* not found */
+     if (!result)
+ 	return FAIL;
  
      if (!VIsual_active)
  	VIsual = start_pos;
*** ../vim-8.1.0017/src/testdir/test_gn.vim	2017-10-15 22:02:53.000000000 +0200
--- src/testdir/test_gn.vim	2018-05-22 17:48:47.536062374 +0200
***************
*** 4,54 ****
    noautocmd new
    " replace a single char by itsself quoted:
    call setline('.', 'abc x def x ghi x jkl')
!   let @/='x'
    exe "norm! cgn'x'\<esc>.."
    call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.'))
    sil! %d_
  
    " simple search match
    call setline('.', 'foobar')
!   let @/='foobar'
    exe "norm! gncsearchmatch"
    call assert_equal('searchmatch', getline('.'))
    sil! %d _
  
    " replace a multi-line match
    call setline('.', ['', 'one', 'two'])
!   let @/='one\_s*two\_s'
    exe "norm! gnceins\<CR>zwei"
    call assert_equal(['','eins','zwei'], getline(1,'$'))
    sil! %d _
  
    " test count argument
    call setline('.', ['', 'abcdx | abcdx | abcdx'])
!   let @/='[a]bcdx'
    exe "norm! 2gnd"
    call assert_equal(['','abcdx |  | abcdx'], getline(1,'$'))
    sil! %d _
  
    " join lines
    call setline('.', ['join ', 'lines'])
!   let @/='$'
    exe "norm! 0gnd"
    call assert_equal(['join lines'], getline(1,'$'))
    sil! %d _
  
    " zero-width match
    call setline('.', ['', 'zero width pattern'])
!   let @/='\>\zs'
    exe "norm! 0gnd"
    call assert_equal(['', 'zerowidth pattern'], getline(1,'$'))
    sil! %d _
  
    " delete first and last chars
    call setline('.', ['delete first and last chars'])
!   let @/='^'
    exe "norm! 0gnd$"
!   let @/='\zs'
    exe "norm! gnd"
    call assert_equal(['elete first and last char'], getline(1,'$'))
    sil! %d _
--- 4,54 ----
    noautocmd new
    " replace a single char by itsself quoted:
    call setline('.', 'abc x def x ghi x jkl')
!   let @/ = 'x'
    exe "norm! cgn'x'\<esc>.."
    call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.'))
    sil! %d_
  
    " simple search match
    call setline('.', 'foobar')
!   let @/ = 'foobar'
    exe "norm! gncsearchmatch"
    call assert_equal('searchmatch', getline('.'))
    sil! %d _
  
    " replace a multi-line match
    call setline('.', ['', 'one', 'two'])
!   let @/ = 'one\_s*two\_s'
    exe "norm! gnceins\<CR>zwei"
    call assert_equal(['','eins','zwei'], getline(1,'$'))
    sil! %d _
  
    " test count argument
    call setline('.', ['', 'abcdx | abcdx | abcdx'])
!   let @/ = '[a]bcdx'
    exe "norm! 2gnd"
    call assert_equal(['','abcdx |  | abcdx'], getline(1,'$'))
    sil! %d _
  
    " join lines
    call setline('.', ['join ', 'lines'])
!   let @/ = '$'
    exe "norm! 0gnd"
    call assert_equal(['join lines'], getline(1,'$'))
    sil! %d _
  
    " zero-width match
    call setline('.', ['', 'zero width pattern'])
!   let @/ = '\>\zs'
    exe "norm! 0gnd"
    call assert_equal(['', 'zerowidth pattern'], getline(1,'$'))
    sil! %d _
  
    " delete first and last chars
    call setline('.', ['delete first and last chars'])
!   let @/ = '^'
    exe "norm! 0gnd$"
!   let @/ = '\zs'
    exe "norm! gnd"
    call assert_equal(['elete first and last char'], getline(1,'$'))
    sil! %d _
***************
*** 61,74 ****
  
    " backwards search
    call setline('.', ['my very excellent mother just served us nachos'])
!   let @/='mother'
    exe "norm! $cgNmongoose"
    call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$'))
    sil! %d _
  
    " search for single char
    call setline('.', ['','for (i=0; i<=10; i++)'])
!   let @/='i'
    exe "norm! cgnj"
    call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$'))
    sil! %d _
--- 61,74 ----
  
    " backwards search
    call setline('.', ['my very excellent mother just served us nachos'])
!   let @/ = 'mother'
    exe "norm! $cgNmongoose"
    call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$'))
    sil! %d _
  
    " search for single char
    call setline('.', ['','for (i=0; i<=10; i++)'])
!   let @/ = 'i'
    exe "norm! cgnj"
    call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$'))
    sil! %d _
***************
*** 76,103 ****
    " search hex char
    call setline('.', ['','Y'])
    set noignorecase
!   let @/='\%x59'
    exe "norm! gnd"
    call assert_equal(['',''], getline(1,'$'))
    sil! %d _
  
    " test repeating gdn
    call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3'])
!   let @/='Johnny'
    exe "norm! dgn."
    call assert_equal(['','1', '', '2', '', '3'], getline(1,'$'))
    sil! %d _
  
    " test repeating gUgn
    call setline('.', ['', '1', 'Depp', '2', 'Depp', '3'])
!   let @/='Depp'
    exe "norm! gUgn."
    call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$'))
    sil! %d _
  
    " test using look-ahead assertions
    call setline('.', ['a:10', '', 'a:1', '', 'a:20'])
!   let @/='a:0\@!\zs\d\+'
    exe "norm! 2nygno\<esc>p"
    call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$'))
    sil! %d _
--- 76,103 ----
    " search hex char
    call setline('.', ['','Y'])
    set noignorecase
!   let @/ = '\%x59'
    exe "norm! gnd"
    call assert_equal(['',''], getline(1,'$'))
    sil! %d _
  
    " test repeating gdn
    call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3'])
!   let @/ = 'Johnny'
    exe "norm! dgn."
    call assert_equal(['','1', '', '2', '', '3'], getline(1,'$'))
    sil! %d _
  
    " test repeating gUgn
    call setline('.', ['', '1', 'Depp', '2', 'Depp', '3'])
!   let @/ = 'Depp'
    exe "norm! gUgn."
    call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$'))
    sil! %d _
  
    " test using look-ahead assertions
    call setline('.', ['a:10', '', 'a:1', '', 'a:20'])
!   let @/ = 'a:0\@!\zs\d\+'
    exe "norm! 2nygno\<esc>p"
    call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$'))
    sil! %d _
***************
*** 113,124 ****
    " search upwards with nowrapscan set
    call setline('.', ['foo', 'bar', 'foo', 'baz'])
    set nowrapscan
!   let @/='foo'
    $
    norm! dgN
    call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$'))
    sil! %d_
  
    set wrapscan&vim
  endfu
  
--- 113,133 ----
    " search upwards with nowrapscan set
    call setline('.', ['foo', 'bar', 'foo', 'baz'])
    set nowrapscan
!   let @/ = 'foo'
    $
    norm! dgN
    call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$'))
    sil! %d_
  
+   " search using the \zs atom
+   call setline(1, [' nnoremap', '' , 'nnoremap'])
+   set wrapscan&vim
+   let @/ = '\_s\zsnnoremap'
+   $
+   norm! cgnmatch
+   call assert_equal([' nnoremap', '', 'match'], getline(1,'$'))
+   sil! %d_
+ 
    set wrapscan&vim
  endfu
  
*** ../vim-8.1.0017/src/version.c	2018-05-22 16:58:43.979903077 +0200
--- src/version.c	2018-05-22 17:49:43.960023944 +0200
***************
*** 763,764 ****
--- 763,766 ----
  {   /* Add new patch number below this line */
+ /**/
+     18,
  /**/

-- 
Eye have a spelling checker, it came with my PC;
It plainly marks four my revue mistakes I cannot sea.
I've run this poem threw it, I'm sure your please to no,
It's letter perfect in it's weigh, my checker tolled me sew!

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