Skip to content

fix: TOC generation and window now respect initial_depth configuration#96

Merged
YousefHadder merged 6 commits intomainfrom
fix/toc-initial-depth
Nov 1, 2025
Merged

fix: TOC generation and window now respect initial_depth configuration#96
YousefHadder merged 6 commits intomainfrom
fix/toc-initial-depth

Conversation

@YousefHadder
Copy link
Copy Markdown
Owner

Summary

This PR fixes the TOC functionality to properly respect the initial_depth configuration setting for both the interactive TOC window and markdown TOC generation.

Changes

Bug Fixes

  • TOC Generation: generate_toc() and update_toc() now respect config.toc.initial_depth setting
  • TOC Window: Fixed folding behavior with proper ancestor chain checking
  • Headers are only visible in TOC window if all ancestors are expanded

Code Quality Improvements

  • Added missing toc? field to InternalConfig type annotation
  • Simplified config access pattern for consistency with codebase
  • Extracted are_all_ancestors_expanded() helper function to reduce complexity
  • Fixed misleading comment about auto-expansion logic

Documentation

  • Updated CHANGELOG.md with bug fix entry
  • Updated README.md to clarify initial_depth applies to both TOC window and generation

Tests

  • Added 3 comprehensive tests for TOC generation with different depth settings
  • All 211 tests passing ✅

Testing

make format-check  # ✅ Pass
make test          # ✅ 211/211 tests pass

Configuration

require('markdown-plus').setup({
  toc = {
    initial_depth = 2,  -- Now applies to both :Toc window AND generated TOC
  },
})

Related Issues

Fixes the issue where initial_depth only worked for the TOC window but not for TOC generation/update.

Copilot AI review requested due to automatic review settings November 1, 2025 17:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_depth configuration (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

Copilot AI review requested due to automatic review settings November 1, 2025 22:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@YousefHadder YousefHadder merged commit 5f35596 into main Nov 1, 2025
12 checks passed
@YousefHadder YousefHadder deleted the fix/toc-initial-depth branch November 1, 2025 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants