parent
4bc6ed719c
commit
9387bd988c
|
@ -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"
|
||||
const taskNode =
|
||||
node.type === "Task"
|
||||
? node
|
||||
: findParentMatching(node!, (n) => n.type === "Task");
|
||||
if (!taskNode) {
|
||||
await editor.flashNotification("No task at cursor");
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
convertListItemToTask(listItem);
|
||||
}
|
||||
|
||||
export async function postponeCommand() {
|
||||
|
|
Loading…
Reference in New Issue