Avoid automatic bracket pairing inside comments and strings
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
Problem
Automatic bracket pairing currently inserts a closing bracket inside comments and string literals. In these contexts, an opening bracket may be ordinary text, so inserting an additional closer can interrupt typing.
This behavior was mentioned in #85, which also proposed the core pairing behavior and an optional toggle. Those features have since been addressed through #88, #165, and #252. This proposal focuses specifically on making automatic insertion aware of comments and strings.
Reproduction
With automatic bracket pairing enabled, select C++ in the interview editor.
In the examples below, | represents the caret and is not part of the code.
Line comment
Before typing (:
// note |
Actual result:
// note (|)
Expected result:
// note (|
String literal
Before typing (:
const char* s = "left| ";
Actual result:
const char* s = "left(|) ";
Expected result:
const char* s = "left(| ";
I also reproduced automatic pairing inside a multiline C++ block comment.
These behaviors were reproduced with Chromium against revision 59bde8f. I also inspected web/editor.js and its beforeinput integration at revision 8394d5489630f7ed989cd86835c57647bf7f2e44: the pairing path checks the following character but does not check whether the caret is inside a comment or string.
Proposed behavior
For a collapsed selection, typing (, [, or { inside a recognized comment or string should insert only the typed character.
Outside those contexts, the existing pairing behavior should remain unchanged, including the following-character restriction introduced by #165.
This proposal would preserve:
- Wrapping selected text with brackets.
- Typing over an existing closing bracket.
- Deleting an empty pair with Backspace.
- The Auto-close setting and its persistence.
- Existing undo, paste, and IME behavior.
Tracking which closing brackets were automatically inserted is a separate concern and is outside this proposal.
Implementation approach
I propose checking the lexical context at the caret before attempting automatic pair insertion.
The editor already has language-aware tokenization for syntax highlighting and bracket matching. I would first investigate reusing that classification instead of introducing another independent parser.
The check should use the current editor contents and selected language. It also needs to handle partially typed code and caret positions at string or comment boundaries. If the context cannot be determined reliably, the initial implementation would preserve the existing behavior.
When pairing is suppressed, the handler should allow the browser's normal text insertion to proceed. This would avoid introducing a separate editing path for ordinary typing.
Validation
I would add focused helper tests and browser tests covering:
- Ordinary code where automatic pairing should still occur.
- Line and block comments where supported by the selected language.
- Strings, including escaped quotes and supported multiline forms.
- Caret positions immediately inside and outside comments and strings.
- Switching languages without reusing stale context.
- Selected-text wrapping and the Auto-close setting.
- Undo behavior for both automatic pairing and ordinary insertion.
The browser tests would exercise actual typing in the editor. I would also run the repository's verification script and report any skipped checks.
Scope confirmation
I would like to implement this as a focused follow-up to #85. Does suppressing automatic insertion for collapsed selections inside comments and strings match the intended editor behavior?
Refs #85.
- 主要言語
- Rust
- スター
- 160
- フォーク
- 64
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 114
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
sysprog21/codetrial のほかの issue
-
Highlight the active line in the code editor対応中かも @ArthurArthurArthur0817 が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
sysprog21/codetrial#247 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Include local time in downloaded report filenames対応中かも @106081011 が今日担当しました。 オープン
sysprog21/codetrial#309 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
メンテナーはふだん 1 日以内に返信
-
Preserve test run history対応中かも @yunhsuan0510 が 1 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
sysprog21/codetrial#301 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Standardize section header and toggle indicator styles for test panel対応中かも @kumi222 が 2 日前に担当しました。 オープン
sysprog21/codetrial#298 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
sysprog21/codetrial の issue をすべて見る
似ている issue
-
agent:triaged bug bughunt pm:bundler priority:p1
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
SocketDev/socket-patch#1573 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
bytecodealliance/rustix#1706 · コメント 1 件 ·
メンテナーはふだん 11 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
wormhole-foundation/wormhole#5062 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信