Skip to content

Add surround pairs#41

Merged
MrSubidubi merged 6 commits intozed-extensions:mainfrom
George-Miao:patch-1
Mar 26, 2026
Merged

Add surround pairs#41
MrSubidubi merged 6 commits intozed-extensions:mainfrom
George-Miao:patch-1

Conversation

@George-Miao
Copy link
Copy Markdown
Contributor

This PR adds support for surrounding words with asterisk (bold), underscore (italic) and backquote (code).

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Nov 20, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @George-Miao on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@George-Miao
Copy link
Copy Markdown
Contributor Author

@cla-bot check

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Nov 20, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @George-Miao on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Nov 20, 2025

The cla-bot has been summoned, and re-checked this pull request!

@George-Miao
Copy link
Copy Markdown
Contributor Author

@cla-bot check

@cla-bot cla-bot bot added the cla-signed label Nov 20, 2025
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Nov 20, 2025

The cla-bot has been summoned, and re-checked this pull request!

@WeetHet
Copy link
Copy Markdown
Collaborator

WeetHet commented Nov 20, 2025

Wouldn't adding * break math mode (I personally use a show rule replacing it with dot) since it would input twice? I'm not sure if it would, just checking

@George-Miao
Copy link
Copy Markdown
Contributor Author

Wouldn't adding * break math mode (I personally use a show rule replacing it with dot) since it would input twice? I'm not sure if it would, just checking

It's only surrounding so I assume it will be really hard to break by accident. Also this is what typst vscode plugin does so.

@MrSubidubi MrSubidubi changed the title feat: surround pairs Add surround pairs Dec 12, 2025
@MrSubidubi
Copy link
Copy Markdown
Contributor

Thanks for this!

If we are afraid of breaking math mode, could we not add an override in overrides.scm to prevent that?

@George-Miao
Copy link
Copy Markdown
Contributor Author

George-Miao commented Dec 13, 2025

Thanks for this!

If we are afraid of breaking math mode, could we not add an override in overrides.scm to prevent that?

I think it's a good idea to disable the surrounding behavior in math mode, though I'm not really familiar with zed's scope override rule. I did find the document. Can you elaborate more?

@MrSubidubi
Copy link
Copy Markdown
Contributor

You can add scopes in the overrides.scm for where this autoclose behavior should not trigger and then reference this in the not_in section. We usually do this for strings, e.g. you can say not_in = ["string"], so that the autoclose behavior will not trigger whenever you are in a string. We could do the same for the math mode here, so add a math override scope and disable the autoclosing in math blocks. https://github.com/zed-extensions/kotlin/blob/main/languages/kotlin/overrides.scm is an example for the overrides file and you see these overrides referenced in https://github.com/zed-extensions/kotlin/blob/main/languages/kotlin/config.toml

Copilot AI review requested due to automatic review settings March 26, 2026 11:47
MrSubidubi
MrSubidubi previously approved these changes Mar 26, 2026
Copy link
Copy Markdown
Contributor

@MrSubidubi MrSubidubi left a comment

Choose a reason for hiding this comment

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

Picked this up myself, thanks for the initial stuff! And congrats to your first contribution!

@MrSubidubi MrSubidubi enabled auto-merge (squash) March 26, 2026 11:48
Copy link
Copy Markdown

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

Adds “surround selection” delimiter pairs for Typst markup so users can wrap text with * (bold), _ (italic), and ` (code), with basic context exclusions (e.g., avoiding * in math).

Changes:

  • Add Typst bracket/surround pair definitions for *, _, and ` in config.toml.
  • Add Tree-sitter override captures for string and math scopes to support context-aware behavior.
  • Regenerate Cargo.lock (lockfile format/version and crate version metadata).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
languages/typst/overrides.scm Adds captures (@string, @math) used for context-aware editor features (e.g., not_in).
languages/typst/config.toml Defines new surround pairs for *, _, and ` and restricts * inside math.
Cargo.lock Updated generated lockfile (format v4) and zed_typst package version entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread languages/typst/config.toml Outdated
{ start = "*", end = "*", close = false, newline = false, surround = true, not_in = [
"math"
] },
{ start = "_", end = "_", close = false, newline = false, surround = true },
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

_ is a math operator in Typst (subscript/attach), so enabling it as a surround pair inside (math) will likely interfere with normal math editing. Consider adding not_in = ["math"] to the underscore surround entry (similar to the * entry) so it only applies in markup/text contexts.

Suggested change
{ start = "_", end = "_", close = false, newline = false, surround = true },
{ start = "_", end = "_", close = false, newline = false, surround = true, not_in = [
"math"
] },

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +18
{ start = "*", end = "*", close = false, newline = false, surround = true, not_in = [
"math"
] },
{ start = "_", end = "_", close = false, newline = false, surround = true },
{ start = "`", end = "`", close = false, newline = false, surround = true },
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The new surround pairs are defined in config.toml, but languages/typst/brackets.scm currently only declares bracket tokens for ()[]{} plus " and $. If Zed relies on brackets.scm to recognize bracket-like delimiters, *, _, and ` may not work for matching/surrounding until they’re also added to brackets.scm (keeping it in sync with the brackets = [...] list).

Suggested change
{ start = "*", end = "*", close = false, newline = false, surround = true, not_in = [
"math"
] },
{ start = "_", end = "_", close = false, newline = false, surround = true },
{ start = "`", end = "`", close = false, newline = false, surround = true },

Copilot uses AI. Check for mistakes.
@MrSubidubi MrSubidubi merged commit cff942b into zed-extensions:main Mar 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants