Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/features/editor/codemirror/tasklist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const createDefaultTaskHandler = (
): TaskHandler => ({
onTaskClosed: ({ taskContent, originalLine, section, pos, view }: OnTaskClosed) => {
const taskIdentifier = generateTaskIdentifier(taskContent);
const timestamp = new Date().toISOString();

// Auto Flush
if (taskAutoFlushMode === "instant" && view) {
Expand All @@ -41,10 +40,12 @@ export const createDefaultTaskHandler = (
const task = Object.freeze({
id: taskIdentifier,
content: taskContent,
completed: true,
createdAt: new Date().toISOString(),
completedAt: new Date().toISOString(),
originalLine,
taskIdentifier,
section,
completedAt: timestamp,
});

taskStorage.save(task);
Expand All @@ -58,3 +59,6 @@ export const createDefaultTaskHandler = (
export const createChecklistPlugin = (taskHandler: TaskHandler): Extension => {
return [taskDecoration, taskHoverField, taskMouseInteraction(taskHandler), taskAutoComplete, taskKeyMap];
};

export { taskKeyBindings } from "./keymap";
export { taskAgingPlugin } from "./task-aging";
36 changes: 36 additions & 0 deletions src/features/editor/codemirror/tasklist/task-aging.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, it, expect } from "vitest";
import { EditorState } from "@codemirror/state";
import { taskAgingPlugin } from "./task-aging";

describe("Task Aging", () => {
it("should create editor with task aging plugin without errors", () => {
// Test that the plugin initializes correctly with task content
const state = EditorState.create({
doc: "- [ ] Test task\n- [ ] Another task",
extensions: [taskAgingPlugin],
});

expect(state).toBeDefined();
expect(state.doc.toString()).toBe("- [ ] Test task\n- [ ] Another task");
});

it("should create editor with task aging plugin", () => {
const state = EditorState.create({
doc: "- [ ] New task\n- [x] Completed task",
extensions: [taskAgingPlugin],
});

expect(state).toBeDefined();
expect(state.doc.toString()).toBe("- [ ] New task\n- [x] Completed task");
});

it("should handle nested tasks", () => {
const state = EditorState.create({
doc: "- [ ] Parent task\n - [ ] Child task\n - [ ] Another child",
extensions: [taskAgingPlugin],
});

expect(state).toBeDefined();
expect(state.doc.toString()).toBe("- [ ] Parent task\n - [ ] Child task\n - [ ] Another child");
});
});
Loading