Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Support tag text objects in xml / htmlmixed mode. - #6356

Merged
marijnh merged 1 commit into
codemirror:masterfrom
howardjing:add-vim-tag-support
Jul 23, 2020
Merged

marijnh merged 1 commit into
codemirror:masterfrom
howardjing:add-vim-tag-support

Conversation

@howardjing

Copy link
Copy Markdown
Contributor

User can use t to operate on tag text objects. For example, given the
following html:

<div>
  <span>hello world!</span>
</div>

If the user's cursor (denoted by █) is inside "hello world!":

<div>
  <span>hello█world!</span>
</div>

And they enter dit (delete inner tag), then the text inside the
enclosing tag is deleted -- the following is the expected result:

<div>
  <span></span>
</div>

If they enter dat (delete around tag), then the surrounding tags are
deleted as well:

<div>
</div>

This logic depends on the following:

  • mode/xml/xml.js
  • addon/fold/xml-fold.js
  • editor is in htmlmixedmode / xml mode

Caveats

This is NOT a 100% accurate implementation of vim tag text objects.
For example, the following cases noop / are inconsistent with vim
behavior:

  • Does not work inside comments:
    <!-- <div>broken</div> -->
    
  • Does not work when tags have different cases:
    <div>broken</DIV>
    
  • Does not work when inside a broken tag:
    <div><brok><en></div>
    

This addresses #3828.

User can use `t` to operate on tag text objects. For example, given the
following html:

```
<div>
  <span>hello world!</span>
</div>
```

If the user's cursor (denoted by █) is inside "hello world!":

```
<div>
  <span>hello█world!</span>
</div>
```

And they enter `dit` (delete inner tag), then the text inside the
enclosing tag is deleted -- the following is the expected result:

```
<div>
  <span></span>
</div>
```

If they enter `dat` (delete around tag), then the surrounding tags are
deleted as well:

```
<div>
</div>
```

This logic depends on the following:

- mode/xml/xml.js
- addon/fold/xml-fold.js
- editor is in htmlmixedmode / xml mode

Caveats

This is _NOT_ a 100% accurate implementation of vim tag text objects.
For example, the following cases noop / are inconsistent with vim
behavior:

- Does not work inside comments:
  ```
  <!-- <div>broken</div> -->
  ```
- Does not work when tags have different cases:
  ```
  <div>broken</DIV>
  ```
- Does not work when inside a broken tag:
  ```
  <div><brok><en></div>
  ```

This addresses codemirror#3828.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants