Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/8554 8

Vanessa649b1d37fc3b
diff --git a/app/src/assets/scss/protyle/_attr.scss b/app/src/assets/scss/protyle/_attr.scss
index d9475c84c9..b8d333f024 100644
--- a/app/src/assets/scss/protyle/_attr.scss
+++ b/app/src/assets/scss/protyle/_attr.scss
@@ -8,7 +8,10 @@
font-weight: normal;
align-items: center;
line-height: 16px;
- // 会导致 https://github.com/siyuan-note/siyuan/issues/16829 先移除 user-select: none;
+ // 容器保持可选以支持三击选中文本,仅排除属性内容 https://github.com/siyuan-note/siyuan/issues/16829
+ & > div {
+ user-select: none;
+ }
&--av span:hover {
color: var(--b3-protyle-inline-blockref-color);
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index cac1acf728..7a5511a7ce 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -296,6 +296,17 @@ export class WYSIWYG {
});
}
+ private clearAttrContent(element: HTMLElement) {
+ const attrElements = element.querySelectorAll(".protyle-attr");
+ if (attrElements.length === 0) {
+ return;
+ }
+ attrElements.forEach(item => {
+ item.textContent = Constants.ZWSP;
+ });
+ return element.textContent;
+ }
+
private bindCommonEvent(protyle: IProtyle) {
this.element.addEventListener("copy", async (event: ClipboardEvent & { target: HTMLElement }) => {
window.siyuan.ctrlIsPressed = false; // https://github.com/siyuan-note/siyuan/issues/6373
@@ -482,6 +493,10 @@ export class WYSIWYG {
if (matchHeading) {
// 复制标题 https://github.com/siyuan-note/insider/issues/297
tempElement.append(headingElement.cloneNode(true));
+ const textWithoutAttr = this.clearAttrContent(tempElement);
+ if (textWithoutAttr !== undefined) {
+ textPlain = textWithoutAttr;
+ }
// https://github.com/siyuan-note/siyuan/issues/13232
headingElement.removeAttribute("fold");
} else if (!["DIV", "TD", "TH", "TR"].includes(range.startContainer.parentElement.tagName)) {
@@ -491,10 +506,14 @@ export class WYSIWYG {
} else {
// 直接复制块 https://github.com/siyuan-note/insider/issues/318
tempElement.append(range.cloneContents());
+ const textWithoutAttr = this.clearAttrContent(tempElement);
+ if (textWithoutAttr !== undefined) {
+ textPlain = textWithoutAttr;
+ }
this.emojiToMd(tempElement);
}
html = tempElement.innerHTML;
- textPlain = range.toString();
+ textPlain = textPlain || range.toString();
} else if (selectImgElement) {
html = selectImgElement.outerHTML;
// 和图片菜单中的复制保持一致
@@ -518,6 +537,7 @@ export class WYSIWYG {
textPlain = range.toString();
} else {
tempElement.append(range.cloneContents());
+ const textWithoutAttr = this.clearAttrContent(tempElement);
this.emojiToMd(tempElement);
const inlineMathElement = hasClosestByAttribute(range.commonAncestorContainer, "data-type", "inline-math");
if (inlineMathElement) {
@@ -552,7 +572,7 @@ export class WYSIWYG {
}
});
} else if (!hasClosestByTag(range.startContainer, "CODE")) {
- textPlain = range.toString();
+ textPlain = textWithoutAttr ?? range.toString();
}
}
}