Hi everyone! ![]()
I’ve just published a new extension that brings VS Code / Monaco-style sticky scroll to CodeMirror 6:
@fazelstudio/codemirror-stickyscroll
- GitHub: GitHub - fazelllyyy/codemirror-stickyscroll: VS Code / Monaco-style sticky scroll (sticky lines) extension for CodeMirror 6 · GitHub
- npm: https://www.npmjs.com/package/@fazelstudio/codemirror-stickyscroll
What it does
Sticky lines keep the opening lines of the enclosing scopes (function, class, if/loop, etc.) pinned at the top of the editor as you scroll — exactly like VS Code’s sticky scroll, but built as a pure external extension (no fork of any @codemirror/* package).
Features
- Per-pixel updates via native
scroll+requestAnimationFrame— no jumpy redraws - Slide-away effect — the innermost row slides up smoothly as its scope’s closing line approaches the viewport (matches Monaco’s exact behavior)
- Click-to-jump with scroll margin compensation so the target line is never hidden behind the bar
- Reuses the consumer’s theme — token colors come from the active
highlightingFor()highlighters; the package never registers its ownsyntaxHighlighting - Language-agnostic — works with any
@codemirror/lang-*that registersfoldNodeProp, with a built-in smart denylist for JS/TS, Python, Rust, Go, and graceful JSON support - Gutter alignment — line numbers mirror the real gutter column-by-column via
ResizeObserver - Dynamic height clamping — the bar never covers more than ~40% of the viewport
- Zero runtime deps — peer dependencies only
Usage
import { stickyScroll } from "@fazelstudio/codemirror-stickyscroll";
new EditorView({
extensions: [
basicSetup,
javascript(),
stickyScroll({ maxStickyLines: 4 }),
],
parent: document.body,
});
──────
Any feedback, bug reports, or suggestions are very welcome! 🙏