Add "directly open editor" shortcut and icon
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 4m48s

This commit is contained in:
MassiveBox 2025-06-24 22:26:26 +02:00
parent dc15e91def
commit d34258e6bf
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
2 changed files with 37 additions and 1 deletions

View file

@ -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();