Skip to content

Fix section embed viewport clipping#39

Open
MDerman wants to merge 1 commit into
uthvah:mainfrom
MDerman:fix-section-embed-viewport-decorations
Open

Fix section embed viewport clipping#39
MDerman wants to merge 1 commit into
uthvah:mainfrom
MDerman:fix-section-embed-viewport-decorations

Conversation

@MDerman
Copy link
Copy Markdown

@MDerman MDerman commented May 12, 2026

Replace nth-child based section hiding with CodeMirror decorations so embedded section ranges are anchored to document positions instead of virtualized DOM line nodes.

Replace nth-child based section hiding with CodeMirror decorations so embedded section ranges are anchored to document positions instead of virtualized DOM line nodes.
@MDerman
Copy link
Copy Markdown
Author

MDerman commented May 12, 2026

I hate to be that c*nt who does AI-genned PRs, but this has fixed issues I've experienced locally so why not? Thanks for making this plugin. Discovered obsidian 5 days ago and am deep in this rabbit hole clearly.

Summary

Fixes section embeds showing the wrong range of content, including cases where the top of the target section is clipped and the next section heading appears inside the embed.

What Changed

  • Replaced CSS nth-child() line hiding with CodeMirror document-position decorations.
  • Kept the existing CSS viewport fallback for cases where a CodeMirror view is unavailable.
  • Skipped the old scroll clamp for decoration-based section embeds.
  • Fixed keyup listener cleanup to remove the same handler that was registered.

Why

CodeMirror 6 virtualizes .cm-line DOM nodes, so DOM child indexes are not stable document line numbers. The previous viewport logic could hide the wrong lines as the editor rendered or recycled visible rows.

Testing

  • Built successfully with npm run build.
  • Verified locally in Obsidian that section embeds no longer clip the top of the current section or leak the next heading.

@uthvah
Copy link
Copy Markdown
Owner

uthvah commented May 16, 2026

Thank you! My apologies - I had some critical fixes on the main branch that was long due for a release. Is this still a problem with the latest release, and if it is - could you send some steps to recreate/screenshots?

@MDerman
Copy link
Copy Markdown
Author

MDerman commented May 19, 2026

Hey man - yes latest release seems to have patched this. Thanks!

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