Skip to content

Commit

Permalink
Make more safe for accidental invalid batch count
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Nov 1, 2023
1 parent 76e5795 commit 959368b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions webextensions/sidebar/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ function startBatchToUpdateMaxTreeLevel(trigger) {
}

function finishBatchToUpdateMaxTreeLevel(trigger) {
reserveToUpdateVisualMaxTreeLevel.batchCount--;
if (reserveToUpdateVisualMaxTreeLevel.batchCount > 0) // safe guard for accidental negative count
reserveToUpdateVisualMaxTreeLevel.batchCount--;
console.log('finish ', trigger);
if (reserveToUpdateVisualMaxTreeLevel.batchCount > 0)
return;
Expand Down Expand Up @@ -242,6 +243,7 @@ async function reserveToUpdateIndent() {
const restVisibilityChangedTabIds = new Set();

CollapseExpand.onUpdated.addListener((tab, _options) => {
const isFinishBatch = restVisibilityChangedTabIds.has(tab.id);
restVisibilityChangedTabIds.delete(tab.id);

if (configs.indentAutoShrink &&
Expand All @@ -250,7 +252,7 @@ CollapseExpand.onUpdated.addListener((tab, _options) => {

console.log('restVisibilityChangedTabIds ', restVisibilityChangedTabIds);

if (restVisibilityChangedTabIds.size == 0)
if (isFinishBatch && restVisibilityChangedTabIds.size == 0)
finishBatchToUpdateMaxTreeLevel('CollapseExpand.onUpdated');
});

Expand Down Expand Up @@ -288,7 +290,8 @@ BackgroundConnection.onMessage.addListener(async message => {
}; break;

case Constants.kCOMMAND_NOTIFY_SUBTREE_COLLAPSED_STATE_CHANGED:
if (restVisibilityChangedTabIds.size == 0)
if (restVisibilityChangedTabIds.size == 0 &&
message.visibilityChangedTabIds.length > 0)
startBatchToUpdateMaxTreeLevel('Constants.kCOMMAND_NOTIFY_SUBTREE_COLLAPSED_STATE_CHANGED');
for (const id of message.visibilityChangedTabIds) {
restVisibilityChangedTabIds.add(id);
Expand Down

0 comments on commit 959368b

Please sign in to comment.