mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
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 #2418, closes #2435)
This commit is contained in:
52
src/gui.c
52
src/gui.c
@@ -5173,8 +5173,6 @@ gui_update_screen(void)
|
||||
#endif
|
||||
|
||||
#if defined(FIND_REPLACE_DIALOG) || defined(PROTO)
|
||||
static void concat_esc(garray_T *gap, char_u *text, int what);
|
||||
|
||||
/*
|
||||
* Get the text to use in a find/replace dialog. Uses the last search pattern
|
||||
* if the argument is empty.
|
||||
@@ -5238,31 +5236,6 @@ get_find_dialog_text(
|
||||
return text;
|
||||
}
|
||||
|
||||
/*
|
||||
* Concatenate "text" to grow array "gap", escaping "what" with a backslash.
|
||||
*/
|
||||
static void
|
||||
concat_esc(garray_T *gap, char_u *text, int what)
|
||||
{
|
||||
while (*text != NUL)
|
||||
{
|
||||
#ifdef FEAT_MBYTE
|
||||
int l = (*mb_ptr2len)(text);
|
||||
|
||||
if (l > 1)
|
||||
{
|
||||
while (--l >= 0)
|
||||
ga_append(gap, *text++);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (*text == what)
|
||||
ga_append(gap, '\\');
|
||||
ga_append(gap, *text);
|
||||
++text;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle the press of a button in the find-replace dialog.
|
||||
* Return TRUE when something was added to the input buffer.
|
||||
@@ -5305,10 +5278,11 @@ gui_do_findrepl(
|
||||
ga_concat(&ga, (char_u *)"\\c");
|
||||
if (flags & FRD_WHOLE_WORD)
|
||||
ga_concat(&ga, (char_u *)"\\<");
|
||||
if (type == FRD_REPLACEALL || down)
|
||||
concat_esc(&ga, find_text, '/'); /* escape slashes */
|
||||
else
|
||||
concat_esc(&ga, find_text, '?'); /* escape '?' */
|
||||
/* escape / and \ */
|
||||
p = vim_strsave_escaped(find_text, (char_u *)"/\\");
|
||||
if (p != NULL)
|
||||
ga_concat(&ga, p);
|
||||
vim_free(p);
|
||||
if (flags & FRD_WHOLE_WORD)
|
||||
ga_concat(&ga, (char_u *)"\\>");
|
||||
|
||||
@@ -5371,8 +5345,20 @@ gui_do_findrepl(
|
||||
if (type == FRD_REPLACE)
|
||||
searchflags += SEARCH_START;
|
||||
i = msg_scroll;
|
||||
(void)do_search(NULL, down ? '/' : '?', ga.ga_data, 1L,
|
||||
searchflags, NULL, NULL);
|
||||
if (down)
|
||||
{
|
||||
(void)do_search(NULL, '/', ga.ga_data, 1L, searchflags, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We need to escape '?' if and only if we are searching in the up
|
||||
* direction */
|
||||
p = vim_strsave_escaped(ga.ga_data, (char_u *)"?");
|
||||
if (p != NULL)
|
||||
(void)do_search(NULL, '?', p, 1L, searchflags, NULL, NULL);
|
||||
vim_free(p);
|
||||
}
|
||||
|
||||
msg_scroll = i; /* don't let an error message set msg_scroll */
|
||||
}
|
||||
|
||||
|
@@ -761,6 +761,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1834,
|
||||
/**/
|
||||
1833,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user