yxcoder

[monaco-editor] formatOnPaste 无效问题

  •  
  •   yxcoder · Jun 12, 2023 · 1101 views
    This topic created in 1078 days ago, the information mentioned may be changed or developed.

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

    一样没有进行格式化操作
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1184 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 69ms · UTC 23:31 · PVG 07:31 · LAX 16:31 · JFK 19:31
    ♥ Do have faith in what you're doing.