summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0971
blob: 6c37d5e91869c13ea4bf4172d817ca71891db64b (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
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0971
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.0971
Problem:    Failure for selecting quoted text object moves cursor.
Solution:   Restore the Visual selection on failure. (Christian Brabandt,
            closes #4024)
Files:	    src/search.c, src/testdir/test_textobjects.vim


*** ../vim-8.1.0970/src/search.c	2019-02-17 17:44:36.219875473 +0100
--- src/search.c	2019-02-22 14:55:16.869702567 +0100
***************
*** 4359,4369 ****
      int		col_end;
      int		col_start = curwin->w_cursor.col;
      int		inclusive = FALSE;
!     int		vis_empty = TRUE;	/* Visual selection <= 1 char */
!     int		vis_bef_curs = FALSE;	/* Visual starts before cursor */
!     int		inside_quotes = FALSE;	/* Looks like "i'" done before */
!     int		selected_quote = FALSE;	/* Has quote inside selection */
      int		i;
  
      /* Correct cursor when 'selection' is "exclusive". */
      if (VIsual_active)
--- 4359,4370 ----
      int		col_end;
      int		col_start = curwin->w_cursor.col;
      int		inclusive = FALSE;
!     int		vis_empty = TRUE;	// Visual selection <= 1 char
!     int		vis_bef_curs = FALSE;	// Visual starts before cursor
!     int		inside_quotes = FALSE;	// Looks like "i'" done before
!     int		selected_quote = FALSE;	// Has quote inside selection
      int		i;
+     int		restore_vis_bef = FALSE; // restore VIsual on abort
  
      /* Correct cursor when 'selection' is "exclusive". */
      if (VIsual_active)
***************
*** 4377,4388 ****
  	{
  	    if (!vis_bef_curs)
  	    {
! 		/* VIsual needs to be start of Visual selection. */
  		pos_T t = curwin->w_cursor;
  
  		curwin->w_cursor = VIsual;
  		VIsual = t;
  		vis_bef_curs = TRUE;
  	    }
  	    dec_cursor();
  	}
--- 4378,4390 ----
  	{
  	    if (!vis_bef_curs)
  	    {
! 		// VIsual needs to be the start of Visual selection.
  		pos_T t = curwin->w_cursor;
  
  		curwin->w_cursor = VIsual;
  		VIsual = t;
  		vis_bef_curs = TRUE;
+ 		restore_vis_bef = TRUE;
  	    }
  	    dec_cursor();
  	}
***************
*** 4431,4437 ****
  	     * opening quote. */
  	    col_start = find_next_quote(line, col_start + 1, quotechar, NULL);
  	    if (col_start < 0)
! 		return FALSE;
  	    col_end = find_next_quote(line, col_start + 1, quotechar,
  							      curbuf->b_p_qe);
  	    if (col_end < 0)
--- 4433,4439 ----
  	     * opening quote. */
  	    col_start = find_next_quote(line, col_start + 1, quotechar, NULL);
  	    if (col_start < 0)
! 		goto abort_search;
  	    col_end = find_next_quote(line, col_start + 1, quotechar,
  							      curbuf->b_p_qe);
  	    if (col_end < 0)
***************
*** 4445,4451 ****
  	{
  	    col_end = find_prev_quote(line, col_start, quotechar, NULL);
  	    if (line[col_end] != quotechar)
! 		return FALSE;
  	    col_start = find_prev_quote(line, col_end, quotechar,
  							      curbuf->b_p_qe);
  	    if (line[col_start] != quotechar)
--- 4447,4453 ----
  	{
  	    col_end = find_prev_quote(line, col_start, quotechar, NULL);
  	    if (line[col_end] != quotechar)
! 		goto abort_search;
  	    col_start = find_prev_quote(line, col_end, quotechar,
  							      curbuf->b_p_qe);
  	    if (line[col_start] != quotechar)
***************
*** 4480,4491 ****
  	    /* Find open quote character. */
  	    col_start = find_next_quote(line, col_start, quotechar, NULL);
  	    if (col_start < 0 || col_start > first_col)
! 		return FALSE;
  	    /* Find close quote character. */
  	    col_end = find_next_quote(line, col_start + 1, quotechar,
  							      curbuf->b_p_qe);
  	    if (col_end < 0)
! 		return FALSE;
  	    /* If is cursor between start and end quote character, it is
  	     * target text object. */
  	    if (col_start <= first_col && first_col <= col_end)
--- 4482,4493 ----
  	    /* Find open quote character. */
  	    col_start = find_next_quote(line, col_start, quotechar, NULL);
  	    if (col_start < 0 || col_start > first_col)
! 		goto abort_search;
  	    /* Find close quote character. */
  	    col_end = find_next_quote(line, col_start + 1, quotechar,
  							      curbuf->b_p_qe);
  	    if (col_end < 0)
! 		goto abort_search;
  	    /* If is cursor between start and end quote character, it is
  	     * target text object. */
  	    if (col_start <= first_col && first_col <= col_end)
***************
*** 4502,4515 ****
  	    /* No quote before the cursor, look after the cursor. */
  	    col_start = find_next_quote(line, col_start, quotechar, NULL);
  	    if (col_start < 0)
! 		return FALSE;
  	}
  
  	/* Find close quote character. */
  	col_end = find_next_quote(line, col_start + 1, quotechar,
  							      curbuf->b_p_qe);
  	if (col_end < 0)
! 	    return FALSE;
      }
  
      /* When "include" is TRUE, include spaces after closing quote or before
--- 4504,4517 ----
  	    /* No quote before the cursor, look after the cursor. */
  	    col_start = find_next_quote(line, col_start, quotechar, NULL);
  	    if (col_start < 0)
! 		goto abort_search;
  	}
  
  	/* Find close quote character. */
  	col_end = find_next_quote(line, col_start + 1, quotechar,
  							      curbuf->b_p_qe);
  	if (col_end < 0)
! 	    goto abort_search;
      }
  
      /* When "include" is TRUE, include spaces after closing quote or before
***************
*** 4596,4601 ****
--- 4598,4617 ----
      }
  
      return OK;
+ 
+ abort_search:
+     if (VIsual_active && *p_sel == 'e')
+     {
+ 	inc_cursor();
+ 	if (restore_vis_bef)
+ 	{
+ 	    pos_T t = curwin->w_cursor;
+ 
+ 	    curwin->w_cursor = VIsual;
+ 	    VIsual = t;
+ 	}
+     }
+     return FALSE;
  }
  
  #endif /* FEAT_TEXTOBJ */
