mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 15:58:49 +01:00
🎨 thub.com/siyuan-note/siyuan/issues/14496
This commit is contained in:
parent
95c666cdd3
commit
4d0c136a56
3 changed files with 39 additions and 3 deletions
|
|
@ -47,6 +47,7 @@ import {getAllModels} from "../layout/getAll";
|
|||
/// #endif
|
||||
import {isSupportCSSHL} from "./render/searchMarkRender";
|
||||
import {renderAVAttribute} from "./render/av/blockAttr";
|
||||
import {genEmptyElement} from "../block/util";
|
||||
|
||||
export class Protyle {
|
||||
|
||||
|
|
@ -175,6 +176,19 @@ export class Protyle {
|
|||
return true;
|
||||
} else {
|
||||
onTransaction(this.protyle, item, false);
|
||||
// 反链面板移除元素后,文档为空
|
||||
if (this.protyle.wysiwyg.element.childElementCount === 0) {
|
||||
const newID = Lute.NewNodeID();
|
||||
const emptyElement = genEmptyElement(false, false, newID);
|
||||
this.protyle.wysiwyg.element.append(emptyElement);
|
||||
transaction(this.protyle, [{
|
||||
action: "insert",
|
||||
data: emptyElement.outerHTML,
|
||||
id: newID,
|
||||
parentID: this.protyle.block.parentID
|
||||
}]);
|
||||
this.protyle.undo.clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ import {Constants} from "../../constants";
|
|||
import {scrollCenter} from "../../util/highlightById";
|
||||
import {isMobile} from "../../util/functions";
|
||||
import {mathRender} from "../render/mathRender";
|
||||
import {hasClosestByClassName} from "../util/hasClosest";
|
||||
import {getInstanceById} from "../../layout/util";
|
||||
import {Tab} from "../../layout/Tab";
|
||||
import {Backlink} from "../../layout/dock/Backlink";
|
||||
|
||||
export const removeBlock = async (protyle: IProtyle, blockElement: Element, range: Range, type: "Delete" | "Backspace" | "remove") => {
|
||||
// 删除后,防止滚动条滚动后调用 get 请求,因为返回的请求已查找不到内容块了
|
||||
|
|
@ -69,7 +73,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
|
|||
sideElement = getPreviousBlock(topElement);
|
||||
}
|
||||
}
|
||||
if (!sideElement) {
|
||||
if (!sideElement && !protyle.options.backlinkData) {
|
||||
sideElement = topElement.parentElement || protyle.wysiwyg.element.firstElementChild;
|
||||
sideIsNext = false;
|
||||
}
|
||||
|
|
@ -189,6 +193,24 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
|
|||
}
|
||||
|
||||
hideElements(["util"], protyle);
|
||||
if (!sideElement) {
|
||||
const backlinkElement = hasClosestByClassName(protyle.element, "sy__backlink", true)
|
||||
if (backlinkElement) {
|
||||
const backLinkTab = getInstanceById(backlinkElement.getAttribute("data-id"));
|
||||
if (backLinkTab instanceof Tab && backLinkTab.model instanceof Backlink) {
|
||||
const editors = backLinkTab.model.editors
|
||||
editors.find((item, index) => {
|
||||
if (item.protyle.element.isSameNode(protyle.element)) {
|
||||
item.destroy();
|
||||
editors.splice(index, 1);
|
||||
item.protyle.element.previousElementSibling.remove();
|
||||
item.protyle.element.remove();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
const blockType = blockElement.getAttribute("data-type");
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ const promiseTransaction = () => {
|
|||
if (operation.action === "delete" || operation.action === "append") {
|
||||
if (protyle.options.backlinkData) {
|
||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => {
|
||||
if (!isInEmbedBlock(item)) {
|
||||
if (!isInEmbedBlock(item) && !item.contains(range.startContainer)) {
|
||||
item.remove();
|
||||
}
|
||||
});
|
||||
|
|
@ -204,7 +204,7 @@ const promiseTransaction = () => {
|
|||
});
|
||||
} else {
|
||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.parentID}"]`)).forEach(item => {
|
||||
if (!isInEmbedBlock(item)) {
|
||||
if (!isInEmbedBlock(item) && !item.contains(range.startContainer)) {
|
||||
// 列表特殊处理
|
||||
if (item.firstElementChild && item.firstElementChild.classList.contains("protyle-action") &&
|
||||
item.firstElementChild.nextElementSibling.getAttribute("data-node-id") !== operation.id) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue