2 Star 0 Fork 0

安润鲁/3d-graph

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.html 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
安润鲁 提交于 2024-04-08 11:42 . opt:编辑器高亮
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Monaco Editor - Bracket Auto-Completion</title>
<!-- Load Monaco Editor -->
<script src="https://cdn.jsdelivr.net/npm/monaco-editor@latest/min/vs/loader.js"></script>
<style>
#container {
width: 800px;
height: 600px;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
require.config({
paths: {
vs: "https://cdn.jsdelivr.net/npm/monaco-editor@latest/min/vs",
},
});
require(["vs/editor/editor.main"], function () {
var editor = monaco.editor.create(
document.getElementById("container"),
{
value: "",
language: "javascript",
}
);
// Register bracket auto-completion snippet
monaco.languages.registerCompletionItemProvider("javascript", {
provideCompletionItems: function (model, position) {
var textUntilPosition = model.getValueInRange({
startLineNumber: position.lineNumber,
startColumn: 1,
endLineNumber: position.lineNumber,
endColumn: position.column,
});
var match = textUntilPosition.match(/(\()|(\[)|({)/);
if (!match) return [];
var bracketType = match[0];
var closingBracket = "";
switch (bracketType) {
case "(":
closingBracket = ")";
break;
case "[":
closingBracket = "]";
break;
case "{":
closingBracket = "}";
break;
default:
break;
}
var suggestion = {
label: closingBracket,
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: closingBracket,
range: new monaco.Range(
position.lineNumber,
position.column,
position.lineNumber,
position.column
),
};
return [suggestion];
},
});
});
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/an_run_lu/3d-graph.git
git@gitee.com:an_run_lu/3d-graph.git
an_run_lu
3d-graph
3d-graph
main

搜索帮助