*** ../vim-8.1.0970/src/testdir/test_textobjects.vim	2019-01-09 23:00:58.001176090 +0100
--- src/testdir/test_textobjects.vim	2019-02-22 14:56:31.897291834 +0100
***************
*** 52,57 ****
--- 52,82 ----
    bw!
  endfunc
  
+ func Test_quote_selection_selection_exclusive_abort()
+   new
+   set selection=exclusive
+   call setline(1, "'abzzc'")
+   let exp_curs = [0, 1, 6, 0]
+   call cursor(1,1)
+   exe 'norm! fcdvi"'
+   " make sure to end visual mode to have a clear state
+   exe "norm! \<esc>"
+   call assert_equal(exp_curs, getpos('.'))
+   call cursor(1,1)
+   exe 'norm! fcvi"'
+   exe "norm! \<esc>"
+   call assert_equal(exp_curs, getpos('.'))
+   call cursor(1,2)
+   exe 'norm! vfcoi"'
+   exe "norm! \<esc>"
+   let exp_curs = [0, 1, 2, 0]
+   let exp_visu = [0, 1, 7, 0]
+   call assert_equal(exp_curs, getpos('.'))
+   call assert_equal(exp_visu, getpos("'>"))
+   set selection&vim
+   bw!
+ endfunc
+ 
  " Tests for string and html text objects
  func Test_string_html_objects()
    enew!
*** ../vim-8.1.0970/src/version.c	2019-02-22 14:38:46.447452832 +0100
--- src/version.c	2019-02-22 15:02:30.395260732 +0100
***************
*** 781,782 ****
--- 781,784 ----
  {   /* Add new patch number below this line */
+ /**/
+     971,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
11. You find yourself typing "com" after every period when using a word
    processor.com

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