Skip to content

Commit a06d25e

Browse files
committed
fix(recent): keep recent list collapsed unless user toggles
Recording a new entry or loading persisted entries no longer auto-expands the recent list. Pruning still collapses an emptied list, but no longer expands a non-empty one. This makes expansion state fully user-controlled.
1 parent 2ffedc8 commit a06d25e

4 files changed

Lines changed: 20 additions & 18 deletions

File tree

cue_lib/audio/recent.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class CueRecentManager(object):
2626
"""Most-recent-first persistent list of heterogeneous used entries.
2727
2828
expand-state (toggle) is session-local -- only the entries are persisted.
29-
expanded defaults to True whenever the list has entries, so a non-empty
30-
list shows open until the user collapses it.
29+
The list opens only when the user toggles it; recording a use or loading
30+
persisted entries never auto-expands. prune only collapses a list that
31+
has been emptied of valid refs.
3132
"""
3233

3334
def __init__(self, key, keep):
@@ -59,14 +60,13 @@ def save(self):
5960

6061
def record(self, kind, ref):
6162
# type: (str, str) -> None
62-
"""Mark an attempt to use (kind, ref): move to front, cap, expand."""
63+
"""Mark an attempt to use (kind, ref): move to front, cap."""
6364
for i, e in enumerate(self._entries):
6465
if e["type"] == kind and e["ref"] == ref:
6566
del self._entries[i]
6667
break
6768
self._entries.insert(0, {"type": kind, "ref": ref})
6869
del self._entries[CUE_RECENT_MAX_ENTRIES:]
69-
self.expanded = True
7070
self.save()
7171

7272
def entries(self):
@@ -84,7 +84,8 @@ def prune(self):
8484
self._entries = [e for e in self._entries
8585
if self._keep(e["type"], e["ref"])]
8686
del self._entries[CUE_RECENT_MAX_ENTRIES:]
87-
self.expanded = bool(self._entries)
87+
if not self._entries:
88+
self.expanded = False
8889
self.save()
8990

9091

test_game/templates/testcases_legacy.rpy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ testcase sfx_recently_used:
120120
$ _ok = _ok and not _cue.sfx_manager._recent.expanded
121121
run Function(_cue.markers.image.send_file, 0)
122122
$ _ok = _ok and _cue.sfx_manager._recent.entries() == [{"type": "file", "ref": _cue.sfx_manager.files[0]}]
123-
$ _ok = _ok and _cue.sfx_manager._recent.expanded
123+
$ _ok = _ok and not _cue.sfx_manager._recent.expanded
124124
run Function(_cue.markers.image.send_folder, "Sub/")
125125
$ _ok = _ok and _cue.sfx_manager._recent.entries()[0] == {"type": "folder", "ref": "Sub/"}
126126
$ _ok = _ok and len(_cue.sfx_manager._recent.entries()) == 2
@@ -144,7 +144,7 @@ testcase music_recently_used:
144144
$ _ok = _ok and not _cue.music._recent.expanded
145145
run Function(_cue.music.add_user_song_to_trigger, "music/song_001.ogg")
146146
$ _ok = _ok and _cue.music._recent.entries() == [{"type": "file", "ref": "u:music/song_001.ogg"}]
147-
$ _ok = _ok and _cue.music._recent.expanded
147+
$ _ok = _ok and not _cue.music._recent.expanded
148148
run Function(_cue.music.add_user_folder_to_trigger, "music/")
149149
$ _ok = _ok and _cue.music._recent.entries()[0] == {"type": "folder", "ref": "u:music/"}
150150
$ _ok = _ok and len(_cue.music._recent.entries()) == 2

