@codemirror/lang-javascript
Advanced tools
Comparing version 6.2.0 to 6.2.1
@@ -0,1 +1,7 @@ | ||
## 6.2.1 (2023-08-28) | ||
### Bug fixes | ||
`autoCloseTags` now generates two separate transactions, so that the completion can be undone separately. | ||
## 6.2.0 (2023-08-26) | ||
@@ -2,0 +8,0 @@ |
@@ -390,5 +390,2 @@ import { parser } from '@lezer/javascript'; | ||
} | ||
function isEndTag(node) { | ||
return node && (node.name == "JSXEndTag" || node.name == "JSXSelfCloseEndTag"); | ||
} | ||
const android = typeof navigator == "object" && /*@__PURE__*//Android\b/.test(navigator.userAgent); | ||
@@ -399,3 +396,3 @@ /** | ||
*/ | ||
const autoCloseTags = /*@__PURE__*/EditorView.inputHandler.of((view, from, to, text) => { | ||
const autoCloseTags = /*@__PURE__*/EditorView.inputHandler.of((view, from, to, text, defaultInsert) => { | ||
if ((android ? view.composing : view.compositionStarted) || view.state.readOnly || | ||
@@ -405,18 +402,18 @@ from != to || (text != ">" && text != "/") || | ||
return false; | ||
let { state } = view; | ||
let changes = state.changeByRange(range => { | ||
let base = defaultInsert(), { state } = base; | ||
let closeTags = state.changeByRange(range => { | ||
var _a; | ||
let { head } = range, around = syntaxTree(state).resolveInner(head, -1), name; | ||
let { head } = range, around = syntaxTree(state).resolveInner(head - 1, -1), name; | ||
if (around.name == "JSXStartTag") | ||
around = around.parent; | ||
if (around.name == "JSXAttributeValue" && around.to > head) ; | ||
if (state.doc.sliceString(head - 1, head) != text || around.name == "JSXAttributeValue" && around.to > head) ; | ||
else if (text == ">" && around.name == "JSXFragmentTag") { | ||
return { range: EditorSelection.cursor(head + 1), changes: { from: head, insert: `></>` } }; | ||
return { range, changes: { from: head, insert: `</>` } }; | ||
} | ||
else if (text == "/" && around.name == "JSXFragmentTag") { | ||
let empty = around.parent, base = empty === null || empty === void 0 ? void 0 : empty.parent; | ||
if (empty.from == head - 1 && ((_a = base.lastChild) === null || _a === void 0 ? void 0 : _a.name) != "JSXEndTag" && | ||
(name = elementName(state.doc, base === null || base === void 0 ? void 0 : base.firstChild, head))) { | ||
let insert = `/${name}>`; | ||
return { range: EditorSelection.cursor(head + insert.length), changes: { from: head, insert } }; | ||
else if (text == "/" && around.name == "JSXStartCloseTag") { | ||
let empty = around.parent, base = empty.parent; | ||
if (base && empty.from == head - 2 && | ||
((name = elementName(state.doc, base.firstChild, head)) || ((_a = base.firstChild) === null || _a === void 0 ? void 0 : _a.name) == "JSXFragmentTag")) { | ||
let insert = `${name}>`; | ||
return { range: EditorSelection.cursor(head + insert.length, -1), changes: { from: head, insert } }; | ||
} | ||
@@ -426,12 +423,15 @@ } | ||
let openTag = findOpenTag(around); | ||
if (openTag && !isEndTag(openTag.lastChild) && | ||
state.sliceDoc(head, head + 2) != "</" && | ||
if (openTag && | ||
!/^\/?>|^<\//.test(state.doc.sliceString(head, head + 2)) && | ||
(name = elementName(state.doc, openTag, head))) | ||
return { range: EditorSelection.cursor(head + 1), changes: { from: head, insert: `></${name}>` } }; | ||
return { range, changes: { from: head, insert: `</${name}>` } }; | ||
} | ||
return { range }; | ||
}); | ||
if (changes.changes.empty) | ||
if (closeTags.changes.empty) | ||
return false; | ||
view.dispatch(changes, { userEvent: "input.type", scrollIntoView: true }); | ||
view.dispatch([ | ||
base, | ||
state.update(closeTags, { userEvent: "input.complete", scrollIntoView: true }) | ||
]); | ||
return true; | ||
@@ -438,0 +438,0 @@ }); |
{ | ||
"name": "@codemirror/lang-javascript", | ||
"version": "6.2.0", | ||
"version": "6.2.1", | ||
"description": "JavaScript language support for the CodeMirror code editor", | ||
@@ -33,3 +33,3 @@ "scripts": { | ||
"@codemirror/state": "^6.0.0", | ||
"@codemirror/view": "^6.0.0", | ||
"@codemirror/view": "^6.17.0", | ||
"@lezer/common": "^1.0.0", | ||
@@ -36,0 +36,0 @@ "@lezer/javascript": "^1.0.0" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60743
Updated@codemirror/view@^6.17.0