# editor: Add SelectInsideDelimiters and SelectAroundDelimiters actions \(\#53789\) · gitcafe/zed

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

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

Visibility: public

Requested revision: f2fbe40b5daf106ffb34861bcc3580a35ac8cca4

Requested commit: f2fbe40b5daf106ffb34861bcc3580a35ac8cca4

Commit: f2fbe40b5daf106ffb34861bcc3580a35ac8cca4

Tree: 77ff9b7133bb3ebaff89002fb4829b3e61700c09

Author: subeax

Committer: GitHub

## Message

```
editor: Add SelectInsideDelimiters and SelectAroundDelimiters actions (#53789)

## Summary

Adds two new editor actions:
- `editor::SelectInsideDelimiters`: selects the content inside the
nearest enclosing delimiters. Works for `()`, `[]`, `{}`, and string
literals (`""`, `''`, `` ` ` ``).
- `editor::SelectAroundDelimiters`: same as above, but the selection
includes the surrounding delimiters themselves.

This addresses the request in #50042

## Why not `select_larger_syntax_node`?

`SelectLargerSyntaxNode` walks up the AST one level at a time. It's an
incremental, history-aware operation: press repeatedly to expand outward
by syntax tree level. The number of presses needed to reach a specific
delimiter pair depends on the language's AST shape and is unpredictable:
sometimes one press, sometimes three, sometimes overshoot.

`SelectInsideDelimiters` is delimiter-based and stateless: one
invocation jumps directly to the nearest enclosing pair, regardless of
AST nodes. It's the equivalent of Vim's `vi(`, `vi{`, `vi"` text
objects, available without requiring Vim mode. The two actions solve
different problems.

## Implementation

Both actions use
`MultiBufferSnapshot::innermost_enclosing_bracket_ranges`, which already
handles nesting, multi-buffer excerpts, and language-specific bracket
definitions, including languages where quotes are declared as bracket
pairs (Rust, Python, JavaScript, JSON, etc.).

For string-like content where the language does not register quotes as
brackets (notably Markdown inline content), `SelectInsideDelimiters`
additionally falls back to a `syntax_ancestor` check for tree-sitter
node kinds `string_content` and `inline`. This is the same set of node
kinds already used in `select_larger_syntax_node`.

Multi-cursor support comes from `move_offsets_with`.

## Tests

Two new tests in `editor_tests.rs` covering:
- Basic delimiter selection (parens, brackets, braces)
- Innermost detection with nested pairs
- String content selection (TypeScript)
- Selection expansion when starting from an existing selection
- No-op when cursor is not inside any delimiter

## Notes

No default keybindings are provided. Users can bind via their keymap.
Can add defaults if reviewers prefer.

Self-Review Checklist:
- [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

Closes #50042

Release Notes:

- Added `editor::SelectInsideDelimiters` and
`editor::SelectAroundDelimiters` actions for selecting content within
the nearest enclosing brackets, braces, parentheses, or quotes.

---------

Co-authored-by: dino <dinojoaocosta@gmail.com>
```

## Parents

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

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