Skip to content

Let the candidate choose the editor indentation width #589

Open

Description

@princelu1009

The code editor always indents by four spaces. INDENT is a constant in web/editor.js:4 (revision b2c2bc9), and both Tab (indentSelection) and auto-indent on Enter (indentNewline) insert it. Shift+Tab removes at most four leading spaces (/^\t|^ {1,4}/ in indentSelection).

This does not match the starter code the candidate is given. Of the 151 problems in web/problems/, 130 JavaScript starters indent by two spaces, while the Python, C, C++ and Java starters indent by four. In a JavaScript interview, the first Tab or Enter inside the starter function therefore produces a body indented at a different width from the line above it. A candidate who writes two-space or tab-indented code has no way to change this.

This falls under the editor settings gap (indentation) in the HackerRank Mock Interviews comparison of the contribution guide.

Proposed behavior

  • A new editor option, beside the existing ones in web/editor-options.js (autoIndent, autoClose, ...), selects the indentation unit: 2 spaces, 4 spaces (the default, so nothing changes for existing users) or a tab.
  • Tab, Shift+Tab and auto-indent on Enter on the interview page use the selected unit until the buffer has an indented block of its own, then the width that block uses, so a four-space Python starter is not nested at another width (agreed in review on Let the candidate choose the editor indent width #590).
  • Shift+Tab removes one level of the selected unit rather than up to four spaces.
  • The choice is saved the same way as the other editor options.

Out of scope: reformatting code the candidate has already written, and the task page, which honors none of the lobby's editor options today.

Acceptance criteria

  • With 2 spaces selected, Tab at the start of a line inserts two spaces, Enter after { indents the new line by two spaces more than the current one, and Shift+Tab removes two.
  • With tab selected, the same actions insert and remove a single \t.
  • With the default, behavior is unchanged, and the existing tests in tests/browser/editor.test.js pass unmodified.
  • New cases in tests/browser/editor.test.js and tests/browser/editor-options.test.js cover each unit and the saved option, and fail if the unit is ignored.

I am working on this and will open a pull request.

Activity

  1. jserv commented on Nov 5, 2026

    @jserv
    Contributor

    Provide more details about the components or modules you plan to modify, along with your proposed verification plans.

  2. princelu1009 commented on Nov 5, 2026

    @princelu1009
    ContributorAuthor

    Here is the plan at revision b2c2bc9.

    Components to change

    1. web/editor.js: replace the INDENT constant (line 4) with an indent argument to indentSelection and indentNewline, defaulting to four spaces so existing callers behave as now. Outdent removes one unit: a single \t for the tab unit, and up to N leading spaces for N spaces (the /^\t|^ {1,4}/ pattern at line 229 becomes unit-dependent).
    2. web/editor-options.js: add a non-boolean indent option carried in a new editorIndent URL parameter (2 or tab; absent means four spaces, and an unknown value falls back to four). editorOptionsFromParams, setEditorOptions, loadEditorOptions and saveEditorOptions handle it beside the existing booleans.
    3. web/index.html and web/app.js: an "Indentation" select (2 spaces / 4 spaces / Tab) in the lobby's editor options fieldset, saved and forwarded to the interview URL the same way the checkboxes are (app.js:313-323 and app.js:782).
    4. web/interview.js: pass the chosen unit at the two call sites, indentSelection (line 1496) and indentNewline (line 1557).

    Left unchanged, and why

    • The task page (web/task.js:1544, 1566) keeps four spaces: it honors none of the lobby's editor options today, so making it read only this one would be inconsistent. This narrows the issue's "both pages" scope, and I will update the issue text to match.
    • web/indent-guides.js already measures the indentation width from the buffer (2 or 4), and the tab-size: 4 rule in web/styles.css keeps tab rendering unchanged.
    • The interview start payload pinned in tests/web/contract.rs:298 does not change. This is a display preference that neither Jim nor the report needs.

    Verification plan

    1. tests/browser/editor.test.js: for each unit (2 spaces, 4 spaces, tab), test Tab with a caret at column 0 and mid-line, block indent and outdent of a multi-line selection, Shift+Tab on 2-space and tab-indented lines removing exactly one unit, and Enter after { and after a Python :. The existing 66 tests stay unmodified and pass, which pins the default.
    2. tests/browser/editor-options.test.js: a parameter round-trip for each value, an unknown value falling back to four spaces, and the default leaving no editorIndent in the URL.
    3. tests/browser/lobby.test.js: the select survives a reload and reaches the interview URL.
    4. A mutation check: with the unit argument ignored (the constant restored), the new cases in 1 fail.
    5. ./scripts/test.sh before opening the PR, plus a manual check: choose 2 spaces in the lobby, start a JavaScript problem, and confirm Tab and Enter inside the starter function match its two-space body.

    I expect the change to stay well under 200 lines.

  3. added 3 commits that reference this issue on Nov 5, 2026
    a155276
    cd50805
    20b073e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions