Skip to content

Commit

Permalink
Add option to prevent self-closing from removing content
Browse files Browse the repository at this point in the history
Closes redhat-developer#440

Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed May 3, 2021
1 parent 6f9bda8 commit 2d64dbb
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
69 changes: 69 additions & 0 deletions docs/Preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,75 @@ See the [Formatting page](Formatting.md#formatting).

Use `xml.codeLens.enabled` in order to enable or disable code lens. Please see [the Code Lens page](CodeLens.md#code-lens) for more information.

## Tag Auto Closing

The closing tags for elements should automatically be added when typing `>` to complete an opening tag.

For instance, if you type `>` when your cursor is placed at the `|` pipe in the following code:

```xml
<root>
<child|
</root>
```

Then the closing tag for the `<child>` element will automatically be inserted:

```xml
<root>
<child></child>
</root>
```

Similarly, the closing tag will be automatically completed when typing `</` to start a closing tag.

The `xml.completion.autoCloseRemovesContent` setting controls if all content inside an element gets deleted when the start tag gets changed to a self-closing tag.

For instance if `xml.completion.autoCloseRemovesContent` is set to `true`, in the following code:

```xml
<root |
<child />
content
</root>
Orphaned text
<orphaned-element />
```

If `/` is typed at the pipe (`|`), then `/>` will be inserted at the cursor,
and `<child />` and `content` will be removed.
Note that `Orphaned text` and `<orphaned-element />` will be preserved.

If `xml.completion.autoCloseRemovesContent` is set to `false` in this case,
`/>` is inserted at the cursor, but no content will be removed.

Unfortunately, this only works if the first content inside the element is an element.
For instance, if you typed `/` at the `|` for this document:

```xml
<root>
<container |
text content
<child />
</container>
</root>
```

it gets turned into the following (no auto completion):

```xml
<root>
<container /
text content
<child />
</container>
</root>
```

The same result would occur for the previous example if `xml.completion.autoCloseRemovesContent` is set to `false`.

By default, `xml.completion.autoCloseRemovesContent` is set to `true`.

## Documentation Type

Use `xml.preferences.showSchemaDocumentationType` in order to control which documentation is presented during completion and hover for XML documents associated with XSD schemas.
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@
"markdownDescription": "Enable/disable autoclosing of XML tags. Default is `true`. \n\nIMPORTANT: Turn off `#editor.autoClosingTags#` for this to work.",
"scope": "window"
},
"xml.completion.autoCloseRemovesContent": {
"type": "boolean",
"default": true,
"markdownDescription": "Enable/disable the content of an element being removed when the element start tag is turned into a self-closing tag. The default setting is to remove the content.",
"scope": "window"
},
"xml.codeLens.enabled": {
"type": "boolean",
"default": false,
Expand Down

0 comments on commit 2d64dbb

Please sign in to comment.