Skip to content

Experiment regarding sticky scroll for yaml#327

Open
stvncode wants to merge 1 commit into
mainfrom
sticky-scroll
Open

Experiment regarding sticky scroll for yaml#327
stvncode wants to merge 1 commit into
mainfrom
sticky-scroll

Conversation

@stvncode
Copy link
Copy Markdown
Collaborator

@stvncode stvncode commented May 13, 2026

What does this implement/fix?

Related issue or feature (if applicable):

  • fixes

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — docs
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • npm run lint passes.
  • npm run test passes.
  • Tests have been added to verify that the new code works (where applicable).

@stvncode stvncode self-assigned this May 13, 2026
Copilot AI review requested due to automatic review settings May 13, 2026 19:36
@stvncode stvncode added the enhancement Improvement to an existing feature label May 13, 2026
@github-actions github-actions Bot added new-feature New feature and removed enhancement Improvement to an existing feature labels May 13, 2026
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

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

YAML editor: sticky scroll missing (regression from legacy dashboard)

2 participants