This commit is contained in:
Vanessa 2023-03-13 11:42:18 +08:00
parent 0f62506d25
commit dde4c66033
2 changed files with 28 additions and 10 deletions

View file

@ -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) => {

View file

@ -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) {