[hamster-applet/gnome-2-30] fixed bug 617297 - allow properly combining clicking and typing in autocomplete and correct cursor p



commit 8d154326d95bd62199f834e6d5042cfd1e4f4ee4
Author: Toms Bauģis <toms baugis gmail com>
Date:   Thu May 6 02:23:27 2010 +0100

    fixed bug 617297 - allow properly combining clicking and typing in autocomplete and correct cursor position

 src/hamster/widgets/tags.py |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/hamster/widgets/tags.py b/src/hamster/widgets/tags.py
index 038c02d..60345a9 100644
--- a/src/hamster/widgets/tags.py
+++ b/src/hamster/widgets/tags.py
@@ -72,14 +72,23 @@ class TagsEntry(gtk.Entry):
         return [tag.strip() for tag in self.get_text().decode('utf8', 'replace').split(",") if tag.strip()]
 
     def on_tag_selected(self, tag_box, tag):
-        tags = self.get_tags()
-        tags.append(tag)
+        cursor_tag = self.get_cursor_tag()
+        if cursor_tag and tag.startswith(cursor_tag):
+            self.replace_tag(cursor_tag, tag)
+            tags = self.get_tags()
+        else:
+            tags = self.get_tags()
+            tags.append(tag)
 
         self.tag_box.selected_tags = tags
 
-        self.set_text(", ".join(tags))
+
+        self.set_text("%s, " % ", ".join(tags))
         self.set_position(len(self.get_text()))
 
+        self.populate_suggestions()
+        self.show_popup()
+
     def on_tag_unselected(self, tag_box, tag):
         tags = self.get_tags()
         while tag in tags: #it could be that dear user is mocking us and entering same tag over and over again
@@ -87,7 +96,7 @@ class TagsEntry(gtk.Entry):
 
         self.tag_box.selected_tags = tags
 
-        self.set_text(", ".join(tags))
+        self.set_text("%s, " % ", ".join(tags))
         self.set_position(len(self.get_text()))
 
 
@@ -197,7 +206,7 @@ class TagsEntry(gtk.Entry):
             cursor = self.get_position()
 
         self.set_text(", ".join(tags))
-        self.set_position(cursor + len(new_tag)-len(old_tag)) # put the cursor back
+        self.set_position(len(self.get_text()))
 
     def _on_key_press_event(self, entry, event):
         if event.keyval == gtk.keysyms.Tab:



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