Skip to content

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

:bug: Refine database rich-text editing and copying https://github.com/siyuan-note/siyuan/issues/11553

Daniel1b3e8a5b0f0a
diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts
index 8d2f2f2237..809882037b 100644
--- a/app/src/protyle/render/av/action.ts
+++ b/app/src/protyle/render/av/action.ts
@@ -38,7 +38,7 @@ import * as dayjs from "dayjs";
import {openCalcMenu} from "./calc";
import {avRender, initUnfoldedGroupTables, setAVGroupFolded as setGroupFolded} from "./render";
import {addView, openViewMenu} from "./view";
-import {isOnlyMeta, writeText} from "../../util/compatibility";
+import {isOnlyMeta, writeBlockDOMClipboard, writeText} from "../../util/compatibility";
import {selectAVItemRange, setAVItemAnchor} from "./rangeSelect";
import {openSearchAV} from "./relation";
import {Constants} from "../../../constants";
@@ -67,7 +67,13 @@ import {getAVCurrentViewID} from "./viewVisibility";
import {cloneAVCellValueSnapshot} from "./cellValue";
import {formatAVItemLinks, genAVItemLink} from "./itemLink";
import {openLink} from "../../../editor/openLink";
-import {getAVRichTextSafeURL, renderAVRichTextElements} from "./richText";
+import {
+ getAVRichTextBlockDOM,
+ getAVRichTextLute,
+ getAVRichTextSafeURL,
+ getAVTextSource,
+ renderAVRichTextElements
+} from "./richText";
/// #if !MOBILE
import {openGlobalSearch} from "../../../search/util";
/// #else
@@ -758,8 +764,24 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.stopPropagation();
return true;
} else if (type === "copy") {
- writeText(getCellText(hasClosestByClassName(target, "av__cell")));
- showMessage(window.siyuan.languages.copied);
+ const cellElement = hasClosestByClassName(target, "av__cell") as HTMLElement;
+ const source = getAVTextSource(genCellValueByElement("text", cellElement));
+ if (source.kind === "rich") {
+ const blockDOM = getAVRichTextBlockDOM(source.content);
+ if (blockDOM) {
+ void writeBlockDOMClipboard(getAVRichTextLute(), blockDOM).then((copied) => {
+ if (copied) {
+ showMessage(window.siyuan.languages.copied);
+ }
+ });
+ } else {
+ writeText(getCellText(cellElement));
+ showMessage(window.siyuan.languages.copied);
+ }
+ } else {
+ writeText(getCellText(cellElement));
+ showMessage(window.siyuan.languages.copied);
+ }
event.preventDefault();
event.stopPropagation();
return true;
diff --git a/app/src/protyle/render/av/richTextEditor.ts b/app/src/protyle/render/av/richTextEditor.ts
index 91f1647527..1636c830dc 100644
--- a/app/src/protyle/render/av/richTextEditor.ts
+++ b/app/src/protyle/render/av/richTextEditor.ts
@@ -94,15 +94,16 @@ export const destroyAVRichTextEditor = (save = false) => {
export const openAVRichTextEditor = (options: AVRichTextEditorOptions) => {
void activeEditor?.finish(false);
+ const mobile = isMobile();
const maskElement = document.createElement("div");
maskElement.className = "av__mask av__richtext-mask";
maskElement.style.zIndex = (++window.siyuan.zIndex).toString();
maskElement.innerHTML = `<div class="av__richtext-editor" role="dialog">
<div class="av__richtext-host"></div>
- <div class="av__richtext-actions">
+ ${mobile ? `<div class="av__richtext-actions">
<button type="button" class="b3-button b3-button--cancel" data-type="cancel">${escapeHtml(window.siyuan.languages.cancel)}</button>
<button type="button" class="b3-button b3-button--text" data-type="save">${escapeHtml(window.siyuan.languages.save)}</button>
- </div>
+ </div>` : ""}
</div>`;
document.body.appendChild(maskElement);
const panelElement = maskElement.firstElementChild as HTMLElement;
@@ -111,7 +112,7 @@ export const openAVRichTextEditor = (options: AVRichTextEditorOptions) => {
setPanelPosition(panelElement, options.anchorElement);
const source = getAVTextSource(options.value);
- const toolbar = getDefaultToolbar(isMobile());
+ const toolbar = getDefaultToolbar(mobile);
const hint: IProtyleOptions["hint"] = {
extend: [{key: "((", hint: hintAVRef}, {key: "【【", hint: hintAVRef},
{key: "((", hint: hintAVRef}, {key: "[[", hint: hintAVRef},
@@ -200,15 +201,15 @@ export const openAVRichTextEditor = (options: AVRichTextEditorOptions) => {
void finish(true);
}
});
- panelElement.querySelector('[data-type="cancel"]').addEventListener("click", () => void finish(false));
- panelElement.querySelector('[data-type="save"]').addEventListener("click", () => void finish(true));
+ panelElement.querySelector('[data-type="cancel"]')?.addEventListener("click", () => void finish(false));
+ panelElement.querySelector('[data-type="save"]')?.addEventListener("click", () => void finish(true));
panelElement.addEventListener("keydown", (event: KeyboardEvent) => {
if (event.key === "Escape" && fragment.hintElement.classList.contains("fn__none") &&
fragment.protyle.toolbar.element.classList.contains("fn__none") &&
fragment.protyle.toolbar.subElement.classList.contains("fn__none")) {
event.preventDefault();
event.stopPropagation();
- void finish(false);
+ void finish(true);
}
}, true);
fragment.focus(true);