Skip to content

feat(editor): add auto_close_pairs setting#9711

Merged
kirangadhave merged 4 commits into
marimo-team:mainfrom
nojaf:auto_close_pair_setting
May 28, 2026
Merged

feat(editor): add auto_close_pairs setting#9711
kirangadhave merged 4 commits into
marimo-team:mainfrom
nojaf:auto_close_pair_setting

Conversation

@nojaf
Copy link
Copy Markdown
Contributor

@nojaf nojaf commented May 28, 2026

📝 Summary

Closes #9679

Adds an auto_close_pairs setting to CompletionConfig that 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.

image

Changes:

  • marimo/_config/config.py: Added auto_close_pairs: NotRequired[bool] to CompletionConfig with docstring, and "auto_close_pairs": True to DEFAULT_CONFIG.
  • frontend/src/core/config/config-schema.ts: Added auto_close_pairs: z.boolean().prefault(true) to the Zod schema so the TypeScript type is derived automatically.
  • frontend/src/core/codemirror/cm.ts: closeBrackets() and Prec.high(keymap.of(closeBracketsKeymap)) are now conditional on completionConfig.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.yaml and packages/openapi/src/api.ts: Regenerated from the updated Python types.

📋 Pre-Review Checklist

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes (optional).

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Tests have been added for the changes made.

 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.
Copilot AI review requested due to automatic review settings May 28, 2026 09:19
@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment May 28, 2026 12:47pm

Request Review

@github-actions github-actions Bot added the bash-focus Area to focus on during release bug bash label May 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_pairs field added to backend (CompletionConfig TypedDict + 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.

Comment thread frontend/src/core/codemirror/cm.ts Outdated
Comment thread frontend/src/components/app-config/user-config-form.tsx Outdated
@kirangadhave
Copy link
Copy Markdown
Member

@cubic-dev-ai

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented May 28, 2026

@cubic-dev-ai

@kirangadhave I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Re-trigger cubic

Copy link
Copy Markdown
Member

@kirangadhave kirangadhave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

<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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not cover backticks (``)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, backtick are not auto inserted to begin with I believe.

@kirangadhave kirangadhave merged commit 7110967 into marimo-team:main May 28, 2026
45 of 47 checks passed
@github-actions
Copy link
Copy Markdown

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.9-dev17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow disabling auto-close brackets in the cell editor

3 participants