test_game/templates/testcases_modern.rpy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ testcase sfx_recently_used:
8383
assert eval (_cue.sfx_manager._recent is not None)
8484
assert eval (_cue.sfx_manager._recent.entries() == [])
8585
assert eval (not _cue.sfx_manager._recent.expanded)
86-
# A file send records the resolved path and expands the list.
86+
# A file send records the resolved path; it does not expand the list.
8787
run Function(_cue.markers.image.send_file, 0)
8888
assert eval (_cue.sfx_manager._recent.entries() == [{"type": "file", "ref": _cue.sfx_manager.files[0]}])
89-
assert eval (_cue.sfx_manager._recent.expanded)
89+
assert eval (not _cue.sfx_manager._recent.expanded)
9090
# A folder send normalizes its ref and bumps to front.
9191
run Function(_cue.markers.image.send_folder, "Sub/")
9292
assert eval (_cue.sfx_manager._recent.entries()[0] == {"type": "folder", "ref": "Sub/"})
@@ -107,10 +107,10 @@ testcase music_recently_used:
107107
assert eval (_cue.music._recent is not None)
108108
assert eval (_cue.music._recent.entries() == [])
109109
assert eval (not _cue.music._recent.expanded)
110-
# Adding a My Music song records its u:-tagged ref and expands the list.
110+
# Adding a My Music song records its u:-tagged ref; it does not expand.
111111
run Function(_cue.music.add_user_song_to_trigger, "music/song_001.ogg")
112112
assert eval (_cue.music._recent.entries() == [{"type": "file", "ref": "u:music/song_001.ogg"}])
113-
assert eval (_cue.music._recent.expanded)
113+
assert eval (not _cue.music._recent.expanded)
114114
# A folder add normalizes its ref and bumps to front.
115115
run Function(_cue.music.add_user_folder_to_trigger, "music/")
116116
assert eval (_cue.music._recent.entries()[0] == {"type": "folder", "ref": "u:music/"})

tests/test_recent.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _all_keep(kind, ref):
2828

2929

3030
# ---------------------------------------------------------------------------
31-
# record: dedup, MRU order, cap, expand-on-first
31+
# record: dedup, MRU order, cap (no auto-expand)
3232
# ---------------------------------------------------------------------------
3333

3434
def test_record_moves_existing_entry_to_front():
@@ -55,11 +55,10 @@ def test_record_caps_at_max_entries():
5555
assert m.entries()[0]["ref"] == "f{}.ogg".format(CUE_RECENT_MAX_ENTRIES + 2)
5656

5757

58-
def test_first_record_expands_list():
58+
def test_record_does_not_expand_list():
5959
m = CueRecentManager("recent_entries", _all_keep)
60-
assert m.expanded is False
6160
m.record("file", "a.ogg")
62-
assert m.expanded is True
61+
assert m.expanded is False
6362

6463

6564
# ---------------------------------------------------------------------------
@@ -85,13 +84,13 @@ def test_record_writes_to_persistent():
8584
assert persistent._cue["recent_entries"] == [{"type": "file", "ref": "a.ogg"}]
8685

8786

88-
def test_load_roundtrips_entries_and_expands():
87+
def test_load_roundtrips_entries_without_expanding():
8988
m = CueRecentManager("recent_entries", _all_keep)
9089
m.record("preset", "Hurt")
9190
m2 = CueRecentManager("recent_entries", _all_keep)
9291
m2.load()
9392
assert [e["ref"] for e in m2.entries()] == ["Hurt"]
94-
assert m2.expanded is True
93+
assert m2.expanded is False
9594

9695

9796
def test_load_no_entries_when_key_absent():
@@ -117,7 +116,7 @@ def test_load_prunes_stale_entries():
117116
lambda kind, ref: ref == "keep.ogg")
118117
m2.load()
119118
assert [e["ref"] for e in m2.entries()] == ["keep.ogg"]
120-
assert m2.expanded is True
119+
assert m2.expanded is False
121120

122121

123122
def test_load_collapses_when_all_stale():
@@ -139,13 +138,15 @@ def test_prune_drops_stale_entries():
139138
m.record("file", "gone.ogg")
140139
m.record("file", "keep.ogg")
141140
m.record("folder", "sfx/keep/")
141+
m.expanded = True
142142
m.prune()
143143
assert [e["ref"] for e in m.entries()] == ["sfx/keep/", "keep.ogg"]
144144
assert m.expanded is True
145145

146146

147147
def test_prune_empty_when_all_stale_collapses():
148148
m = CueRecentManager("recent_entries", lambda kind, ref: False)
149+
m.expanded = True
149150
m.record("file", "a.ogg")
150151
m.prune()
151152
assert m.entries() == []

0 commit comments

Comments
 (0)