@@ -17,8 +17,7 @@ const props = defineProps<{
1717// ------------------------------------------------------------
1818const store = diffTreeStore ();
1919const count = ref (0 );
20- let pendingUpdate = 0 ;
21- let pendingTimer: Promise <void > | undefined ;
20+ const updateQueue = ref (0 );
2221// ------------------------------------------------------------
2322// Batch Update Mechanism
2423// ------------------------------------------------------------
@@ -27,15 +26,12 @@ let pendingTimer: Promise<void> | undefined;
2726 * Prevents multiple updates within the same tick
2827 */
2928const setCount = (isViewed : boolean ) => {
30- pendingUpdate += (isViewed ? 1 : - 1 );
31-
32- if (pendingTimer === undefined ) {
33- pendingTimer = nextTick (() => {
34- count .value = Math .max (0 , count .value + pendingUpdate );
35- pendingUpdate = 0 ;
36- pendingTimer = undefined ;
37- });
38- }
29+ updateQueue .value += (isViewed ? 1 : - 1 );
30+
31+ nextTick (() => {
32+ count .value = Math .max (0 , count .value + updateQueue .value );
33+ updateQueue .value = 0 ;
34+ });
3935};
4036
4137// ------------------------------------------------------------
@@ -49,6 +45,18 @@ const setCount = (isViewed: boolean) => {
4945const isViewed = computed (() => {
5046 return props .item .isFile ? props .item .file .IsViewed : (props .item as DirItem ).children .length === count .value ;
5147});
48+
49+ // ------------------------------------------------------------
50+ // Collapse Behavior Documentation
51+ // ------------------------------------------------------------
52+ /**
53+ * Collapse behavior rules:
54+ * - Viewed folders start collapsed initially
55+ * - Manual expand/collapse takes precedence over automatic behavior
56+ * - State persists after manual interaction
57+ */
58+ const collapsed = ref (isViewed .value );
59+
5260// ------------------------------------------------------------
5361// Watchers & Side Effects
5462// ------------------------------------------------------------
@@ -62,21 +70,11 @@ watch(
6270 if (props .setViewed ) {
6371 props .setViewed (newVal );
6472 }
73+ collapsed .value = newVal ;
6574 },
6675 {immediate: true , flush: ' post' },
6776);
6877
69- // ------------------------------------------------------------
70- // Collapse Behavior Documentation
71- // ------------------------------------------------------------
72- /**
73- * Collapse behavior rules:
74- * - Viewed folders start collapsed initially
75- * - Manual expand/collapse takes precedence over automatic behavior
76- * - State persists after manual interaction
77- */
78- const collapsed = ref (isViewed .value );
79-
8078function getIconForDiffStatus(pType : FileStatus ) {
8179 const diffTypes: Record <FileStatus , { name: SvgName , classes: Array <string > }> = {
8280 ' added' : {name: ' octicon-diff-added' , classes: [' text' , ' green' ]},
0 commit comments