Repository navigation
Draw indent guides in the code editor - #267
Merged
Merged
Conversation
jserv
requested changes
Oct 9, 2026
jserv
left a comment
Contributor
There was a problem hiding this comment.
Rebase latest main branch and resolve conflicts.
jserv
reviewed
Oct 9, 2026
sidney-Hung
force-pushed
the
editor-indent-guides
branch
from
October 9, 2026 03:15
dcdefce to
22fb99e
Compare
Contributor
Author
|
Rebased onto main and added |
ColtenOuO
reviewed
Oct 9, 2026
A candidate writing nested loops or branches in the plain textarea has no visual cue for which block a line belongs to, and Python makes that the difference between correct and broken code. The highlighter wraps each level of a line's leading whitespace in a guide, so the guides share the overlay's layout and scroll instead of needing a layer of their own. The level width is measured from the buffer, because the starters indent by two in JavaScript and by four elsewhere; the cost is that a buffer mixing both widths gets guides at the narrower one.
sidney-Hung
force-pushed
the
editor-indent-guides
branch
from
October 9, 2026 19:01
22fb99e to
cb8d07f
Compare
Contributor
Author
|
Pushed an update addressing the review comments, and updated the PR description to match. |
ColtenOuO
approved these changes
Oct 9, 2026
ColtenOuO
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, thanks for working on this.
Contributor
|
Thank @sidney-Hung for contributing! |
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.
Summary
The code editor is a plain textarea, so when writing nested loops or branches there is no visual cue for which block a line belongs to. In Python that cue decides whether the code is correct. This adds vertical indent guides to the interview editor, one per indent level.
How it works
The syntax highlighter draws the guides, so they share the overlay's layout and scroll instead of needing a layer of their own. The textarea is unchanged.
web/indent-guides.js(new):indentGuides(code, tokens)measures the level width and returns one run per line that has guides: the line's leading whitespace wrapped in<span class="indent-guide">elements.web/highlight.js:highlight()splices each run into the line's leading whitespace.web/interview.js: passes the runs to the highlighter, and re-syncs the overlay's scroll after each paint (see below).web/styles.css: guide style, plus a--code-guidetoken next to--code-gutter-border:#404040in the dark theme and#d3d3d3, VS Code Light+'s indent-guide color, in both light-theme blocks.Design notes
web/editor.jsinserts for Tab. Lines continuing a comment or string don't vote, since a doc comment's*body would otherwise measure 1. JavaScript starters come out at 2; Python, Java, C and C++ at 4.*.scrollTopto the old height and leave every row one above its code. The overlay's scroll is now re-synced when each paint finishes.web/editor.jsinserts gets guides at 2. Making Enter and Tab insert the detected width is left for a separate change.Screenshot
Tests
tests/browser/indent-guides.test.js(new, 21 tests): width detection, partial levels, whitespace-only lines, comment and string lines, HTML escaping.tests/browser/editor-font-size.test.js: a regression test for the scroll fix, which fails with the post-paint re-sync removed.Closes #254