Mercurial > vim
comparison src/gui.c @ 13927:ec54a202ad0c v8.0.1834
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
commit https://github.com/vim/vim/commit/518bc174ed34dc79303488914aaaa3c238a85080
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 13 17:05:30 2018 +0200
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Problem: GUI: find/replace dialog does not handle some chars properly.
Solution: Escape '?' when needed. Always escape backslash. (closes https://github.com/vim/vim/issues/2418,
closes #2435)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 13 May 2018 17:15:05 +0200 |
parents | fa0dcdaec6a3 |
children | 4cb334816bb1 |
comparison
equal
deleted
inserted
replaced
13926:e104131e69e2 | 13927:ec54a202ad0c |
---|---|
5171 out_flush_cursor(TRUE, FALSE); | 5171 out_flush_cursor(TRUE, FALSE); |
5172 } | 5172 } |
5173 #endif | 5173 #endif |
5174 | 5174 |
5175 #if defined(FIND_REPLACE_DIALOG) || defined(PROTO) | 5175 #if defined(FIND_REPLACE_DIALOG) || defined(PROTO) |
5176 static void concat_esc(garray_T *gap, char_u *text, int what); | |
5177 | |
5178 /* | 5176 /* |
5179 * Get the text to use in a find/replace dialog. Uses the last search pattern | 5177 * Get the text to use in a find/replace dialog. Uses the last search pattern |
5180 * if the argument is empty. | 5178 * if the argument is empty. |
5181 * Returns an allocated string. | 5179 * Returns an allocated string. |
5182 */ | 5180 */ |
5237 } | 5235 } |
5238 return text; | 5236 return text; |
5239 } | 5237 } |
5240 | 5238 |
5241 /* | 5239 /* |
5242 * Concatenate "text" to grow array "gap", escaping "what" with a backslash. | |
5243 */ | |
5244 static void | |
5245 concat_esc(garray_T *gap, char_u *text, int what) | |
5246 { | |
5247 while (*text != NUL) | |
5248 { | |
5249 #ifdef FEAT_MBYTE | |
5250 int l = (*mb_ptr2len)(text); | |
5251 | |
5252 if (l > 1) | |
5253 { | |
5254 while (--l >= 0) | |
5255 ga_append(gap, *text++); | |
5256 continue; | |
5257 } | |
5258 #endif | |
5259 if (*text == what) | |
5260 ga_append(gap, '\\'); | |
5261 ga_append(gap, *text); | |
5262 ++text; | |
5263 } | |
5264 } | |
5265 | |
5266 /* | |
5267 * Handle the press of a button in the find-replace dialog. | 5240 * Handle the press of a button in the find-replace dialog. |
5268 * Return TRUE when something was added to the input buffer. | 5241 * Return TRUE when something was added to the input buffer. |
5269 */ | 5242 */ |
5270 int | 5243 int |
5271 gui_do_findrepl( | 5244 gui_do_findrepl( |
5303 ga_concat(&ga, (char_u *)"\\C"); | 5276 ga_concat(&ga, (char_u *)"\\C"); |
5304 else | 5277 else |
5305 ga_concat(&ga, (char_u *)"\\c"); | 5278 ga_concat(&ga, (char_u *)"\\c"); |
5306 if (flags & FRD_WHOLE_WORD) | 5279 if (flags & FRD_WHOLE_WORD) |
5307 ga_concat(&ga, (char_u *)"\\<"); | 5280 ga_concat(&ga, (char_u *)"\\<"); |
5308 if (type == FRD_REPLACEALL || down) | 5281 /* escape / and \ */ |
5309 concat_esc(&ga, find_text, '/'); /* escape slashes */ | 5282 p = vim_strsave_escaped(find_text, (char_u *)"/\\"); |
5310 else | 5283 if (p != NULL) |
5311 concat_esc(&ga, find_text, '?'); /* escape '?' */ | 5284 ga_concat(&ga, p); |
5285 vim_free(p); | |
5312 if (flags & FRD_WHOLE_WORD) | 5286 if (flags & FRD_WHOLE_WORD) |
5313 ga_concat(&ga, (char_u *)"\\>"); | 5287 ga_concat(&ga, (char_u *)"\\>"); |
5314 | 5288 |
5315 if (type == FRD_REPLACEALL) | 5289 if (type == FRD_REPLACEALL) |
5316 { | 5290 { |
5369 /* Search for the next match. | 5343 /* Search for the next match. |
5370 * Don't skip text under cursor for single replace. */ | 5344 * Don't skip text under cursor for single replace. */ |
5371 if (type == FRD_REPLACE) | 5345 if (type == FRD_REPLACE) |
5372 searchflags += SEARCH_START; | 5346 searchflags += SEARCH_START; |
5373 i = msg_scroll; | 5347 i = msg_scroll; |
5374 (void)do_search(NULL, down ? '/' : '?', ga.ga_data, 1L, | 5348 if (down) |
5375 searchflags, NULL, NULL); | 5349 { |
5350 (void)do_search(NULL, '/', ga.ga_data, 1L, searchflags, NULL, NULL); | |
5351 } | |
5352 else | |
5353 { | |
5354 /* We need to escape '?' if and only if we are searching in the up | |
5355 * direction */ | |
5356 p = vim_strsave_escaped(ga.ga_data, (char_u *)"?"); | |
5357 if (p != NULL) | |
5358 (void)do_search(NULL, '?', p, 1L, searchflags, NULL, NULL); | |
5359 vim_free(p); | |
5360 } | |
5361 | |
5376 msg_scroll = i; /* don't let an error message set msg_scroll */ | 5362 msg_scroll = i; /* don't let an error message set msg_scroll */ |
5377 } | 5363 } |
5378 | 5364 |
5379 /* Don't want to pass did_emsg to other code, it may cause disabling | 5365 /* Don't want to pass did_emsg to other code, it may cause disabling |
5380 * syntax HL if we were busy redrawing. */ | 5366 * syntax HL if we were busy redrawing. */ |