This commit is contained in:
Vanessa 2023-04-23 11:33:50 +08:00
parent 245e7b145e
commit db16d8f76c
3 changed files with 62 additions and 53 deletions

View file

@ -40,6 +40,7 @@ export abstract class Constants {
public static readonly SIYUAN_AUTO_LAUNCH: string = "siyuan-auto-launch"; public static readonly SIYUAN_AUTO_LAUNCH: string = "siyuan-auto-launch";
// size // size
public static readonly SIZE_LINK_TEXT_MAX: number = 24;
public static readonly SIZE_TOOLBAR_HEIGHT: number = isMobile() ? 0 : 32; public static readonly SIZE_TOOLBAR_HEIGHT: number = isMobile() ? 0 : 32;
public static readonly SIZE_GET_MAX = 102400; public static readonly SIZE_GET_MAX = 102400;
public static readonly SIZE_UNDO = 64; public static readonly SIZE_UNDO = 64;

View file

@ -437,60 +437,68 @@ export const openAttr = (nodeElement: Element, protyle: IProtyle, focusName = "b
}; };
export const copySubMenu = (id: string, accelerator = true, focusElement?: Element) => { export const copySubMenu = (id: string, accelerator = true, focusElement?: Element) => {
return [ return [{
{ icon: "iconRef",
icon: "iconRef", accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockRef.custom : undefined,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockRef.custom : undefined, label: window.siyuan.languages.copyBlockRef,
label: window.siyuan.languages.copyBlockRef, click: () => {
click: () => { fetchPost("/api/block/getRefText", {id}, (response) => {
fetchPost("/api/block/getRefText", {id}, (response) => { writeText(`((${id} '${response.data}'))`);
writeText(`((${id} '${response.data}'))`); });
}); if (focusElement) {
if (focusElement) { focusBlock(focusElement);
focusBlock(focusElement);
}
}
}, {
icon: "iconSQL",
label: window.siyuan.languages.copyBlockEmbed,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom : undefined,
click: () => {
writeText(`{{select * from blocks where id='${id}'}}`);
if (focusElement) {
focusBlock(focusElement);
}
}
}, {
icon: "iconSiYuan",
label: window.siyuan.languages.copyProtocol,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocol.custom : undefined,
click: () => {
writeText(`siyuan://blocks/${id}`);
if (focusElement) {
focusBlock(focusElement);
}
}
}, {
label: window.siyuan.languages.copyHPath,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyHPath.custom : undefined,
click: () => {
fetchPost("/api/filetree/getHPathByID", {
id
}, (response) => {
writeText(response.data);
});
}
}, {
label: window.siyuan.languages.copyID,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyID.custom : undefined,
click: () => {
writeText(id);
if (focusElement) {
focusBlock(focusElement);
}
} }
} }
]; }, {
icon: "iconSQL",
label: window.siyuan.languages.copyBlockEmbed,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom : undefined,
click: () => {
writeText(`{{select * from blocks where id='${id}'}}`);
if (focusElement) {
focusBlock(focusElement);
}
}
}, {
icon: "iconSiYuan",
label: window.siyuan.languages.copyProtocol,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocol.custom : undefined,
click: () => {
writeText(`siyuan://blocks/${id}`);
if (focusElement) {
focusBlock(focusElement);
}
}
}, {
label: window.siyuan.languages.copyProtocol,
click: () => {
fetchPost("/api/block/getRefText", {id}, (response) => {
writeText(`[${response.data.substring(0, Constants.SIZE_LINK_TEXT_MAX)}](siyuan://blocks/${id})`);
});
if (focusElement) {
focusBlock(focusElement);
}
}
}, {
label: window.siyuan.languages.copyHPath,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyHPath.custom : undefined,
click: () => {
fetchPost("/api/filetree/getHPathByID", {
id
}, (response) => {
writeText(response.data);
});
}
}, {
label: window.siyuan.languages.copyID,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyID.custom : undefined,
click: () => {
writeText(id);
if (focusElement) {
focusBlock(focusElement);
}
}
}];
}; };
export const exportMd = (id: string) => { export const exportMd = (id: string) => {

View file

@ -762,7 +762,7 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText
if (!anchor && linkAddress) { if (!anchor && linkAddress) {
anchor = linkAddress.replace("https://", "").replace("http://", ""); anchor = linkAddress.replace("https://", "").replace("http://", "");
if (anchor.length > 24) { if (anchor.length > 24) {
anchor = anchor.substring(0, 24) + "..."; anchor = anchor.substring(0, Constants.SIZE_LINK_TEXT_MAX) + "...";
} }
linkElement.innerHTML = Lute.EscapeHTMLStr(anchor); linkElement.innerHTML = Lute.EscapeHTMLStr(anchor);
} }