From 751e790c791427c68d9233e440120d3cbc8735e1 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 27 Apr 2023 10:59:20 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/8108 --- app/src/protyle/wysiwyg/turnIntoList.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/protyle/wysiwyg/turnIntoList.ts b/app/src/protyle/wysiwyg/turnIntoList.ts index c11d9ecba..d1d601585 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) { - `
`; + 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 = `
` + 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();