%C escape suspends colors as well as attributes
[canto-curses.git] / canto_curses / tag.py
index 3ee93d9..a636d08 100644 (file)
@@ -155,8 +155,11 @@ class Tag(PluginHandler, list):
                 break
 
     def on_items_added(self, tagcore, added):
+        cur_ids = self.get_ids()
         if tagcore == self.tagcore:
-            self.updates_pending += len(added)
+            for story_id in added:
+                if story_id not in cur_ids:
+                    self.updates_pending += 1
             self.need_redraw()
 
     # We override eq so that empty tags don't evaluate
@@ -338,7 +341,7 @@ class Tag(PluginHandler, list):
 
             if not self.collapsed and self.border:
                 theme_print(pad, theme_border("ts") * (width - 2), width,\
-                        "%B%1"+ theme_border("tl"), theme_border("tr") + "%0%b")
+                        "%B"+ theme_border("tl"), theme_border("tr") + "%b")
                 lines += 1
         except Exception as e:
             tb = traceback.format_exc()
@@ -352,7 +355,7 @@ class Tag(PluginHandler, list):
     def render_footer(self, width, pad):
         if not self.collapsed and self.border:
             theme_print(pad, theme_border("bs") * (width - 2), width,\
-                    "%B%1" + theme_border("bl"), theme_border("br") + "%0%b")
+                    "%B" + theme_border("bl"), theme_border("br") + "%b")
             theme_reset()
             return 1
         return 0
@@ -368,10 +371,19 @@ class Tag(PluginHandler, list):
 
             self.tagcore.lock.acquire_read()
 
+            self.tagcore.ack_changes()
+
             for story in self:
                 if story.id in self.tagcore:
                     current_stories.append((self.tagcore.index(story.id), story))
                 elif story == sel:
+
+                    # If we preserve the selection in an "undead" state, then
+                    # we keep set tagcore changed so that the next sync operation
+                    # will re-evaluate it.
+
+                    self.tagcore.changed()
+
                     if current_stories:
                         place = max([ x[0] for x in current_stories ]) + .5
                     else:
@@ -418,5 +430,4 @@ class Tag(PluginHandler, list):
         for s in self:
             s.sync()
 
-        self.tagcore.ack_changes()
         self.updates_pending = 0