Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(ckeditor): new to-do row no longer inherits the custom task state on Enter
Elian Dorandd0aa4d53458
diff --git a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.spec.ts b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.spec.tsindex 2e2ab2034d..97547be7b1 100644--- a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.spec.ts+++ b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.spec.ts@@ -4,6 +4,7 @@ import { _setModelData as setModelData, ClassicEditor, Essentials, keyCodes, Lisimport { beforeEach, describe, expect, it, vi } from "vitest";import { createTestEditor } from "../../../test/editor-kit.js";+import TodoListUncheckOnEnter from "../todo_list_uncheck_on_enter.js";import TodoListMultistateEditing, { getActiveTaskStates, getConfiguredTaskStates, TASK_STATE_ATTRIBUTE } from "./todo_list_multistate_editing.js";const TODO_LIST_CHECKED_ATTRIBUTE = "todoListChecked";@@ -18,7 +19,9 @@ const CUSTOM_STATES: TaskStateDef[] = [const TODO_FIXTURE = '<paragraph listIndent="0" listItemId="t-a" listType="todo">Task[]</paragraph>';async function createEditor(config: Record<string, unknown> = {}): Promise<ClassicEditor> {- return await createTestEditor([Essentials, Paragraph, List, TodoList, TodoListMultistateEditing], config);+ // TodoListUncheckOnEnter ships alongside multistate in the real build; include it so the+ // Enter-reset behavior is exercised end to end.+ return await createTestEditor([Essentials, Paragraph, List, TodoList, TodoListUncheckOnEnter, TodoListMultistateEditing], config);}function getBlock(editor: ClassicEditor, index: number): ModelElement {@@ -243,6 +246,37 @@ describe("TodoListMultistateEditing", () => {expect(getBlock(editor, 0).getAttribute(TODO_LIST_CHECKED_ATTRIBUTE)).toBe(true);});+ it("Enter on a checked/custom-state row starts the new row unchecked with no state (#10084)", () => {+ // A native completed (checked) row: pressing Enter must not carry the check over.+ setModelData(editor.model,+ '<paragraph listIndent="0" listItemId="t-a" listType="todo" todoListChecked="true">Task[]</paragraph>');+ editor.execute("enter");+ const newNative = getBlock(editor, 1);+ expect(newNative.getAttribute("listType")).toBe("todo");+ expect(newNative.hasAttribute(TODO_LIST_CHECKED_ATTRIBUTE)).toBe(false);+ expect(newNative.hasAttribute(TASK_STATE_ATTRIBUTE)).toBe(false);++ // A custom completed state ('review', isCompleted: true) must not carry the state+ // or the (post-fixer-forced) checkbox over to the new row.+ setModelData(editor.model, TODO_FIXTURE);+ editor.execute("setTaskState", { state: "review" });+ editor.execute("enter");+ const newCustom = getBlock(editor, 1);+ expect(newCustom.hasAttribute(TASK_STATE_ATTRIBUTE)).toBe(false);+ expect(newCustom.hasAttribute(TODO_LIST_CHECKED_ATTRIBUTE)).toBe(false);++ // The original row keeps its state.+ expect(getBlock(editor, 0).getAttribute(TASK_STATE_ATTRIBUTE)).toBe("review");+ expect(getBlock(editor, 0).getAttribute(TODO_LIST_CHECKED_ATTRIBUTE)).toBe(true);+ });++ it("Enter outside a todo list leaves the new block untouched", () => {+ // The afterExecute reset only applies to todo blocks.+ setModelData(editor.model, "<paragraph>Hello[]</paragraph>");+ editor.execute("enter");+ expect(getBlock(editor, 1).getAttribute("listType")).toBe(undefined);+ });+it("post-fixer leaves a cleared (unknown) state alone instead of forcing the checkbox", () => {// 'ghost' is not in the config → stateByName lookup misses → no checkbox forcing.editor.model.change((writer) => {diff --git a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.tsindex 3799070f67..638e5f51c9 100644--- a/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts+++ b/packages/ckeditor5/src/plugins/todo_list_multistate/todo_list_multistate_editing.ts@@ -2,6 +2,8 @@ import { DEFAULT_TASK_STATES, DONE_STATE_NAME, isAnchorState, NONE_STATE_NAME, timport { Tooltip } from "bootstrap";import { Command, getEnvKeystrokeText, ListEditing, Plugin, TodoList, type Editor, type ModelElement, type ViewElement } from "ckeditor5";+import { onTodoRowSplit } from "../todo_list_uncheck_on_enter.js";+export const TASK_STATE_ATTRIBUTE = "taskState";const TODO_LIST_CHECKED_ATTRIBUTE = "todoListChecked";@@ -117,6 +119,18 @@ export default class TodoListMultistateEditing extends Plugin {}});+ // A new row split off with Enter inherits the previous row's `taskState` (writer.split+ // copies block attributes). Drop it so each new task starts in the plain "none" state.+ // Without this, `TodoListUncheckOnEnter` clears the new row's checkbox but the inherited+ // `taskState` survives, leaving an inconsistent row (e.g. a completed "review" state with+ // an unchecked box) and carrying #10084 over to custom states. The post-fixer below can't+ // catch it: it reacts to taskState *changes*, but on a split the attribute arrives as part+ // of the inserted node, not as a diff. `TodoListUncheckOnEnter` clears the companion+ // `todoListChecked` via the same seam.+ onTodoRowSplit(this, (writer, block) => {+ writer.removeAttribute(TASK_STATE_ATTRIBUTE, block);+ });+editor.model.document.registerPostFixer((writer) => {const differ = editor.model.document.differ;const stateChanged = new Set<ModelElement>();