parent
4bc6ed719c
commit
9387bd988c
|
@ -178,9 +178,18 @@ export function previewTaskToggle(eventString: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cycleTaskState(
|
async function convertListItemToTask(node: ParseTree){
|
||||||
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!;
|
const stateText = node.children![1].text!;
|
||||||
let changeTo: string | undefined;
|
let changeTo: string | undefined;
|
||||||
if (completeStates.includes(stateText)) {
|
if (completeStates.includes(stateText)) {
|
||||||
|
@ -325,17 +334,27 @@ export async function taskCycleCommand() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("Node", node);
|
console.log("Node", node);
|
||||||
const taskNode = node.type === "Task"
|
const taskNode =
|
||||||
? node
|
node.type === "Task"
|
||||||
: findParentMatching(node!, (n) => n.type === "Task");
|
? node
|
||||||
if (!taskNode) {
|
: 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");
|
await editor.flashNotification("No task at cursor");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const taskState = findNodeOfType(taskNode!, "TaskState");
|
|
||||||
if (taskState) {
|
convertListItemToTask(listItem);
|
||||||
await cycleTaskState(taskState);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function postponeCommand() {
|
export async function postponeCommand() {
|
||||||
|
|
Loading…
Reference in New Issue