paperbox r116 - in trunk: . src



Author: markoa
Date: Wed Mar 12 21:28:36 2008
New Revision: 116
URL: http://svn.gnome.org/viewvc/paperbox?rev=116&view=rev

Log:
Erase tag from buffer on repeated selection

Modified:
   trunk/ChangeLog
   trunk/src/category-editor.cc

Modified: trunk/src/category-editor.cc
==============================================================================
--- trunk/src/category-editor.cc	(original)
+++ trunk/src/category-editor.cc	Wed Mar 12 21:28:36 2008
@@ -327,14 +327,22 @@
         using Glib::ustring;
 
         Glib::RefPtr<Gtk::TextBuffer> buf = text_view_.get_buffer();
-        ustring::size_type pos = buf->get_text().find(tag);
+        ustring text = buf->get_text();
+        ustring::size_type pos = text.find(tag);
 
-        if (pos == ustring::size_type(-1)) {
-            ustring text = buf->get_text();
+        if (pos == ustring::size_type(-1))
             text.insert(text.size(), " " + tag);
-            buf->set_text(text);
-            check_buffer_status();
+        else {
+            ustring::size_type end_pos = pos + tag.size();
+            if (pos > 0) { // erase the leading whitespace as well
+                --pos;
+                ++end_pos;
+            }
+            text.erase(pos, end_pos);
         }
+
+        buf->set_text(text);
+        check_buffer_status();
     }
 
     void



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