Save full summary on quit regardless of cursor row

__getstate__ emitted an empty entry list whenever the cursor was on the
top row (y == 0), so quitting from the top silently discarded all
previously calculated results. The guard was intended to rotate the
cursor row to the front, but the y == 0 case should simply keep the whole
list as-is. Remove the guard so all entries are always persisted.
This commit is contained in:
Andrew Hamilton 2026-08-03 12:45:59 +10:00
parent 53474b2bcb
commit 8af627b502
2 changed files with 7 additions and 1 deletions

View file

@ -221,7 +221,7 @@ class Summary:
open_compressed = functools.partial(gzip.open, compresslevel=1) open_compressed = functools.partial(gzip.open, compresslevel=1)
x, y = self.cursor_position() x, y = self.cursor_position()
entries = itertools.chain([self._entries[y]], itertools.islice(self._entries, y), entries = itertools.chain([self._entries[y]], itertools.islice(self._entries, y),
itertools.islice(self._entries, y+1, None)) if y != 0 else [] itertools.islice(self._entries, y+1, None))
state["_old_entries"] = paged_list.PagedList(entries, summary_path, 2000, 1, state["_old_entries"] = paged_list.PagedList(entries, summary_path, 2000, 1,
exist_ok=True, open_func=open_compressed) exist_ok=True, open_func=open_compressed)
state["_entries"] = None state["_entries"] = None

View file

@ -101,6 +101,12 @@ class SummaryCursorTest(unittest.TestCase):
self._assert_movements([(self.summary.cursor_down, (1, 1)), self._assert_movements([(self.summary.cursor_down, (1, 1)),
(self.summary.cursor_down, (2, 2))]) (self.summary.cursor_down, (2, 2))])
def test_getstate_preserves_entries_at_top_row(self):
state = self.summary.__getstate__()
entries = list(state["_old_entries"])
self.assertEqual(len(entries), 3)
self.assertEqual(sum(len(row) for row in entries), 8)
class SummarySyncWithFilesystemTestCase(unittest.TestCase): class SummarySyncWithFilesystemTestCase(unittest.TestCase):