Open louwers opened 1 year ago
Nice idea. Thank you.
I guess there would need to be shortcuts for setting Due and Start dates too.
I have a custom command right now that is a bit hacky.
If a task is already done and it is scheduled, I also set it as "todo". This way I can easily manually schedule recurring tasks.
editor.setCursor(getLineEndPos(editor.getCursor().line, editor));
const currentLine = () => editor.getLine(editor.getCursor().line);
const scheduledPattern = / β³ \d\d\d\d-\d\d-\d\d/;
const donePattern = /^- \[x\]/;
if (isScheduled() && isDone()) {
unschedule();
setTodo();
schedule();
} else if (isScheduled()) {
unschedule();
} else {
unschedule();
schedule();
}
function isDone() {
return currentLine().match(donePattern);
}
function replace(pattern: RegExp, withThis: string) {
const currentLine = editor.getLine(editor.getCursor().line);
const newLine = currentLine.replace(pattern, withThis);
editor.replaceRange(
newLine,
{
ch: 0,
line: editor.getCursor().line,
},
getLineEndPos(editor.getCursor().line, editor),
);
}
function isScheduled() {
return currentLine().match(scheduledPattern);
}
if (isScheduled()) {
return;
}
function setTodo() {
replace(donePattern, "- [ ]");
}
function schedule() {
editor.replaceRange(
`${
currentLine()[currentLine().length - 1] === " " ? "" : " "
}β³ ${moment().format("YYYY-MM-DD")}`,
editor.getCursor(),
);
}
function unschedule() {
replace(scheduledPattern, " ");
}
@louwers, wow. Thank you. Please could you share the steps needed to use the code above?
Maybe I will try to submit a pull request.
The above code is wrapped in a
this.addCommand({
id: "schedule-task-today",
name: "Schedule Task Today",
editorCallback: (editor: Editor) => {
call and uses this helper function
export const getLineEndPos = (
line: number,
editor: Editor,
): EditorPosition => ({
line,
ch: editor.getLine(line).length,
});
But this code is quite hacky as I have said, so I would hold off intergrating it.
Oh right, thanks - so if I now understand correctly, itβs a modification to the Tasks code itself?
I created a separate plugin (that is why I am using regex and not the API of the plugin).
β οΈ Please check that this feature request hasn't been suggested before.
π Feature description
I am aware of the Auto-suggest feature, but I don't like using it, because it highjacks the down arrow.
I would like to go through a list of tasks quickly and schedule a certain task for today with a keyboard shortcut.
βοΈ Solution
A shortcut that sets the scheduled day to today on the task that is currently selected.
β Alternatives
No response
π Additional Context
No response