Monaco Editor实现ctrl+v粘贴时进行代码格式化
// 添加Ctrl+V快捷键粘贴后格式化保存
editor.addAction({
id: 'paste-and-format',
label: 'Paste and Format',
keybindings: [monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyV)],
run: function () {
console.log('粘贴后格式化');
// editor.getAction('editor.action.formatDocument').run();
editor.trigger('editor', 'editor.action.clipboardPasteAction');
setTimeout(() => {
editor.trigger('editor', 'editor.action.formatDocument');
}, 1 * 100);
// saveContent(); // 你的保存函数
},
});