Added "Paste code block"

This commit is contained in:
Patrik Lindefors 2022-05-30 10:17:32 +02:00
parent b9a5d8bcf9
commit 580d075bc8
1 changed files with 12 additions and 2 deletions

12
main.ts
View File

@ -21,7 +21,7 @@ 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();
@ -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));
}