Skip to content

Let the candidate choose the editor indent width - #590

Merged
jserv merged 1 commit into
sysprog21:mainfrom
princelu1009:editor-indent-width
Nov 6, 2026
Merged

jserv merged 1 commit into
sysprog21:mainfrom
princelu1009:editor-indent-width

Conversation

@princelu1009

@princelu1009 princelu1009 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

The code editor always indented by four spaces (INDENT in web/editor.js), while 130 of the 151 JavaScript starters indent by two, so the first Tab or Enter inside a JavaScript starter function produced a body at a different width from the line above it, and a candidate who writes two-space or tab-indented code had no way to change it.

The lobby's editor options gain an Indentation select with 2 spaces, 4 spaces (the default) and Tab. The choice is saved in the browser and forwarded to the interview in a new editorIndent URL parameter. Four spaces keeps the editor exactly as main has it. Under another choice, a starter with an indented block sets one space width for the buffer, used by unindented and space-indented lines alike (bufferIndent in web/indent-guides.js, which shares detectWidth's voting over space-indented lines only); the choice applies where the starter measures none, as in the JavaScript and C starters written with an empty body. A tab-indented line keeps tabs, and a blank line follows the nearest non-blank line above it, so a blank line inside a tab-indented block takes a tab. That width is measured once from the starter, never from the live buffer, so Tab, a language switch, Restore, undo or a paste cannot change it, Tab and Shift+Tab stay exact opposites, and a four-space Python starter stays four-space under a two-space or tab choice instead of raising IndentationError or TabError. Enter at the end of a line, with nothing selected, above a block that already has a deeper body matches that body, skipping lines the tokenizer marks as comment-only (line, block or doc comments) since a comment may sit at any column, so pasted code keeps its own width. indentSelection and indentNewline take the unit as an argument, which interview.js hands to the code workspace (web/workspace.js) through its controller, and a block Tab or Shift+Tab resolves it for each selected line. Shift+Tab takes back one level: a single tab, or up to one unit's width of spaces, where the tab unit counts as four columns to match tab-size: 4.

Four spaces leaves no URL parameter and no stored value, so existing interview URLs behave as before, and the 66 existing tests in tests/browser/editor.test.js pass unmodified. The task page is unchanged, as agreed in #589: it honors none of the lobby's editor options today. The interview start payload pinned in tests/web/contract.rs does not change, since this is a display preference neither Jim nor the report needs.

