🎨 Support copying file in the asset menu on Windows and macOS (#17049)

This commit is contained in:
Jeffrey Chen 2026-02-16 11:26:13 +08:00 committed by GitHub
parent d484ddc079
commit ca41244188
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 387 additions and 2 deletions

View file

@ -44,7 +44,7 @@ import {blockRender} from "../protyle/render/blockRender";
import {renameAsset} from "../editor/rename";
import {electronUndo} from "../protyle/undo";
import {pushBack} from "../mobile/util/MobileBackFoward";
import {copyPNGByLink, exportAsset} from "./util";
import {copyAsset, copyPNGByLink, exportAsset} from "./util";
import {removeInlineType} from "../protyle/toolbar/util";
import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey";
import {checkFold, renameTag} from "../util/noRelyPCFunction";
@ -1418,6 +1418,11 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
const dataSrc = imgElement.getAttribute("data-src");
if (dataSrc && dataSrc.startsWith("assets/")) {
window.siyuan.menus.menu.append(new MenuItem(exportAsset(dataSrc)).element);
/// #if !BROWSER
if (["windows", "darwin"].includes(window.siyuan.config.system.os)) {
window.siyuan.menus.menu.append(new MenuItem(copyAsset(dataSrc)).element);
}
/// #endif
}
if (protyle?.app?.plugins) {
emitOpenMenu({
@ -1691,6 +1696,11 @@ style="margin:4px 0;width: ${isMobile() ? "100%" : "360px"}" class="b3-text-fiel
openMenu(protyle.app, linkAddress, false, true);
if (linkAddress?.startsWith("assets/")) {
window.siyuan.menus.menu.append(new MenuItem(exportAsset(linkAddress)).element);
/// #if !BROWSER
if (["windows", "darwin"].includes(window.siyuan.config.system.os)) {
window.siyuan.menus.menu.append(new MenuItem(copyAsset(linkAddress)).element);
}
/// #endif
}
}
@ -2114,6 +2124,11 @@ export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string)
}
if (src && src.startsWith("assets/")) {
subMenus.push(exportAsset(src));
/// #if !BROWSER
if (["windows", "darwin"].includes(window.siyuan.config.system.os)) {
subMenus.push(copyAsset(src));
}
/// #endif
}
return subMenus;
};

View file

@ -39,6 +39,28 @@ export const exportAsset = (src: string) => {
};
};
// 复制资源文件到系统剪贴板,在文件资源管理器中可粘贴为文件(仅 Windows、macOS 桌面端支持)
export const copyAsset = (src: string) => {
return {
id: "copy",
label: window.siyuan.languages.copyFile,
icon: "iconCopy",
click: () => {
/// #if !BROWSER
fetchPost("/api/clipboard/writeFilePath", {path: src}, (response) => {
if (response.code === 0) {
showMessage(window.siyuan.languages.copied);
} else {
showMessage(response.msg || "", response.data?.closeTimeout ?? 5000, "error");
}
});
/// #else
showMessage("Copy as file is only supported in the Windows and macOS desktop app");
/// #endif
}
};
};
export const openEditorTab = (app: App, ids: string[], notebookId?: string, pathString?: string, onlyGetMenus = false) => {
/// #if !MOBILE
const openSubmenus: IMenu[] = [{