Let the candidate choose the editor indentation width

已关闭
#589 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@princelu1009 已经在做这个了。

开始于 2026年11月5日。

  • #590 来自 @princelu1009 —— 未关闭

评估

这个 Issue 还没有评估数据。

描述

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 #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.

主要语言
Rust
星标
223
派生
148
平均合并
1 天 10 小时
30 天内合并 PR
227

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

sysprog21/codetrial 的其他 Issue

查看 sysprog21/codetrial 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。