Improve container block copy text * (#16467)

fix https://ld246.com/article/1764395026961
This commit is contained in:
Jeffrey Chen 2025-12-01 19:41:23 +08:00 committed by GitHub
parent 743bb59155
commit 107284c799
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,7 +16,7 @@ import {cellScrollIntoView, getCellText} from "../render/av/cell";
import {getContenteditableElement} from "../wysiwyg/getBlock"; import {getContenteditableElement} from "../wysiwyg/getBlock";
import {clearBlockElement} from "./clear"; import {clearBlockElement} from "./clear";
export const getTextStar = (blockElement: HTMLElement) => { export const getTextStar = (blockElement: HTMLElement, contentOnly = false) => {
const dataType = blockElement.dataset.type; const dataType = blockElement.dataset.type;
let refText = ""; let refText = "";
if (["NodeHeading", "NodeParagraph"].includes(dataType)) { if (["NodeHeading", "NodeParagraph"].includes(dataType)) {
@ -44,15 +44,16 @@ export const getTextStar = (blockElement: HTMLElement) => {
} else if (["NodeBlockquote", "NodeList", "NodeSuperBlock", "NodeListItem"].includes(dataType)) { } else if (["NodeBlockquote", "NodeList", "NodeSuperBlock", "NodeListItem"].includes(dataType)) {
Array.from(blockElement.querySelectorAll("[data-node-id]")).find((item: HTMLElement) => { Array.from(blockElement.querySelectorAll("[data-node-id]")).find((item: HTMLElement) => {
if (!["NodeBlockquote", "NodeList", "NodeSuperBlock", "NodeListItem"].includes(item.getAttribute("data-type"))) { if (!["NodeBlockquote", "NodeList", "NodeSuperBlock", "NodeListItem"].includes(item.getAttribute("data-type"))) {
refText = getTextStar(blockElement.querySelector("[data-node-id]")); // 获取子块内容,使用容器块本身的 ID
refText = getTextStar(item, true);
return true; return true;
} }
}); });
if (refText) {
return refText;
}
} }
} }
if (contentOnly) {
return refText;
}
return refText + ` <span data-type="block-ref" data-subtype="s" data-id="${blockElement.getAttribute("data-node-id")}">*</span>`; return refText + ` <span data-type="block-ref" data-subtype="s" data-id="${blockElement.getAttribute("data-node-id")}">*</span>`;
}; };