Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

Fix task list checkbox toggle (#17840)

Jeffrey Chen5adec40ecedf
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 570abd0fae..803cf0e38e 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -45,6 +45,7 @@ import {
isNotEditBlock
} from "./getBlock";
import {transaction, updateTransaction} from "./transaction";
+import {toggleTaskListItem} from "./list";
import {hideElements} from "../ui/hideElements";
/// #if !BROWSER
import {ipcRenderer} from "electron";
@@ -3079,19 +3080,12 @@ export class WYSIWYG {
} else {
if (actionElement.classList.contains("protyle-action--task")) {
if (!protyle.disabled) {
- const html = actionElement.parentElement.outerHTML;
- if (actionElement.parentElement.classList.contains("protyle-task--done")) {
- actionElement.querySelector("use").setAttribute("xlink:href", "#iconUncheck");
- actionElement.parentElement.classList.remove("protyle-task--done");
- actionElement.parentElement.setAttribute("data-task", " ");
- } else {
- actionElement.querySelector("use").setAttribute("xlink:href", "#iconCheck");
- actionElement.parentElement.classList.add("protyle-task--done");
- actionElement.parentElement.setAttribute("data-task", "X");
- }
- actionElement.parentElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
- actionElement.parentElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true");
- updateTransaction(protyle, actionElement.parentElement, html);
+ 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);
}
} 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 6be774af19..e75cfe2ab0 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -46,7 +46,7 @@ import {
updateTransaction
} from "./transaction";
import {fontEvent} from "../toolbar/Font";
-import {addSubList, listIndent, listOutdent} from "./list";
+import {addSubList, listIndent, listOutdent, toggleTaskListItem} from "./list";
import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
import {cancelSB, insertEmptyBlock, jumpToParent} from "../../block/util";
import {isLocalPath} from "../../util/pathName";
@@ -1713,13 +1713,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return;
}
const html = taskItemElement.outerHTML;
- if (taskItemElement.classList.contains("protyle-task--done")) {
- taskItemElement.querySelector("use").setAttribute("xlink:href", "#iconUncheck");
- taskItemElement.classList.remove("protyle-task--done");
- } else {
- taskItemElement.querySelector("use").setAttribute("xlink:href", "#iconCheck");
- taskItemElement.classList.add("protyle-task--done");
- }
+ toggleTaskListItem(taskItemElement);
taskItemElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
updateTransaction(protyle, taskItemElement, html);
event.preventDefault();
diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts
index b4c7600efa..18868060b0 100644
--- a/app/src/protyle/wysiwyg/list.ts
+++ b/app/src/protyle/wysiwyg/list.ts
@@ -58,6 +58,20 @@ export const updateListOrder = (listElement: Element, sIndex?: number) => {
});
};
+export const toggleTaskListItem = (taskItemElement: Element): void => {
+ const marker = taskItemElement.getAttribute("data-task");
+ const useElement = taskItemElement.querySelector("use");
+ if (marker !== null && marker !== " ") {
+ taskItemElement.setAttribute("data-task", " ");
+ taskItemElement.classList.remove("protyle-task--done");
+ useElement?.setAttribute("xlink:href", "#iconUncheck");
+ } else {
+ taskItemElement.setAttribute("data-task", "X");
+ taskItemElement.classList.add("protyle-task--done");
+ useElement?.setAttribute("xlink:href", "#iconCheck");
+ }
+};
+
export const genListItemElement = (listItemElement: Element, offset = 0, wbr = false, startIndex?: number) => {
const element = document.createElement("template");
const type = listItemElement.getAttribute("data-subtype");
@@ -167,6 +181,10 @@ export const listIndent = (protyle: IProtyle, liItemElements: Element[], range:
previousID: index === 0 ? previousElement.getAttribute("data-node-id") : previousID,
});
previousID = item.getAttribute("data-node-id");
+ if (item.getAttribute("data-subtype") === subtype) {
+ lastPreviousElement.lastElementChild.before(item);
+ return;
+ }
item.setAttribute("data-subtype", subtype);
const actionElement = item.querySelector(".protyle-action");
if (subtype === "o") {