@codemirror/lang-html
Advanced tools
Comparing version 0.19.3 to 0.19.4
@@ -0,1 +1,7 @@ | ||
## 0.19.4 (2021-11-30) | ||
### Bug fixes | ||
Fix an issue where autoclosing a tag directly in front of alphanumeric text would include nonsense text in the completed tag name. | ||
## 0.19.3 (2021-09-23) | ||
@@ -2,0 +8,0 @@ |
@@ -360,3 +360,3 @@ import { parser, configureNesting } from '@lezer/html'; | ||
const GlobalAttrNames = /*@__PURE__*/Object.keys(GlobalAttrs); | ||
function elementName(doc, tree) { | ||
function elementName(doc, tree, max = doc.length) { | ||
if (!tree) | ||
@@ -366,3 +366,3 @@ return ""; | ||
let name = tag && tag.getChild("TagName"); | ||
return name ? doc.sliceString(name.from, name.to) : ""; | ||
return name ? doc.sliceString(name.from, Math.min(name.to, max)) : ""; | ||
} | ||
@@ -592,14 +592,14 @@ function findParentElement(tree, skip = false) { | ||
var _a, _b, _c; | ||
let around = syntaxTree(state).resolveInner(range.head, -1), name; | ||
let { head } = range, around = syntaxTree(state).resolveInner(head, -1), name; | ||
if (around.name == "TagName" || around.name == "StartTag") | ||
around = around.parent; | ||
if (text == ">" && around.name == "OpenTag") { | ||
if (((_b = (_a = around.parent) === null || _a === void 0 ? void 0 : _a.lastChild) === null || _b === void 0 ? void 0 : _b.name) != "CloseTag" && (name = elementName(state.doc, around.parent))) | ||
return { range: EditorSelection.cursor(range.head + 1), changes: { from: range.head, insert: `></${name}>` } }; | ||
if (((_b = (_a = around.parent) === null || _a === void 0 ? void 0 : _a.lastChild) === null || _b === void 0 ? void 0 : _b.name) != "CloseTag" && (name = elementName(state.doc, around.parent, head))) | ||
return { range: EditorSelection.cursor(head + 1), changes: { from: head, insert: `></${name}>` } }; | ||
} | ||
else if (text == "/" && around.name == "OpenTag") { | ||
let empty = around.parent, base = empty === null || empty === void 0 ? void 0 : empty.parent; | ||
if (empty.from == range.head - 1 && ((_c = base.lastChild) === null || _c === void 0 ? void 0 : _c.name) != "CloseTag" && (name = elementName(state.doc, base))) { | ||
if (empty.from == head - 1 && ((_c = base.lastChild) === null || _c === void 0 ? void 0 : _c.name) != "CloseTag" && (name = elementName(state.doc, base, head))) { | ||
let insert = `/${name}>`; | ||
return { range: EditorSelection.cursor(range.head + insert.length), changes: { from: range.head, insert } }; | ||
return { range: EditorSelection.cursor(head + insert.length), changes: { from: head, insert } }; | ||
} | ||
@@ -606,0 +606,0 @@ } |
{ | ||
"name": "@codemirror/lang-html", | ||
"version": "0.19.3", | ||
"version": "0.19.4", | ||
"description": "HTML language support for the CodeMirror code editor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
56234