chiark / gitweb /
Fix file-position stability over backward extend.
authorSimon Tatham <anakin@pobox.com>
Sat, 9 Dec 2023 18:44:21 +0000 (18:44 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 9 Dec 2023 18:44:21 +0000 (18:44 +0000)
That last-minute idea to bound pos_within_item within the actual size
of the item ... forgot that each logical item (e.g. a status) is made
up of multiple physical items (paragraphs, separator line, etc), so I
bounded it within _those_ and made a mess. Should be back to normal now.

cursesclient.py

index c5a9ed5013d871f74fb4c4be87b985d6b9c2f26e..3e8c0c09dacf0a8fd6b72de91f9f4bad3aaa8010 100644 (file)
@@ -622,18 +622,22 @@ class ObjectFile(File):
         self.lines = []
         self.index_by_line = []
         pos = 0
+        last_itemindex = None
+        curr_itemtop = 0
         for thing, itemindex in self.iter_text_indexed():
             params = {}
             if (self.mode == 'select' and itemindex == self.select_target and
                 hasattr(thing, 'can_highlight_as_target')):
                 params['target'] = True
-            oldlen = len(self.lines)
+            if itemindex != last_itemindex:
+                curr_itemtop = len(self.lines)
+                last_itemindex = itemindex
             for line in thing.render(width, **params):
                 for s in line.split(width):
                     self.lines.append(s)
                     self.index_by_line.append(itemindex)
             if itemindex == self.itempos:
-                itemheight = len(self.lines) - oldlen
+                itemheight = len(self.lines) - curr_itemtop
                 pos = len(self.lines) - min(pos_within_item, itemheight)
 
         self.width = width