[gnome-builder] command-bar: Allow vim substitute commands to omit replace text



commit 5adb98e59c24fee27e1d0e106f13b31f17651033
Author: Matthew Leeds <mleeds redhat com>
Date:   Fri Mar 10 10:11:50 2017 -0600

    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

 plugins/command-bar/gb-vim.c |   79 +++++++++++++++++++++++-------------------
 1 files changed, 43 insertions(+), 36 deletions(-)
---
diff --git a/plugins/command-bar/gb-vim.c b/plugins/command-bar/gb-vim.c
index caa2f12..f992db3 100644
--- a/plugins/command-bar/gb-vim.c
+++ b/plugins/command-bar/gb-vim.c
@@ -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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]