【问题标题】:Beautify only selected code in ace editor仅美化ace编辑器中选定的代码
【发布时间】:2021-01-11 16:31:23
【问题描述】:

我在 javascript 中使用 ace 编辑器,我想创建一个快捷方式来美化所选代码(并且 所选代码)。有没有办法做到这一点?

【问题讨论】:

    标签: javascript editor ace-editor


    【解决方案1】:

    通常,您的美化功能将在 Ace 外部;大多数编辑包使用 js-beautify 或其他东西。因此,确切的答案取决于您的具体设置。实现它:

    var selectedText = editor.getCopyText();
    var range = editor.selection.getRange();
    var beautifiedText = yourBeautifyFunction(selectedText);
    editor.getSession().replace(range,beautifiedText);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多