Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 23, 2020

Conversation

howardjing
Copy link
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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants