Skip to content

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

:art: fix https://github.com/siyuan-note/siyuan/issues/7624

Vanessadde4c66033f6
diff --git a/app/src/protyle/upload/index.ts b/app/src/protyle/upload/index.ts
index 3f7ab60c26..0bf4575fc0 100644
--- a/app/src/protyle/upload/index.ts
+++ b/app/src/protyle/upload/index.ts
@@ -6,6 +6,8 @@ import {fetchPost} from "../../util/fetch";
import {getEditorRange} from "../util/selection";
import {pathPosix} from "../../util/pathName";
import {genAssetHTML} from "../../asset/renderAssets";
+import {hasClosestBlock} from "../util/hasClosest";
+import {getContenteditableElement} from "../wysiwyg/getBlock";
export class Upload {
public element: HTMLElement;
@@ -96,7 +98,25 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => {
if (errorTip) {
showMessage(errorTip);
}
-
+ let insertBlock = true;
+ const range = getEditorRange(protyle.wysiwyg.element);
+ if (range.toString() === "" && range.startContainer.nodeType === 3 && protyle.toolbar.getCurrentType(range).length > 0) {
+ // 防止链接插入其他元素中 https://ld246.com/article/1676003478664
+ range.setEndAfter(range.startContainer.parentElement);
+ range.collapse(false);
+ }
+ // https://github.com/siyuan-note/siyuan/issues/7624
+ const nodeElement = hasClosestBlock(range.startContainer)
+ if (nodeElement) {
+ if (nodeElement.classList.contains("table")) {
+ insertBlock = false;
+ } else {
+ const editableElement = getContenteditableElement(nodeElement);
+ if (editableElement && editableElement.textContent !== "" && nodeElement.classList.contains("p")) {
+ insertBlock = false;
+ }
+ }
+ }
let succFileText = "";
const keys = Object.keys(response.data.succMap);
keys.forEach((key, index) => {
@@ -106,17 +126,15 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => {
succFileText += genAssetHTML(type, path, filename.substring(0, filename.length - type.length), filename);
if (!Constants.SIYUAN_ASSETS_AUDIO.includes(type) && !Constants.SIYUAN_ASSETS_VIDEO.includes(type) &&
keys.length - 1 !== index) {
- succFileText += "\n\n";
+ if (insertBlock) {
+ succFileText += "\n\n";
+ } else {
+ succFileText += "\n";
+ }
}
});
- const range = getEditorRange(protyle.wysiwyg.element);
- if (range.toString() === "" && range.startContainer.nodeType === 3 && protyle.toolbar.getCurrentType(range).length > 0) {
- // 防止链接插入其他元素中 https://ld246.com/article/1676003478664
- range.setEndAfter(range.startContainer.parentElement);
- range.collapse(false);
- }
// 避免插入代码块中,其次因为都要独立成块 https://github.com/siyuan-note/siyuan/issues/7607
- insertHTML(succFileText, protyle, true);
+ insertHTML(succFileText, protyle, insertBlock);
};
export const uploadLocalFiles = (files: string[], protyle: IProtyle, isUpload: boolean) => {
diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts
index 4561fc37fb..755066a63d 100644
--- a/app/src/protyle/util/insertHTML.ts
+++ b/app/src/protyle/util/insertHTML.ts
@@ -187,7 +187,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
lastElement = item;
}
});
- if (editableElement && editableElement.textContent === "") {
+ if (editableElement && editableElement.textContent === "" && blockElement.classList.contains("p")) {
// 选中当前块所有内容粘贴再撤销会导致异常 https://ld246.com/article/1662542137636
doOperation.find((item, index) => {
if (item.id === id) {