[gedit-list] patch for reverse plugin



Here is a little patch to make the reverse plugin selection aware (so
that if there is a selection, it reverses only the selection, not the
entire buffer.) I'd like to also do this for other plugins where
appropriate if nobody objects, but the reverse plugin was an easy place
to start.

**Ali Muñiz
Index: reverse.c
===================================================================
RCS file: /cvs/gnome/gedit/plugins/reverse/reverse.c,v
retrieving revision 1.6
diff -u -r1.6 reverse.c
--- reverse.c	2000/06/11 06:30:07	1.6
+++ reverse.c	2000/06/25 02:22:22
@@ -10,6 +10,7 @@
 #include <gnome.h>
 
 #include "document.h"
+#include "view.h"
 #include "plugin.h"
 
 
@@ -23,27 +24,36 @@
 reverse (void)
 {
      Document *doc = gedit_document_current();
+     View *view = gedit_view_current();
      gchar *buffer ;
      gchar tmp ;
      gint buffer_length ;
      gint i;
+     gint * start = g_new(gint, 1);
+     gint * end = g_new(gint, 1);
 
      if (!doc)
 	  return;
 
      buffer_length = gedit_document_get_buffer_length (doc);
      buffer = gedit_document_get_buffer (doc);
+     if (!gedit_view_get_selection(view, start, end))
+     {
+	     *start = 0;
+	     *end = buffer_length;
+     }
 
-     for (i=0; i < ( buffer_length / 2 ); i++)
+     for (i=*start; i < ( *start + (*end - *start) / 2 ); i++)
      {
 	  tmp = buffer [i];
-	  buffer [i] = buffer [buffer_length - i - 1];
-	  buffer [buffer_length - i - 1] = tmp;
+	  buffer [i] = buffer [*end + *start - i - 1];
+	  buffer [*end + *start - i - 1] = tmp;
      }
-     
+
      gedit_document_delete_text (doc, 0, buffer_length, TRUE);
      gedit_document_insert_text (doc, buffer, 0, TRUE);
-     
+     g_free (start);
+     g_free (end);
      g_free (buffer);
      
 }
 


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