diff --git a/main.ts b/main.ts index 54321d0..e2565d5 100644 --- a/main.ts +++ b/main.ts @@ -21,13 +21,13 @@ export default class CodeBlockPlugin extends Plugin { await this.loadSettings(); this.addCommand({ - id: 'Code block', + id: 'Add code block', name: 'Add code block', editorCallback: (editor: Editor) => { const selection = editor.getSelection(); if (selection.length == 0) { const pos = editor.getCursor(); - editor.replaceRange( '```\n\n```\n', pos); + editor.replaceRange('```\n\n```\n', pos); editor.setCursor(pos.line + 1); return; } @@ -35,6 +35,16 @@ export default class CodeBlockPlugin extends Plugin { } }); + this.addCommand({ + id: 'Paste code block', + name: 'Paste code block', + editorCallback: (editor: Editor) => { + navigator.clipboard.readText().then(text => { + editor.replaceSelection(CodeBlockPlugin.addCodeBlock(this.getLanguage(text), text)); + }); + } + }); + this.addSettingTab(new CodeBlockTab(this.app, this)); }