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

Vanessa751e790c7914
diff --git a/app/src/protyle/wysiwyg/turnIntoList.ts b/app/src/protyle/wysiwyg/turnIntoList.ts
index c11d9ecba9..d1d6015858 100644
--- a/app/src/protyle/wysiwyg/turnIntoList.ts
+++ b/app/src/protyle/wysiwyg/turnIntoList.ts
@@ -1,16 +1,16 @@
-import {transaction} from "./transaction";
+import {transaction, updateTransaction} from "./transaction";
import {focusByWbr} from "../util/selection";
+import * as dayjs from "dayjs";
export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement: HTMLElement, editElement: HTMLElement) => {
if (type !== "NodeCodeBlock" &&
+ blockElement.parentElement.getAttribute("data-subtype") !== "t" &&
(
["[ ]", "[x]", "[X]", "【 】", "【x】", "【X】"].includes(editElement.innerHTML.substring(0, 3)) ||
["[]", "【】"].includes(editElement.innerHTML.substring(0, 2))
)
) {
- const doOperation: IOperation[] = []
- const undoOperation: IOperation[] = []
- const contextStartIndex = (editElement.innerHTML.indexOf("]") || editElement.innerHTML.indexOf("]")) + 1;
+ const contextStartIndex = (editElement.innerHTML.indexOf("]") + 1) || (editElement.innerHTML.indexOf("】") + 1);
const isDone = editElement.innerHTML.substring(1, 2).toLowerCase() === "x";
if (blockElement.parentElement.classList.contains("li") &&
blockElement.parentElement.childElementCount === 3 // https://ld246.com/article/1659315815506
@@ -18,9 +18,20 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement:
// 仅有一项的列表才可转换
if (!blockElement.parentElement.parentElement.classList.contains("protyle-wysiwyg") && // https://ld246.com/article/1659315815506
blockElement.parentElement.parentElement.childElementCount === 2) {
- `<div data-subtype="t" data-node-id="${blockElement.parentElement.parentElement.getAttribute("data-node-id")}" data-type="NodeList" class="list"><div data-marker="*" data-subtype="t" data-node-id="${blockElement.parentElement.getAttribute("data-node-id")}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div><div data-node-id="${id}" data-type="NodeParagraph" class="p"><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}"><wbr></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`;
+ const liElement = blockElement.parentElement.parentElement;
+ const oldHTML = liElement.outerHTML;
+ liElement.setAttribute("data-subtype", "t");
+ liElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
+ blockElement.parentElement.setAttribute("data-subtype", "t");
+ if (isDone) {
+ blockElement.parentElement.classList.add("protyle-task--done");
+ }
+ blockElement.previousElementSibling.outerHTML = `<div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div>`
+ editElement.innerHTML = editElement.innerHTML.substring(contextStartIndex);
+ updateTransaction(protyle, liElement.getAttribute("data-node-id"), liElement.outerHTML, oldHTML);
+ return true;
}
- return true;
+ return false;
} else {
const id = blockElement.getAttribute("data-node-id")
const newId = Lute.NewNodeID();