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

Vanessa2fe5ec93dc81
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 0fd19146b6..89f94381fd 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -796,7 +796,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (nextRange) {
const nextBlockElement = hasClosestBlock(nextRange.startContainer);
if (nextBlockElement) {
- removeBlock(protyle, nextBlockElement, nextRange);
+ removeBlock(protyle, nextBlockElement, nextRange, true);
}
}
event.stopPropagation();
diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts
index cc06a9781e..37a3c03ca6 100644
--- a/app/src/protyle/wysiwyg/list.ts
+++ b/app/src/protyle/wysiwyg/list.ts
@@ -3,6 +3,7 @@ import {transaction, updateTransaction} from "./transaction";
import {genEmptyBlock} from "../../block/util";
import * as dayjs from "dayjs";
import {Constants} from "../../constants";
+import {moveToPrevious} from "./remove";
export const updateListOrder = (listElement: Element, sIndex?: number) => {
if (listElement.getAttribute("data-subtype") !== "o") {
@@ -277,7 +278,15 @@ export const breakList = (protyle: IProtyle, blockElement: Element, range: Range
focusByWbr(protyle.wysiwyg.element, range);
};
-export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: Range) => {
+/**
+ * 缩进列表
+ * @param protyle
+ * @param liItemElements
+ * @param range
+ * @param isDelete
+ * @param deleteElement 末尾反向删除时才会传入
+ */
+export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: Range, isDelete = false, deleteElement:Element) => {
const liElement = liItemElements[0].parentElement;
const liId = liElement.getAttribute("data-node-id");
if (!liId) {
@@ -295,6 +304,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
const doOperations: IOperation[] = [];
const undoOperations: IOperation[] = [];
range.collapse(false);
+ moveToPrevious(deleteElement, range, isDelete);
range.insertNode(document.createElement("wbr"));
let startIndex;
if (!liItemElements[0].previousElementSibling && liElement.getAttribute("data-subtype") === "o") {
@@ -446,6 +456,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
if (liElement.childElementCount === 2 && parentLiItemElement.childElementCount === 3) {
// 列表项里仅有包含一个列表项的列表,如 1. 1. 1 https://github.com/siyuan-note/insider/issues/494
range.collapse(false);
+ moveToPrevious(deleteElement, range, isDelete);
range.insertNode(document.createElement("wbr"));
const html = parentLiItemElement.outerHTML;
liItemElements[0].firstElementChild.remove();
@@ -457,6 +468,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
}
range.collapse(false);
+ moveToPrevious(deleteElement, range, isDelete);
range.insertNode(document.createElement("wbr"));
const doOperations: IOperation[] = [];
const undoOperations: IOperation[] = [];
diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts
index 6555124b6c..770a059147 100644
--- a/app/src/protyle/wysiwyg/remove.ts
+++ b/app/src/protyle/wysiwyg/remove.ts
@@ -23,9 +23,9 @@ import {Constants} from "../../constants";
import {scrollCenter} from "../../util/highlightById";
import {isMobile} from "../../util/functions";
-const removeLi = (protyle: IProtyle, blockElement: Element, range: Range) => {
+const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDelete = false) => {
if (!blockElement.parentElement.previousElementSibling && blockElement.parentElement.nextElementSibling && blockElement.parentElement.nextElementSibling.classList.contains("protyle-attr")) {
- listOutdent(protyle, [blockElement.parentElement], range);
+ listOutdent(protyle, [blockElement.parentElement], range, isDelete, blockElement);
return;
}
// 第一个子列表合并到上一个块的末尾
@@ -67,6 +67,7 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range) => {
if (blockElement.parentElement.parentElement.classList.contains("protyle-wysiwyg")) {
return;
}
+ moveToPrevious(blockElement, range, isDelete);
range.insertNode(document.createElement("wbr"));
const listElement = blockElement.parentElement.parentElement;
const listHTML = listElement.outerHTML;
@@ -116,6 +117,7 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range) => {
}
const listItemId = listItemElement.getAttribute("data-node-id");
const listElement = listItemElement.parentElement;
+ moveToPrevious(blockElement, range, isDelete);
range.insertNode(document.createElement("wbr"));
const html = listElement.outerHTML;
const doOperations: IOperation[] = [];
@@ -184,7 +186,7 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range) => {
focusByWbr(previousLastElement.parentElement, range);
};
-export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Range) => {
+export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Range, isDelete = false) => {
// 删除后,防止滚动条滚动后调用 get 请求,因为返回的请求已查找不到内容块了
preventScroll(protyle);
const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
@@ -362,7 +364,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
}
if (blockElement.parentElement.classList.contains("li") && blockElement.previousElementSibling.classList.contains("protyle-action")) {
- removeLi(protyle, blockElement, range);
+ removeLi(protyle, blockElement, range, isDelete);
return;
}
@@ -510,3 +512,15 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
}
focusByWbr(protyle.wysiwyg.element, range);
};
+
+export const moveToPrevious = (blockElement: Element, range: Range, isDelete: boolean) => {
+ if (isDelete) {
+ const previousBlockElement = getPreviousBlock(blockElement)
+ if (previousBlockElement) {
+ const previousEditElement = getContenteditableElement(getLastBlock(previousBlockElement))
+ if (previousEditElement) {
+ setLastNodeRange(previousEditElement, range, false);
+ }
+ }
+ }
+}