You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Let the candidate choose the editor indentation width #589
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.
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).
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.
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).
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
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.
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.
tests/browser/lobby.test.js: the select survives a reload and reaches the interview URL.
A mutation check: with the unit argument ignored (the constant restored), the new cases in 1 fail.
./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.
Activity
jserv commentedon Nov 5, 2026
Provide more details about the components or modules you plan to modify, along with your proposed verification plans.
princelu1009 commentedon Nov 5, 2026
Here is the plan at revision b2c2bc9.
Components to change
web/editor.js: replace theINDENTconstant (line 4) with anindentargument toindentSelectionandindentNewline, defaulting to four spaces so existing callers behave as now. Outdent removes one unit: a single\tfor the tab unit, and up to N leading spaces for N spaces (the/^\t|^ {1,4}/pattern at line 229 becomes unit-dependent).web/editor-options.js: add a non-booleanindentoption carried in a neweditorIndentURL parameter (2ortab; absent means four spaces, and an unknown value falls back to four).editorOptionsFromParams,setEditorOptions,loadEditorOptionsandsaveEditorOptionshandle it beside the existing booleans.web/index.htmlandweb/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-323andapp.js:782).web/interview.js: pass the chosen unit at the two call sites,indentSelection(line 1496) andindentNewline(line 1557).Left unchanged, and why
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.jsalready measures the indentation width from the buffer (2 or 4), and thetab-size: 4rule inweb/styles.csskeeps tab rendering unchanged.tests/web/contract.rs:298does not change. This is a display preference that neither Jim nor the report needs.Verification plan
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.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 noeditorIndentin the URL.tests/browser/lobby.test.js: the select survives a reload and reaches the interview URL../scripts/test.shbefore 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.
Let the candidate choose the editor indent width
Let the candidate choose the editor indent width
Let the candidate choose the editor indent width