Skip to content

Commit

Permalink
fix: ivan-lednev#421 dataview task mouseGripDown
Browse files Browse the repository at this point in the history
  • Loading branch information
bayerju committed Jul 14, 2024
1 parent 5ae2272 commit b8c1ce5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/ui/hooks/use-edit/create-edit-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { get, Readable, Writable } from "svelte/store";

import { ObsidianFacade } from "../../../service/obsidian-facade";
import { PlacedTask, UnscheduledTask } from "../../../types";
import { createTask } from "../../../util/task-utils";
import { createTask, getSchedueldDayFromText } from "../../../util/task-utils";

import { EditMode, EditOperation } from "./types";

Expand Down Expand Up @@ -55,12 +55,17 @@ export function createEditHandlers({
const withAddedTime = {
...task,
startMinutes: get(cursorMinutes),
// todo: add a proper fix
startTime: task.location
? getDateFromPath(task.location.path, "day") || window.moment()
: window.moment(),
startTime:
getSchedueldDayFromText(task) ||
getDateFromPath(task.location.path, "day"),
};

if (!withAddedTime.startTime) {
throw new Error(
"Could not get the day of the task. It should be provided through the Tasks Plugins schduled feature, or the path of the daily note. If you did provide the day through one of these options, please report the issue at https://github.com/ivan-lednev/obsidian-day-planner/issues",
);
}

startEdit({ task: withAddedTime, mode: EditMode.DRAG, day });
}

Expand Down
17 changes: 16 additions & 1 deletion src/util/task-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
scheduledPropRegExp,
shortScheduledPropRegExp,
} from "../regexp";
import type { Task } from "../types";
import type { Task, UnscheduledTask } from "../types";
import { PlacedTask } from "../types";

import { getId } from "./id";
Expand Down Expand Up @@ -131,3 +131,18 @@ export function createTask(day: Moment, startMinutes: number): PlacedTask {
},
};
}

export function getSchedueldDayFromText(task: UnscheduledTask) {
const matches =
scheduledPropRegExp.exec(task.text) ||
keylessScheduledPropRegExp.exec(task.text) ||
shortScheduledPropRegExp.exec(task.text);

if (!matches) {
return undefined;
}
const [fullMatch, preFix] = matches;
const scheduledDay = fullMatch.replace(preFix, "");

return window.moment(scheduledDay);
}

0 comments on commit b8c1ce5

Please sign in to comment.