fix: TOC generation and window now respect initial_depth configuration#96
Merged
YousefHadder merged 6 commits intomainfrom Nov 1, 2025
Merged
fix: TOC generation and window now respect initial_depth configuration#96YousefHadder merged 6 commits intomainfrom
YousefHadder merged 6 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes TOC generation and the TOC window to respect the initial_depth configuration option. Previously, initial_depth only controlled the TOC window's display depth, but now it also limits which headers are included when generating or updating the TOC in the document itself.
Key changes:
- TOC generation/update now filters headers based on
initial_depthconfiguration (default: 2) - TOC window visibility logic improved to properly handle ancestor expansion states
- Entry count in notification messages now reflects actual entries added, not total headers minus one
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lua/markdown-plus/headers/toc.lua | Added config handling, filtering logic for initial_depth, and accurate entry counting |
| lua/markdown-plus/headers/toc_window.lua | Improved visibility logic with ancestor checking and auto-expansion of headers below initial_depth |
| lua/markdown-plus/headers/init.lua | Passes config to TOC module via set_config() |
| lua/markdown-plus/types.lua | Added toc field to InternalConfig type definition |
| spec/markdown-plus/headers_spec.lua | Added comprehensive tests for initial_depth behavior in generation and update |
| README.md | Updated config comment to clarify initial_depth affects both window and generation |
| CHANGELOG.md | Documented the bug fix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the TOC functionality to properly respect the
initial_depthconfiguration setting for both the interactive TOC window and markdown TOC generation.Changes
Bug Fixes
generate_toc()andupdate_toc()now respectconfig.toc.initial_depthsettingCode Quality Improvements
toc?field toInternalConfigtype annotationare_all_ancestors_expanded()helper function to reduce complexityDocumentation
initial_depthapplies to both TOC window and generationTests
Testing
Configuration
Related Issues
Fixes the issue where
initial_depthonly worked for the TOC window but not for TOC generation/update.