nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects

How to target the object and include the before text?

Open
#71 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Tree-sitter Query
Stars
2.8k
Forks
271
Avg merge
8d 8h
Merged PRs (30d)
1

Description

For example, in jsx, the each attribute of element are split by <space>.
But Treesitter doesn't include the separator(space).

截屏2021-06-17 下午8 44 57

When I delete this textobj(test={true}), the `' before is still there.
This is correct, but it is inconvenient.

截屏2021-06-17 下午8 47 39

Then I need to delete that space manually.

图片

So, is there any to target the attribute, but also include the space(one or more) before?

and here's my config now.

; jsx attributes
(jsx_self_closing_element attribute: (_) @attribute.outer)
(jsx_element open_tag: (_ attribute: (_) @attribute.outer))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the JSX attribute query patterns shown in the issue and inspect how captured @attribute.outer nodes are turned into text-object ranges. Check how preceding whitespace is handled for deletion, then verify the behavior on the JSX examples described in the issue. Done means targeting an attribute can include its preceding space without requiring a separate deletion.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.