Add "directly open editor" shortcut and icon
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 4m48s
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 4m48s
This commit is contained in:
parent
dc15e91def
commit
d34258e6bf
2 changed files with 37 additions and 1 deletions
36
src/index.ts
36
src/index.ts
|
@ -1,4 +1,4 @@
|
|||
import {Plugin, Protyle} from 'siyuan';
|
||||
import {Plugin, Protyle, showMessage} from 'siyuan';
|
||||
import {
|
||||
getMarkdownBlock,
|
||||
loadIcons,
|
||||
|
@ -51,6 +51,23 @@ export default class DrawJSPlugin extends Plugin {
|
|||
})
|
||||
})
|
||||
|
||||
this.addCommand({
|
||||
langKey: "editShortcut",
|
||||
hotkey: "⌥⇧D",
|
||||
callback: async () => {
|
||||
await this.editSelectedImg();
|
||||
},
|
||||
})
|
||||
|
||||
this.addTopBar({
|
||||
icon: "iconDraw",
|
||||
title: this.i18n.insertDrawing,
|
||||
callback: async () => {
|
||||
await this.editSelectedImg();
|
||||
},
|
||||
position: "left"
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
onunload() {
|
||||
|
@ -61,6 +78,23 @@ export default class DrawJSPlugin extends Plugin {
|
|||
void this.analytics.sendEvent("uninstall");
|
||||
}
|
||||
|
||||
private async editSelectedImg() {
|
||||
|
||||
let selectedImg = document.getElementsByClassName('img--select');
|
||||
if(selectedImg.length == 0) {
|
||||
showMessage(this.i18n.msgMustSelect, 5000, 'info');
|
||||
return;
|
||||
}
|
||||
|
||||
let ids = imgSrcToIDs(findImgSrc(selectedImg[0] as HTMLElement));
|
||||
if(ids == null) {
|
||||
return;
|
||||
}
|
||||
void this.analytics.sendEvent('edit');
|
||||
(await EditorManager.create(ids.fileID, this)).open(this);
|
||||
|
||||
}
|
||||
|
||||
private async startConfig() {
|
||||
this.config = new PluginConfig();
|
||||
await this.config.load();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue