From bda97eaef5b1e6c35ed228624a785c419540c20b Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 18 Nov 2024 23:43:13 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/13062 --- app/src/protyle/render/av/action.ts | 41 +++++++++++++++------- app/src/protyle/render/av/openMenuPanel.ts | 6 ++-- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts index ac70a2d76..737c99c64 100644 --- a/app/src/protyle/render/av/action.ts +++ b/app/src/protyle/render/av/action.ts @@ -33,6 +33,7 @@ import {Constants} from "../../../constants"; import {hideElements} from "../../ui/hideElements"; import {fetchPost, fetchSyncPost} from "../../../util/fetch"; import {scrollCenter} from "../../../util/highlightById"; +import {escapeHtml} from "../../../util/escape"; export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => { if (isOnlyMeta(event)) { @@ -288,17 +289,31 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi }); /// #endif } - let copyMenu: IMenu[] = []; - if (rowElements.length === 1 && keyCellElement.getAttribute("data-detached") === "true") { - copyMenu.push({ - iconHTML: "", - label: window.siyuan.languages["_attrView"].key, - click() { - writeText(rowElements[0].querySelector('.av__cell[data-dtype="block"] .av__celltext').textContent); - } - }); - } else { - copyMenu = [{ + let hasBlock = false + rowElements.forEach((item, i) => { + if (item.querySelector('.av__cell[data-dtype="block"]').getAttribute("data-detached") !== "true") { + hasBlock = true + } + }) + const copyMenu: IMenu[] = [{ + iconHTML: "", + label: window.siyuan.languages.keyContent, + click() { + let text = "" + rowElements.forEach((item, i) => { + if (rowElements.length > 1) { + text += "* "; + } + text += item.querySelector('.av__cell[data-dtype="block"] .av__celltext').textContent.trim(); + if (ids.length > 1 && i !== ids.length - 1) { + text += "\n"; + } + }) + writeText(text); + } + }]; + if (hasBlock) { + copyMenu.splice(1, 0, { id: "copyBlockRef", iconHTML: "", label: window.siyuan.languages.copyBlockRef, @@ -443,7 +458,7 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi }); writeText(text); } - }]; + }); } menu.addItem({ @@ -572,7 +587,7 @@ ${window.siyuan.languages.insertRowAfter.replace("${x}", '`, - label: cellElement.querySelector(".av__celltext").textContent.trim(), + label: escapeHtml(cellElement.querySelector(".av__celltext").textContent.trim()), click() { popTextCell(protyle, selectElements); } diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts index 5fd5385d5..96f5f396b 100644 --- a/app/src/protyle/render/av/openMenuPanel.ts +++ b/app/src/protyle/render/av/openMenuPanel.ts @@ -28,7 +28,7 @@ import {bindRelationEvent, getRelationHTML, openSearchAV, setRelationCell, updat import {bindRollupData, getRollupHTML, goSearchRollupCol} from "./rollup"; import {updateCellsValue} from "./cell"; import {openCalcMenu} from "./calc"; -import {escapeAttr} from "../../../util/escape"; +import {escapeAttr, escapeHtml} from "../../../util/escape"; import {Dialog} from "../../../dialog"; export const openMenuPanel = (options: { @@ -1336,7 +1336,7 @@ export const getPropertiesHTML = (data: IAVTable) => {
${item.icon ? unicode2Emoji(item.icon, "b3-menu__icon", true) : ``} - ${item.name || " "} + ${escapeHtml(item.name) || " "}
@@ -1346,7 +1346,7 @@ export const getPropertiesHTML = (data: IAVTable) => {
${item.icon ? unicode2Emoji(item.icon, "b3-menu__icon", true) : ``} - ${item.name || " "} + ${escapeHtml(item.name) || " "}