Skip to content

Avoid pairing brackets in comments and strings - #308

Open
Jonathas2127 wants to merge 3 commits into
sysprog21:mainfrom
Jonathas2127:fix/context-aware-bracket-pairing
Open

Jonathas2127 wants to merge 3 commits into
sysprog21:mainfrom
Jonathas2127:fix/context-aware-bracket-pairing

Conversation

@Jonathas2127

@Jonathas2127 Jonathas2127 commented Oct 14, 2026 •

Copy link
Copy Markdown

Typing an opening bracket inside a comment or string currently inserts an unwanted closer. For example, typing ( after // note produces // note (). This change inserts only the typed character in those contexts while retaining pairing in code and wrapping selected text.

The pairing handler reuses the existing tokenizer to classify the inserted character, including at end-of-buffer and in unfinished literals. Parser preparation also runs when Auto-close is enabled independently of highlighting and indentation, with the existing scanner handling parser unavailability.

Validation:

  • Nine C++ reproduction cases failed before the fix and pass afterward.
  • Focused editor tests: 91 passed, no failures or skips.
  • ./scripts/test.sh completed successfully; the Node/browser suite reported 1,165 passed, no failures or skips.
  • Git hook suite: 49 checks passed.
  • Prettier, ESLint, and git diff --check passed.
  • cargo-audit, actionlint, and ruff were unavailable and skipped; the hook run also skipped commentflow.

Closes #307


Summary by cubic

Typing an opening bracket inside a comment or string no longer inserts a matching closer. For example, typing ( after // note stays // note ( instead of // note (), while pairing in code, wrapping selected text, and f-string interpolation expressions all still work. This holds even when the parser is unavailable or returns an error tree for unfinished f-strings. Typing a closer or pressing Backspace inside a literal now also leaves the text to native editing, so existing closers aren't skipped or deleted.

The change reuses the existing tokenizer to classify the inserted character, including at end-of-buffer and in unfinished literals. Python f-strings keep pairing inside expressions while ordinary strings stay literal, and unknown languages keep the previous behavior. Parser preparation now also runs when auto-close is enabled independently of highlighting and indentation.

Closes #307

Written for commit 8fe829b. Summary will update on new commits.

View guided diff

Bracket auto-close inserts unwanted delimiters in comments and strings.
Use the shared lexical context while preserving native insertion and
selection wrapping. Keep pairing independent of syntax highlighting.
cubic-dev-ai[bot]

This comment was marked as resolved.

Comment thread web/editor.js Outdated
Comment thread web/editor.js Outdated
Literal-aware insertion must not let Backspace delete existing closers.
Keep bracket edits consistent and preserve f-string expressions when
parsing is unavailable. Verify parser loading through editor behavior.
cubic-dev-ai[bot]

This comment was marked as resolved.

Unfinished f-strings can produce a syntax tree with parsing errors.
Match the tokenizer's fallback condition when a tree contains errors.
Preserve bracket insertion, deletion, and type-over behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid automatic bracket pairing inside comments and strings

2 participants