[monaco-editor] formatOnPaste 无效问题

2023-06-12 17:08:42 +08:00
 yxcoder

我正在使用 monaco-editor,这个是 monaco 的一个在线测试页面

monaco-editor

这个是我的配置

var editor = monaco.editor.create(document.getElementById("container"), {
    value: "",
    language: "sql",

    lineNumbers: "off",
    roundedSelection: false,
    scrollBeyondLastLine: false,
    readOnly: false,
    theme: "vs-dark",
    fontSize: 18,
    fontWeight: '800',
    formatOnPaste: true      // 粘贴自动格式化的配置
});

我在右边渲染出的编辑器中粘贴这段代码

select * from abc where abc.a="abc";select * from cba where cba.a="cba";

发现编辑器并没有进行格式化操作

我应该怎么去正确地使用 formatOnPaste

482 次点击
所在节点    前端开发
3 条回复
gucheen
2023-06-12 17:33:58 +08:00
monaco 没有内置的 sql 格式化逻辑,你可以自己添加一个
关键词 registerDocumentFormattingEditProvider
yxcoder
2023-06-13 10:22:42 +08:00
@gucheen 感觉不像这个问题,我这么测试了一下
yxcoder
2023-06-13 10:23:30 +08:00
@yxcoder

```
var editor = monaco.editor.create(document.getElementById("container"), {
value: "",
language: "javascript",

lineNumbers: "off",
roundedSelection: false,
scrollBeyondLastLine: false,
readOnly: false,
theme: "vs-dark",
fontSize: 18,
fontWeight: '800',
formatOnPaste: true // 粘贴自动格式化的配置
});
```

右侧输入

```
function hello() {alert('Hello world!');}
```

一样没有进行格式化操作

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/948073

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX