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/17800

Vanessa9a32f2b0eff6
diff --git a/app/src/assets/scss/protyle/_wysiwyg.scss b/app/src/assets/scss/protyle/_wysiwyg.scss
index 3ccd36bd96..69f176ba88 100644
--- a/app/src/assets/scss/protyle/_wysiwyg.scss
+++ b/app/src/assets/scss/protyle/_wysiwyg.scss
@@ -393,7 +393,6 @@
//.protyle-attr--refcount {right: 0;}
& > .protyle-wysiwyg__embed {
- -webkit-user-modify: read-only;
border-top: 1px dashed var(--b3-theme-on-surface-light);
position: relative;
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts
index 8855a76a36..981b2f5839 100644
--- a/app/src/protyle/util/onGet.ts
+++ b/app/src/protyle/util/onGet.ts
@@ -442,9 +442,7 @@ export const enableProtyle = (protyle: IProtyle) => {
}
});
protyle.wysiwyg.element.querySelectorAll('[contenteditable="false"][spellcheck]').forEach(item => {
- if (!hasClosestByClassName(item, "protyle-wysiwyg__embed")) {
- item.setAttribute("contenteditable", "true");
- }
+ item.setAttribute("contenteditable", "true");
});
protyle.wysiwyg.element.querySelectorAll('.protyle-action[draggable="false"]').forEach(item => {
item.setAttribute("draggable", "true");
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 82b0fce5ff..6e40313340 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -64,7 +64,6 @@ import {openGlobalSearch} from "../../search/util";
/// #else
import {popSearch} from "../../mobile/menu/search";
/// #endif
-import {BlockPanel} from "../../block/Panel";
import {copyPlainText, encodeBase64, isInIOS, isMac, isOnlyMeta, readClipboard} from "../util/compatibility";
import {MenuItem} from "../../menus/Menu";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
@@ -1848,10 +1847,12 @@ export class WYSIWYG {
event.preventDefault();
return;
}
- // https://github.com/siyuan-note/siyuan/issues/11793
+ // https://github.com/siyuan-note/siyuan/issues/17800 不能删除
const embedElement = isInEmbedBlock(nodeElement);
if (embedElement) {
- nodeElement = embedElement;
+ event.stopPropagation();
+ event.preventDefault();
+ return;
}
event.stopPropagation();
event.preventDefault();
@@ -2921,51 +2922,46 @@ export class WYSIWYG {
const embedItemElement = hasClosestByClassName(event.target, "protyle-wysiwyg__embed");
if (embedItemElement) {
- const embedId = embedItemElement.getAttribute("data-id");
- checkFold(embedId, (zoomIn, action) => {
- /// #if MOBILE
- mobileBlur = true;
- activeBlur();
- openMobileFileById(protyle.app, embedId, zoomIn ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
- /// #else
- if (event.shiftKey) {
- openFileById({
- app: protyle.app,
- id: embedId,
- position: "bottom",
- action,
- zoomIn
- });
- } else if (event.altKey) {
- openFileById({
- app: protyle.app,
- id: embedId,
- position: "right",
- action,
- zoomIn
- });
- } else if (ctrlIsPressed) {
- openFileById({
- app: protyle.app,
- id: embedId,
- action: zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
- zoomIn,
- keepCursor: true,
- });
- } else if (!protyle.disabled) {
- window.siyuan.blockPanels.push(new BlockPanel({
- app: protyle.app,
- targetElement: embedItemElement,
- isBacklink: false,
- refDefs: [{refID: embedId}]
- }));
+ if (event.shiftKey || event.altKey || ctrlIsPressed) {
+ const embedId = embedItemElement.getAttribute("data-id");
+ checkFold(embedId, (zoomIn, action) => {
+ /// #if MOBILE
+ mobileBlur = true;
+ activeBlur();
+ openMobileFileById(protyle.app, embedId, zoomIn ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
+ /// #else
+ if (event.shiftKey) {
+ openFileById({
+ app: protyle.app,
+ id: embedId,
+ position: "bottom",
+ action,
+ zoomIn
+ });
+ } else if (event.altKey) {
+ openFileById({
+ app: protyle.app,
+ id: embedId,
+ position: "right",
+ action,
+ zoomIn
+ });
+ } else if (ctrlIsPressed) {
+ openFileById({
+ app: protyle.app,
+ id: embedId,
+ action: zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
+ zoomIn,
+ keepCursor: true,
+ });
+ }
+ /// #endif
+ });
+ // https://github.com/siyuan-note/siyuan/issues/12585
+ if (!ctrlIsPressed) {
+ event.stopPropagation();
+ return;
}
- /// #endif
- });
- // https://github.com/siyuan-note/siyuan/issues/12585
- if (!ctrlIsPressed) {
- event.stopPropagation();
- return;
}
}
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 7437fe31dc..393d85574f 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -1524,7 +1524,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return;
}
- if (!nodeElement.classList.contains("code-block") && !event.repeat && !isInEmbedBlock(nodeElement)) {
+ if (!nodeElement.classList.contains("code-block") && !event.repeat) {
let findToolbar = false;
protyle.options.toolbar.find((menuItem: IMenuItem) => {
if (!menuItem.hotkey) {
diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts
index 7b1b1324bc..6700725fe4 100644
--- a/app/src/protyle/wysiwyg/remove.ts
+++ b/app/src/protyle/wysiwyg/remove.ts
@@ -25,7 +25,7 @@ import {Constants} from "../../constants";
import {scrollCenter} from "../../util/highlightById";
import {isMobile} from "../../util/functions";
import {mathRender} from "../render/mathRender";
-import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";
+import {hasClosestBlock, hasClosestByClassName, isInEmbedBlock} from "../util/hasClosest";
import {getInstanceById} from "../../layout/util";
import {Tab} from "../../layout/Tab";
import {Backlink} from "../../layout/dock/Backlink";
@@ -34,6 +34,9 @@ import {onGet} from "../util/onGet";
import {setFold} from "../util/blockFold";
export const removeBlock = async (protyle: IProtyle, blockElement: Element, range: Range, type: "Delete" | "Backspace" | "remove") => {
+ if (isInEmbedBlock(blockElement)) {
+ return;
+ }
protyle.observerLoad?.disconnect();
// 删除后,防止滚动条滚动后调用 get 请求,因为返回的请求已查找不到内容块了
preventScroll(protyle);
diff --git a/app/src/protyle/wysiwyg/renderBacklink.ts b/app/src/protyle/wysiwyg/renderBacklink.ts
index 0dddec4cf2..fe4920df97 100644
--- a/app/src/protyle/wysiwyg/renderBacklink.ts
+++ b/app/src/protyle/wysiwyg/renderBacklink.ts
@@ -83,11 +83,6 @@ export const loadBreadcrumb = (protyle: IProtyle, element: HTMLElement) => {
disabledForeverProtyle(protyle);
} else if (window.siyuan.config.readonly || window.siyuan.config.editor.readOnly) {
disabledProtyle(protyle);
- } else if (element.parentElement.parentElement.classList.contains("protyle-wysiwyg__embed")) {
- // 嵌入块
- element.parentElement.parentElement.querySelectorAll('[contenteditable="true"][spellcheck]').forEach(item => {
- item.setAttribute("contenteditable", "false");
- });
}
});
};
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index a0a6a7253f..a8e35db691 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -285,9 +285,6 @@ const updateEmbed = (protyle: IProtyle, operation: IOperation) => {
const updateHTML = (item: Element, html: string) => {
const tempElement = document.createElement("template");
tempElement.innerHTML = protyle.lute.SpinBlockDOM(html);
- tempElement.content.querySelectorAll('[contenteditable="true"]').forEach(editItem => {
- editItem.setAttribute("contenteditable", "false");
- });
tempElement.content.querySelectorAll(".protyle-wysiwyg--select").forEach(selectItem => {
selectItem.classList.remove("protyle-wysiwyg--select");
});
diff --git a/kernel/model/block.go b/kernel/model/block.go
index 92db6a369f..5b0c690b22 100644
--- a/kernel/model/block.go
+++ b/kernel/model/block.go
@@ -1294,7 +1294,7 @@ func getEmbeddedBlock(trees map[string]*parse.Tree, sqlBlock *sql.Block, heading
fillBlockRefCount(nodes)
luteEngine := NewLute()
- luteEngine.RenderOptions.ProtyleContenteditable = false // 不可编辑
+ luteEngine.RenderOptions.ProtyleContenteditable = true
dom := renderBlockDOMByNodes(nodes, luteEngine)
content := renderBlockContentByNodes(nodes)
block = &Block{Box: def.Box, Path: def.Path, HPath: b.HPath, ID: def.ID, Type: def.Type.String(), Content: dom, Markdown: content /* 这里使用 Markdown 字段来临时存储 content */}