Convert bullet to task when Task: Cycle State is called

Fixes #1074
pull/1099/head
Abin Simon 2024-09-28 11:43:41 +05:30
parent 4bc6ed719c
commit 9387bd988c
1 changed files with 30 additions and 11 deletions

View File

@ -178,9 +178,18 @@ export function previewTaskToggle(eventString: string) {
}
}
async function cycleTaskState(
node: ParseTree,
) {
async function convertListItemToTask(node: ParseTree){
const listMark = node.children![0];
await editor.dispatch({
changes: {
from: listMark.from,
to: listMark.to,
insert: "- [ ]",
},
});
}
async function cycleTaskState(node: ParseTree) {
const stateText = node.children![1].text!;
let changeTo: string | undefined;
if (completeStates.includes(stateText)) {
@ -325,17 +334,27 @@ export async function taskCycleCommand() {
return;
}
console.log("Node", node);
const taskNode = node.type === "Task"
? node
: findParentMatching(node!, (n) => n.type === "Task");
if (!taskNode) {
const taskNode =
node.type === "Task"
? node
: findParentMatching(node!, (n) => n.type === "Task");
if (taskNode) {
const taskState = findNodeOfType(taskNode!, "TaskState");
if (taskState) {
await cycleTaskState(taskState);
}
return
}
// Convert a bullet point to a task
const listItem = findParentMatching(node!, (n) => n.type === "ListItem");
if (!listItem) {
await editor.flashNotification("No task at cursor");
return;
}
const taskState = findNodeOfType(taskNode!, "TaskState");
if (taskState) {
await cycleTaskState(taskState);
}
convertListItemToTask(listItem);
}
export async function postponeCommand() {