diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 803cf0e38..b0e91a25f 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -3080,12 +3080,7 @@ export class WYSIWYG { } else { if (actionElement.classList.contains("protyle-action--task")) { if (!protyle.disabled) { - const taskItemElement = actionElement.parentElement; - const html = taskItemElement.outerHTML; - toggleTaskListItem(taskItemElement); - taskItemElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); - taskItemElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); - updateTransaction(protyle, taskItemElement, html); + toggleTaskListItem(protyle, actionElement.parentElement); } } else if (window.siyuan.config.editor.listItemDotNumberClickFocus) { if (protyle.block.showAll && protyle.block.id === actionId) { diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index e75cfe2ab..58cd207c7 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -1712,10 +1712,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (!taskItemElement) { return; } - const html = taskItemElement.outerHTML; - toggleTaskListItem(taskItemElement); - taskItemElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); - updateTransaction(protyle, taskItemElement, html); + toggleTaskListItem(protyle, taskItemElement); event.preventDefault(); event.stopPropagation(); return; diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts index 18868060b..ad9a032da 100644 --- a/app/src/protyle/wysiwyg/list.ts +++ b/app/src/protyle/wysiwyg/list.ts @@ -58,7 +58,8 @@ export const updateListOrder = (listElement: Element, sIndex?: number) => { }); }; -export const toggleTaskListItem = (taskItemElement: Element): void => { +export const toggleTaskListItem = (protyle: IProtyle, taskItemElement: Element): void => { + const html = taskItemElement.outerHTML; const marker = taskItemElement.getAttribute("data-task"); const useElement = taskItemElement.querySelector("use"); if (marker !== null && marker !== " ") { @@ -70,6 +71,9 @@ export const toggleTaskListItem = (taskItemElement: Element): void => { taskItemElement.classList.add("protyle-task--done"); useElement?.setAttribute("xlink:href", "#iconCheck"); } + taskItemElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); + taskItemElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true"); + updateTransaction(protyle, taskItemElement, html); }; export const genListItemElement = (listItemElement: Element, offset = 0, wbr = false, startIndex?: number) => {