diff --git a/app/src/editor/rename.ts b/app/src/editor/rename.ts
index d0b4cf9e3..3296de93f 100644
--- a/app/src/editor/rename.ts
+++ b/app/src/editor/rename.ts
@@ -85,6 +85,40 @@ export const rename = (options: {
});
};
+export const renameAsset = (assetPath: string) => {
+ const dialog = new Dialog({
+ title: window.siyuan.languages.rename,
+ content: `
+
+
+
+
`,
+ width: isMobile() ? "80vw" : "520px",
+ });
+ const inputElement = dialog.element.querySelector("input") as HTMLInputElement;
+ const btnsElement = dialog.element.querySelectorAll(".b3-button");
+ dialog.bindInput(inputElement, () => {
+ (btnsElement[1] as HTMLButtonElement).click();
+ });
+ const oldName = assetPath.substring(7, assetPath.length - pathPosix().extname(assetPath).length - 23);
+ inputElement.value = oldName;
+ inputElement.focus();
+ inputElement.select();
+ btnsElement[0].addEventListener("click", () => {
+ dialog.destroy();
+ });
+ btnsElement[1].addEventListener("click", () => {
+ if (!validateName(inputElement.value)) {
+ return false;
+ }
+ if (inputElement.value === oldName || !inputElement.value) {
+ dialog.destroy();
+ return false;
+ }
+ fetchPost("/api/asset/renameAsset", {oldPath: assetPath, newName: inputElement.value});
+ });
+};
+
export const newFileContentBySelect = (protyle: IProtyle) => {
if (getSelection().rangeCount === 0) {
return;
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index 5f1cedf09..b7adb2b18 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -34,6 +34,7 @@ import {removeFoldHeading} from "../protyle/util/heading";
import {lineNumberRender} from "../protyle/markdown/highlightRender";
import * as dayjs from "dayjs";
import {blockRender} from "../protyle/markdown/blockRender";
+import {renameAsset} from "../editor/rename";
export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
const nodeElement = hasClosestBlock(element);
@@ -509,6 +510,15 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
+ const imagePath = imgElement.getAttribute("data-src")
+ if (imagePath.startsWith("assets/")) {
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: window.siyuan.languages.rename,
+ click() {
+ renameAsset(imagePath);
+ }
+ }).element);
+ }
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconAlignCenter",
label: window.siyuan.languages.alignCenter,