diff --git a/web/pdf_outline_viewer.js b/web/pdf_outline_viewer.js index 5dbdf1360e327..7d584564c3c34 100644 --- a/web/pdf_outline_viewer.js +++ b/web/pdf_outline_viewer.js @@ -95,7 +95,23 @@ class PDFOutlineViewer extends BaseTreeViewer { * @private */ _addToggleButton(div, { count, items }) { - const hidden = count < 0 && Math.abs(count) === items.length; + let hidden = false; + if (count < 0) { + let totalCount = items.length; + if (totalCount > 0) { + const queue = [...items]; + while (queue.length > 0) { + const { count: nestedCount, items: nestedItems } = queue.shift(); + if (nestedCount > 0 && nestedItems.length > 0) { + totalCount += nestedItems.length; + queue.push(...nestedItems); + } + } + } + if (Math.abs(count) === totalCount) { + hidden = true; + } + } super._addToggleButton(div, hidden); }