mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-07-03 14:09:06 +02:00
Fix task list checkbox toggle (#17840)
* 🐛 Fix task list checkbox toggle https://github.com/siyuan-note/siyuan/issues/17839 * 🐛 Fix task list checkbox toggle https://github.com/siyuan-note/siyuan/issues/17839
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user