Commit 5adb98e5 authored by Matthew Leeds's avatar Matthew Leeds
Browse files

command-bar: Allow vim substitute commands to omit replace text

Builder only allows vim like substitute commands of the form :s/foo/bar/
but vim allows :s/foo/ or :s/foo (which just replace with the empty
string). This commit makes those formats work by changing how the search
text and replace text are calculated.

https://bugzilla.gnome.org/show_bug.cgi?id=746028
parent f893bad7
......@@ -1057,56 +1057,63 @@ gb_vim_command_search (GtkWidget *active_widget,
}
}
if (!search_end)
goto invalid_request;
if (search_end == NULL)
{
search_text = g_strdup (search_begin);
replace_text = g_strdup ("");
}
else
{
search_text = g_strndup (search_begin, search_end - search_begin);
replace_begin = command = g_utf8_next_char (command);
replace_begin = command = g_utf8_next_char (command);
for (; *command; command = g_utf8_next_char (command))
{
if (*command == '\\')
for (; *command; command = g_utf8_next_char (command))
{
command = g_utf8_next_char (command);
if (!*command)
goto invalid_request;
continue;
if (*command == '\\')
{
command = g_utf8_next_char (command);
if (!*command)
goto invalid_request;
continue;
}
if (g_utf8_get_char (command) == separator)
{
replace_end = command;
break;
}
}
if (g_utf8_get_char (command) == separator)
if (replace_end == NULL)
replace_text = g_strdup (replace_begin);
else
{
replace_end = command;
break;
replace_text = g_strndup (replace_begin, replace_end - replace_begin);
command = g_utf8_next_char (command);
}
}
if (!replace_end)
goto invalid_request;
command = g_utf8_next_char (command);
if (*command)
{
for (; *command; command++)
if (*command)
{
switch (*command)
for (; *command; command++)
{
case 'c':
confirm_replace = TRUE;
break;
case 'g':
break;
/* what other options are supported? */
default:
break;
switch (*command)
{
case 'c':
confirm_replace = TRUE;
break;
case 'g':
break;
/* what other options are supported? */
default:
break;
}
}
}
}
search_text = g_strndup (search_begin, search_end - search_begin);
replace_text = g_strndup (replace_begin, replace_end - replace_begin);
if (confirm_replace)
{
GVariant *variant;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment