# Fix incorrect rainbow bracket matching in Markdown \(\#52107\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/e8d2627ef594347afd790b302b59130e0c72f076)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: e8d2627ef594347afd790b302b59130e0c72f076

Requested commit: e8d2627ef594347afd790b302b59130e0c72f076

Commit: e8d2627ef594347afd790b302b59130e0c72f076

Tree: ffb489d3c889b32ae1e2f981ff64cada7518df05

Author: Kai Kozlov

Committer: GitHub

## Message

```
Fix incorrect rainbow bracket matching in Markdown (#52107)

## Context

Fixes #52022.

Rainbow bracket matching could become incorrect when tree-sitter
returned ambiguous bracket pairs for the same opening delimiter. The
repair path rebuilt pairs using a shared stack across all bracket query
patterns, which let excluded delimiters like Markdown single quotes
interfere with parenthesis matching.

This change scopes that repair logic to each bracket query pattern so
ambiguous matches are rebuilt without mixing unrelated delimiter types.
It also adds a regression test for the Markdown repro from the issue.

<img width="104" height="137" alt="image"
src="https://github.com/user-attachments/assets/4318bb4d-7072-4671-8fb5-c4478a179c07"
/>

<img width="104" height="137" alt="image"
src="https://github.com/user-attachments/assets/07a8a0fc-7618-4edb-a14e-645358d8d307"
/>


## How to Review

Review `crates/language/src/buffer.rs` first, especially the fallback
repair path for bogus tree-sitter bracket matches.

Then review `crates/editor/src/bracket_colorization.rs`, which adds
regression coverage for the issue repro.

## Self-Review Checklist

<!-- Check before requesting review: -->
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed rainbow brackets in Markdown when quotes caused parentheses to
match incorrectly
```

## Parents

- [e1268577321e7b48596166701b6f061b255b441a](https://git.cafe/gitcafe/zed/commit/e1268577321e7b48596166701b6f061b255b441a?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/e8d2627ef594347afd790b302b59130e0c72f076?format=markdown)