Validation: new cases in tests/browser/editor.test.js (each unit for Tab, block indent and outdent, Enter after { and a Python :, a selection mixing tab and space functions, followingIndent), tests/browser/editor-options.test.js (round-trip, unknown values fall back to four, only known values are stored), tests/browser/lobby.test.js (the select survives a reload, is disabled for the whiteboard and reaches the interview URL), tests/browser/indent-guides.test.js (bufferIndent returns null with no space-indented block, the width otherwise, ignoring tab-indented lines) and tests/browser/editor-pipeline.test.js on the real interview page (editorIndent=2 and tab, a four-space Python starter under each, Tab then a language switch then Shift+Tab on the two-space JavaScript starter, Enter over a pasted four-space Python body under editorIndent=2, two Tab presses on a blank line of the Python starter under 2 and tab, and Enter with text after the caret, a closer after it, or a selection, above a deeper line, Enter over a two-space line or block comment above a four-space body, and Tab on a blank line inside a tab-indented block). Restoring the old editor.js, removing the unit arguments in web/interview.js, applying one unit to a whole selection, dropping followingIndent, measuring the width from the live buffer, letting unindented lines take the choice over a measured starter, consulting the body below for a selection or mid-line caret, counting a comment line as the body, dropping the look at the line above, letting a non-blank line take a tab from above, skipping only line comments, dropping the workspace's unit arguments, or not short-circuiting the default each fails a test. The full browser suite passes except media-probe.test.js's WebRTC tone test, which fails the same way on clean main here; ./scripts/test.sh on macOS passes everything this change touches, and the lanes that fail (cargo-test's connection-drain timeout under load, task-authoring's timing ratio, run-budget, interactive-review-hook's /private/var path, and six git-hooks checks needing shellcheck, ruff or network) fail the same way on clean main. Not run: a manual check in a live interview.

Screenshots

Lobby: the new Indentation choice in Editor options

Lobby editor options with Indentation set to 2 spaces

JavaScript with 2 spaces: Enter after { nests by two at each level

JavaScript editor nesting by two spaces

Close #589


Summary by cubic

Lets candidates choose 2 spaces, 4 spaces, or Tab for the editor's indentation in the lobby, instead of the fixed four spaces. The choice is saved in the browser and forwarded to the interview via an editorIndent URL parameter, and drives Tab, Shift+Tab, and auto-indent after Enter. Four spaces remains the default and leaves no URL parameter, so existing interview URLs and the task page behave exactly as before. Closes #589.

  • Nested width follows the code it nests into: tab-indented lines keep tabs, space-indented lines use the current language's starter width (measured once per starter and cached), and Enter above a body that is already there matches that body's indentation.
  • A four-space Python starter stays four-space under a two-space or Tab choice instead of raising an IndentationError, and a space-indented line nests with spaces under the Tab unit; Shift+Tab takes back one level per line, counting a Tab as four columns.

Written for commit 4b4385a. Summary will update on new commits.

View guided diff

cubic-dev-ai[bot]

This comment was marked as resolved.

@jserv jserv added the explained label Nov 5, 2026
jserv

This comment was marked as outdated.

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide some screenshots of your changes (some frontend changes in this PR)

Comment thread web/interview.js Resolved
Comment thread web/editor.js Resolved
Comment thread web/editor.js Resolved
cubic-dev-ai[bot]

This comment was marked as resolved.

jserv

This comment was marked as outdated.

@jserv

jserv commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Screenshots at a155276:
Lobby: the new Indentation choice in Editor options

Include screenshots in the pull request description rather than in the comments.

Comment thread web/interview.js Resolved
Comment thread web/indent-guides.js Resolved
Comment thread web/editor.js Resolved
Comment thread web/editor-options.js Resolved
jserv

This comment was marked as outdated.

cubic-dev-ai[bot]

This comment was marked as resolved.

Comment thread web/editor.js Resolved
Comment thread web/interview.js Resolved
Comment thread web/interview.js Resolved
Comment thread web/interview.js Resolved
jserv

This comment was marked as outdated.

Comment thread web/editor.js Resolved
Comment thread web/interview.js Resolved
Comment thread web/editor.js Resolved
jserv

This comment was marked as outdated.

jserv

This comment was marked as outdated.

Comment thread web/editor.js Resolved
Comment thread web/editor.js Resolved
jserv

This comment was marked as outdated.

cubic-dev-ai[bot]

This comment was marked as resolved.

@sysprog21 sysprog21 deleted a comment from princelu1009 Nov 6, 2026
jserv
jserv previously requested changes Nov 6, 2026

@jserv jserv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase onto latest main branch and resolve conflicts.

Comment thread web/interview.js Resolved
Comment thread web/editor.js Resolved
The editor always indented by four spaces, while 130 of the 151
JavaScript starters indent by two, so the first Tab or Enter inside a
starter function broke its indentation and a candidate had no way to
pick another width.

The lobby's editor options gain an Indentation choice of two spaces,
four spaces or a tab. Four spaces stays the default, leaves no URL
parameter and keeps the editor exactly as it was, so existing interview
URLs and the task page behave as before. Under another choice, a starter
with an indented block sets one space width for the buffer, measured
once from the starter rather than the live buffer, so a four-space
Python starter stays four-space instead of raising IndentationError or
TabError; the choice applies where the starter measures none. Enter at
the end of a line above a deeper body matches that body, past any
comment-only lines, so pasted code keeps its width. Tab and Shift+Tab
treat each selected line by its own leading character: a tab line moves
by a tab, a space line by the space width, and a blank line follows the
nearest code above it.

Close sysprog21#589

Change-Id: Iae59277d8424dd3730257d256ce546e5d2f162ea
@jserv
jserv dismissed stale reviews from themself November 6, 2026 14:40

No merge conflicts at the current head.

jserv

This comment was marked as outdated.

@jserv
jserv merged commit 066644e into sysprog21:main Nov 6, 2026
13 of 14 checks passed
@jserv

jserv commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Thank @princelu1009 for contributing!

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.

Let the candidate choose the editor indentation width

3 participants