2022-03-27 07:55:29 +00:00
|
|
|
import type { ClickEvent } from "../../webapp/app_event";
|
2022-03-25 11:03:06 +00:00
|
|
|
import { syscall } from "../lib/syscall";
|
2022-02-26 16:50:50 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|