1
0
silverbullet/plugins/core/task.ts
2022-02-26 17:50:50 +01:00

32 lines
838 B
TypeScript

import { ClickEvent } from "../../webapp/src/app_event.ts";
import { syscall } from "./lib/syscall.ts";
export async function taskToggle(event: ClickEvent) {
let syntaxNode = await syscall("editor.getSyntaxNodeAtPos", event.pos);
if (syntaxNode && syntaxNode.name === "TaskMarker") {
if (syntaxNode.text === "[x]" || syntaxNode.text === "[X]") {
await syscall("editor.dispatch", {
changes: {
from: syntaxNode.from,
to: syntaxNode.to,
insert: "[ ]",
},
selection: {
anchor: event.pos,
},
});
} else {
await syscall("editor.dispatch", {
changes: {
from: syntaxNode.from,
to: syntaxNode.to,
insert: "[x]",
},
selection: {
anchor: event.pos,
},
});
}
}
}