V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yxcoder
V2EX  ›  前端开发

[monaco-editor] formatOnPaste 无效问题

  •  
  •   yxcoder · 327 天前 · 447 次点击
    这是一个创建于 327 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我正在使用 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

    3 条回复    2023-06-13 10:23:30 +08:00
    gucheen
        1
    gucheen  
       327 天前
    monaco 没有内置的 sql 格式化逻辑,你可以自己添加一个
    关键词 registerDocumentFormattingEditProvider
    yxcoder
        2
    yxcoder  
    OP
       327 天前
    @gucheen 感觉不像这个问题,我这么测试了一下
    yxcoder
        3
    yxcoder  
    OP
       327 天前
    @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!');}
    ```

    一样没有进行格式化操作
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2373 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 03:41 · PVG 11:41 · LAX 20:41 · JFK 23:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.