Added "Paste code block"
This commit is contained in:
parent
b9a5d8bcf9
commit
580d075bc8
14
main.ts
14
main.ts
|
@ -21,13 +21,13 @@ export default class CodeBlockPlugin extends Plugin {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
|
|
||||||
this.addCommand({
|
this.addCommand({
|
||||||
id: 'Code block',
|
id: 'Add code block',
|
||||||
name: 'Add code block',
|
name: 'Add code block',
|
||||||
editorCallback: (editor: Editor) => {
|
editorCallback: (editor: Editor) => {
|
||||||
const selection = editor.getSelection();
|
const selection = editor.getSelection();
|
||||||
if (selection.length == 0) {
|
if (selection.length == 0) {
|
||||||
const pos = editor.getCursor();
|
const pos = editor.getCursor();
|
||||||
editor.replaceRange( '```\n\n```\n', pos);
|
editor.replaceRange('```\n\n```\n', pos);
|
||||||
editor.setCursor(pos.line + 1);
|
editor.setCursor(pos.line + 1);
|
||||||
return;
|
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));
|
this.addSettingTab(new CodeBlockTab(this.app, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue