diff --git a/docs/Preferences.md b/docs/Preferences.md index 4d6d56de..abfa3df6 100644 --- a/docs/Preferences.md +++ b/docs/Preferences.md @@ -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 + + +``` + +Then the closing tag for the `` element will automatically be inserted: + +```xml + + + +``` + +Similarly, the closing tag will be automatically completed when typing ` + content + +Orphaned text + +``` + +If `/` is typed at the pipe (`|`), then `/>` will be inserted at the cursor, +and `` and `content` will be removed. +Note that `Orphaned text` and `` 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 + + + + +``` + +it gets turned into the following (no auto completion): + +```xml + + + + +``` + +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. diff --git a/package.json b/package.json index a1b0ce99..c0bffadd 100644 --- a/package.json +++ b/package.json @@ -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,