Experiment regarding sticky scroll for yaml#327
Open
stvncode wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a CodeMirror 6 sticky-scroll overlay for the YAML editor (to mirror the legacy ESPHome dashboard behavior) and introduces the scope-walking utilities/tests that drive it.
Changes:
- Implement sticky-scroll view plugin + rendering/theme helpers.
- Add YAML indentation “scope” utilities (ancestor chain, opener detection, exit line) with comprehensive unit tests.
- Expose highlight styles for reuse by the sticky overlay.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/util/yaml-sticky-scope.test.ts | Adds unit tests for scope computation/opener/exit behavior (blank lines, banner comments, lists, EOF). |
| src/util/yaml-sticky-theme.ts | Adds overlay theme styling for the sticky header container/rows. |
| src/util/yaml-sticky-scroll.ts | Implements the CodeMirror ViewPlugin for sticky overlay rendering, measuring, shifting, and click-to-jump. |
| src/util/yaml-sticky-scope.ts | Implements scope discovery utilities used by the sticky-scroll plugin. |
| src/util/yaml-sticky-render.ts | Adds DOM row creation + syntax-highlighted rendering for sticky rows. |
| src/util/yaml-editor-theme.ts | Exports highlight styles so they can be reused outside the base editor theme. |
| src/components/yaml-editor.ts | Wires the sticky-scroll extension into the YAML editor with light/dark styling. |
Comment on lines
+119
to
+126
| const scrollTop = view.scrollDOM.scrollTop; | ||
| const rowHeight = view.defaultLineHeight; | ||
| const block = view.lineBlockAtHeight(scrollTop); | ||
| const topLine = view.state.doc.lineAt(block.from); | ||
| const gutterEl = view.dom.querySelector<HTMLElement>(".cm-gutters"); | ||
| const gutterWidth = gutterEl ? gutterEl.offsetWidth : 0; | ||
| const lines = view.state.doc.toString().split("\n"); | ||
| const scope = computeStickyScope(lines, topLine.number); |
Comment on lines
+8
to
+11
| const row = document.createElement("div"); | ||
| row.className = "cm-esphome-sticky-line"; | ||
| row.setAttribute("role", "button"); | ||
| row.tabIndex = 0; |
Comment on lines
+282
to
+285
| const rowHeight = | ||
| this._renderedCount > 0 | ||
| ? this._measuredHeight / this._renderedCount | ||
| : this.view.defaultLineHeight; |
Comment on lines
+13
to
+15
| fontFamily: '"JetBrains Mono", "Fira Code", monospace', | ||
| fontSize: "13px", | ||
| lineHeight: "1.4", |
Comment on lines
+124
to
+136
| let prev = topVisibleLine - 1; | ||
| while (prev > 0) { | ||
| const line = lines[prev - 1]; | ||
| const stripped = stripComment(line); | ||
| if (stripped.trim() && !line.startsWith("#")) { | ||
| targetIndent = indentOf(stripped); | ||
| break; | ||
| } | ||
| prev--; | ||
| } | ||
| if (prev === 0) return []; | ||
| targetIndent = indentOf(stripComment(lines[prev - 1])); | ||
| walkFrom = prev - 2; |
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.
What does this implement/fix?
Related issue or feature (if applicable):
Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesChecklist
npm run lintpasses.npm run testpasses.