Add optional automatic bracket pairing to the code editor
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- frontend
Línea de trabajo
Start by reading web/editor.js for indentNewline and indentSelection, then web/interview.js for event handling and applyIndent. Define the setting, edit behavior, and pair tracking boundaries before implementation, including selection wrapping, delimiter skipping, paired deletion, persistence, IME and paste handling, and conservative comment or string behavior. Done means the requested bracket features preserve indentation and normal undo/redo behavior.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Problem
While writing C++ code in CodeTrial, typing an opening delimiter such as (, {, or [ does not insert its matching closing delimiter. I need to type both sides manually.
During an interview, this adds repetitive typing and can interrupt the flow of explaining my solution while coding.
Current behavior
Typing ( produces:
(|
Here, | represents the cursor.
Expected behavior
With automatic bracket pairing enabled, typing ( should produce:
(|)
The same behavior should apply to {} and [].
This proposal concerns basic editing assistance, not code generation or solution suggestions.
Existing implementation
The current editor already supports indentation:
web/editor.jsprovidesindentNewlineandindentSelection.web/interview.jsconnects these helpers to editor events.indentNewlinerecognizes matching delimiters when arranging a newline between an existing pair, but does not insert a missing closing delimiter.
This feature could build on those editing helpers while remaining separate from automatic indentation.
Proposed behavior
- Add an “Auto-close brackets” setting.
- When enabled, insert the matching closing delimiter and leave the cursor between the pair.
- When text is selected, wrap the selection with the chosen pair.
- When the cursor is immediately before an automatically inserted closing delimiter, typing that delimiter should move past it instead of inserting a duplicate.
- Pressing Backspace between an untouched, automatically inserted empty pair should remove both characters.
- Preserve the existing newline indentation behavior.
The setting should be remembered across page reloads. My preference is to enable it by default while allowing users to disable it for plain-editor practice.
Suggested implementation
Editing helpers
Add pure functions to web/editor.js that compute the updated text and selection without directly changing the DOM.
For example, a helper could receive the current text, selection range, and opening delimiter, then return:
- Updated text.
- Updated selection start and end.
- Information about the automatically inserted pair, if applicable.
The delimiter mapping would be:
const BRACKET_PAIRS = {
"(": ")",
"[": "]",
"{": "}",
};
Event handling
In web/interview.js, handle direct delimiter input through beforeinput, alongside the existing newline handling.
The handler should:
- Respect the user setting.
- Ignore IME composition.
- Avoid transforming paste operations.
- Only intercept supported, cancelable input events.
- Apply edits through an undo-preserving editing path.
The existing applyIndent helper could be generalized to apply editor edits, rather than adding a separate implementation that directly replaces the textarea value.
Pair tracking
Track automatically inserted pairs so that closing-delimiter skipping and paired deletion do not accidentally affect unrelated, manually entered characters.
Update or invalidate tracked pairs after edits. Clear stale tracking when the editor content is replaced or the programming language changes.
Language context
Avoid inserting unwanted pairs inside comments or string literals.
The existing indentation helper does not maintain full multiline lexical state, so it should not be treated as a complete parser for this purpose. A conservative first implementation could limit pairing to contexts it can confidently identify.
Requested features
I would like the editor to support the following features:
- Automatically insert the matching closing bracket when typing
(,[, or{, with the cursor placed between the pair. - Wrap selected text in a bracket pair without replacing the selected content.
- Allow typing past an automatically inserted closing bracket without creating a duplicate.
- Remove both brackets when pressing Backspace inside an automatically inserted empty pair.
- Keep the existing automatic indentation when pressing Enter between braces.
- Provide a setting to enable or disable automatic bracket pairing.
It would also be helpful to preserve normal undo/redo behavior and avoid interfering with IME input, pasted text, comments, or strings.
Related work
Issue #61 discusses syntax-aware automatic indentation:
https://github.com/sysprog21/codetrial/issues/61
This proposal addresses inserting matching delimiters while typing, which is separate from indentation after pressing Enter.
- Lenguaje dominante
- Rust
- Estrellas
- 144
- Forks
- 41
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 94
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de sysprog21/codetrial
-
Highlight the active line in the code editorPosiblemente ocupada @ArthurArthurArthur0817 la tomó hace 4 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
sysprog21/codetrial#247 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Downloaded markdown reports use internal lowercase keys instead of display labels for programming languagesPosiblemente ocupada @SkyDrive2 la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
sysprog21/codetrial#246 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Adopt a frontend frameworkAbiertoenhancement help wanted
Dificultad 5/5 Más de una semana Aptitud para principiantes 12/100
sysprog21/codetrial#270 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Support configurable and randomized interviewer voices and accentsPosiblemente ocupada @MorganHo001 la tomó hace 3 días. Abierto
sysprog21/codetrial#261 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
sysprog21/codetrial#258 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de sysprog21/codetrial
Issues similares
-
C-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
rust-lang/rust-analyzer#23501 ·
Los mantenedores suelen responder en 1 día
-
Streamable HTTP client: a 401 or 403 with a JSON-RPC error body and no WWW-Authenticate loses its HTTP statusPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug P2 ready for work T-security T-transport
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
modelcontextprotocol/rust-sdk#1339 ·
Los mantenedores suelen responder en 3 días
-
French BIP39 wordlist starts with a UTF-8 BOM, so generated French mnemonics carry U+FEFF and derive a non-canonical seedPosiblemente ocupada @Kshot3000 la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
ergoplatform/sigma-rust#976 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
[Bug]: Web chat input doesn't regain focus after a reply finishesPosiblemente ocupada @GaijinSystems la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
zeroclaw-labs/zeroclaw#11658 ·
Los mantenedores suelen responder en 2 días