feat(editor): add auto_close_pairs setting#9711
Conversation
autoclose Adds a new `auto_close_pairs` config option under `CompletionConfig` that controls whether CodeMirror's closeBrackets extension is active. When disabled, typing an opening bracket, parenthesis, or quote will not automatically insert the closing character. Exposed as a checkbox in Settings → Editor → Autocomplete. Defaults to true (enabled) to preserve existing behavior.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new auto_close_pairs user setting that controls whether CodeMirror automatically inserts closing brackets/quotes when typing the opening character.
Changes:
- New
auto_close_pairsfield added to backend (CompletionConfigTypedDict + default config) and frontend schema/OpenAPI types. - CodeMirror setup conditionally registers
closeBrackets()and its keymap based on the new setting. - New UI form field in the user config form and a unit test verifying the keymap behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/openapi/src/api.ts | Adds auto_close_pairs to generated TS API types and JSDoc. |
| packages/openapi/api.yaml | Adds auto_close_pairs property to OpenAPI schema. |
| marimo/_config/config.py | Adds auto_close_pairs field and default value to Python config. |
| frontend/src/core/config/config-schema.ts | Adds auto_close_pairs to Zod schema with default true. |
| frontend/src/core/config/tests/config-schema.test.ts | Updates snapshot tests for new default. |
| frontend/src/core/codemirror/cm.ts | Conditionally enables closeBrackets extension and keymap. |
| frontend/src/core/codemirror/tests/setup.test.ts | Adds test ensuring keymap is removed when disabled. |
| frontend/src/components/app-config/user-config-form.tsx | Adds a checkbox UI control for the new setting. |
|
@kirangadhave I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 15 files
Architecture diagram
sequenceDiagram
participant User
participant UI as Settings UI
participant ConfigSchema as Config Schema (Zod)
participant CodeMirror as CodeMirror Editor
participant Backend as Python Backend
Note over User,Backend: NEW: Auto-close pairs configuration flow
User->>UI: Toggle "Auto-close pairs" checkbox
UI->>ConfigSchema: Update completion.auto_close_pairs
ConfigSchema-->>UI: Validated value (default: true)
alt auto_close_pairs === false
UI->>UI: Disable checkbox unchecked
UI->>CodeMirror: NEW: Set autoClosePairs = false
CodeMirror->>CodeMirror: Conditionally exclude closeBrackets() and closeBracketsKeymap
Note over CodeMirror: stringsAutoCloseBraces() still active
CodeMirror-->>User: Typing "(" does NOT insert ")"
else auto_close_pairs === true (default)
UI->>UI: Enable checkbox checked
UI->>CodeMirror: NEW: Set autoClosePairs = true
CodeMirror->>CodeMirror: Include closeBrackets() and closeBracketsKeymap
CodeMirror-->>User: Typing "(" inserts ")"
end
Note over UI,Backend: Configuration persistence
UI->>Backend: POST /api/config with {completion: {auto_close_pairs: bool}}
Backend->>Backend: Validate against CompletionConfig schema
alt auto_close_pairs not provided
Backend->>Backend: Use default value (true)
end
Backend-->>UI: Config saved confirmation
UI-->>User: Setting persisted
Note over Backend,CodeMirror: OpenAPI spec auto-generated
Backend->>Backend: Update openapi.yaml with auto_close_pairs field
Backend-->>ConfigSchema: TypeScript types regenerated via openapi.ts
| <code className="text-xs">{"[]"}</code>,{" "} | ||
| <code className="text-xs">{"{}"}</code>, and quotes{" "} | ||
| <code className="text-xs">{`""`}</code>,{" "} | ||
| <code className="text-xs">{`''`}</code> when opening one. |
There was a problem hiding this comment.
Does this not cover backticks (``)?
There was a problem hiding this comment.
No, backtick are not auto inserted to begin with I believe.
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.9-dev17 |
📝 Summary
Closes #9679
Adds an
auto_close_pairssetting toCompletionConfigthat lets users disable the automatic insertion of closing brackets, parentheses, and quotes when typing an opening character. This was requested by users who find the default auto-close behavior disruptive.The setting defaults to
true(enabled) so existing behavior is unchanged for everyone who doesn't touch it.Verified this change manually.
Changes:
marimo/_config/config.py: Addedauto_close_pairs: NotRequired[bool]toCompletionConfigwith docstring, and"auto_close_pairs": TruetoDEFAULT_CONFIG.frontend/src/core/config/config-schema.ts: Addedauto_close_pairs: z.boolean().prefault(true)to the Zod schema so the TypeScript type is derived automatically.frontend/src/core/codemirror/cm.ts:closeBrackets()andPrec.high(keymap.of(closeBracketsKeymap))are now conditional oncompletionConfig.auto_close_pairs !== false.stringsAutoCloseBraces()is left unconditional per maintainer guidance.frontend/src/components/app-config/user-config-form.tsx: New "Auto-close pairs" checkbox in Settings > Editor > Autocomplete, with helper text listing the affected characters:(),[],{},"",''.packages/openapi/api.yamlandpackages/openapi/src/api.ts: Regenerated from the updated Python types.📋 Pre-Review Checklist
✅ Merge Checklist