Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/features/recurring-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Good uses include:
- A maintenance task where each visit needs photos, links, or a checklist
- A recurring meeting where every occurrence should have its own time entries and completion state

To create one manually, right-click a recurring task card or calendar occurrence and choose **Open or create occurrence note**. The Task Action Palette also exposes **Open or create occurrence note** for recurring tasks. If a matching note already exists for the same parent and date, TaskNotes opens it instead of creating a duplicate.
To create one manually, right-click a recurring task card or calendar occurrence and choose **Open or create occurrence note**. Dragging a pattern instance to another day in the calendar also creates its occurrence note. The Task Action Palette also exposes **Open or create occurrence note** for recurring tasks. If a matching note already exists for the same parent and date, TaskNotes opens it instead of creating a duplicate.

An occurrence note is an ordinary TaskNotes task. It appears in views, can be edited like any other task, and shows an occurrence pill that links back to the recurring parent. On the calendar, a materialized occurrence replaces the matching virtual parent occurrence for the same parent/date pair, so you do not see both the generated instance and the note-backed instance at the same time.

Expand Down Expand Up @@ -147,7 +147,7 @@ Leaving the global template empty preserves the existing filename behavior. Task

Right-click a recurring parent and open **Occurrence notes** to choose its policy:

- **Create manually**: occurrence notes are only created by explicit action.
- **Create manually**: occurrence notes are only created by explicit action, such as the menu command or dragging a pattern instance to another day.
- **Create next after completion**: after you complete a materialized occurrence note, TaskNotes creates the next occurrence note.
- **Rolling window**: defined by the TaskNotes spec, but not automated in the plugin yet.

Expand Down Expand Up @@ -213,12 +213,12 @@ TaskNotes captures this identity when rescheduling through its controls or task

## Calendar Drag and Drop

Calendar interactions follow the same model distinction: drag the concrete next item to reschedule execution, or drag a pattern instance to redefine the recurrence anchor.
Calendar interactions follow the same model distinction: drag the concrete next item to reschedule execution, or drag a pattern instance to change the series' time or move that one instance.

Recurring tasks can show:

- **Next occurrence** (solid border): dragging updates only `scheduled`
- **Pattern instances** (dashed border): dragging updates `DTSTART` and future pattern instances
- **Pattern instances** (dashed border): dragging to another time on the same day updates the time in `DTSTART`, which moves every later pattern instance. Dragging to another day, or between the all-day row and a time slot, creates an occurrence note for that instance at the drop position and leaves the rule unchanged. See [Calendar Views](../views/calendar-views.md#drag-and-drop-behavior).
- **Materialized occurrence notes**: dragging updates the occurrence note's own `scheduled` or `due` date like a normal task, without changing the parent's recurrence rule

In list mode and the Agenda, the card for a pattern instance shows that instance's scheduled date as read-only text and leaves out the task's due date. To give one instance its own dates, create an occurrence note for it.
Expand Down
2 changes: 2 additions & 0 deletions docs/releases/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ When a change has user-facing documentation, include a canonical tasknotes.dev l
- Thanks to @RumiaKitinari for reporting
- (#2613) Fixed status and priority icons not lining up with the task title. In a wide Task List the priority icon sat slightly higher than the title, and when a title wrapped onto several lines with nothing below it, both icons sat between its lines. They now line up with the first line of the title in Task List, Kanban, Agenda and Pomodoro views.
- Thanks to @wivi-prod for reporting
- (#2631) Fixed dragging a later occurrence of a recurring task (dashed border) to another day in the calendar. The drop kept the occurrence on its original day, sometimes changed the time or removed the time from the recurrence rule for every later occurrence, and showed a notice saying the occurrence had moved. A drop on another day, or between the all-day row and a time slot, now moves only that occurrence by creating its occurrence note, and leaves the recurrence rule unchanged. A drop at another time on the same day still changes the series' time, and the notice now says so. A drop at the same day and time changes nothing. See [Calendar Views](https://tasknotes.dev/views/calendar-views/#drag-and-drop-behavior).
- Thanks to @martin-forge for reporting
11 changes: 7 additions & 4 deletions docs/views/calendar-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ The calendar provides different behaviors depending on which type of recurring e

**Dragging Pattern Instances (Dashed Border)**:

- Updates the DTSTART time in the recurrence rule
- Changes when all future pattern instances appear
- Does not affect the independently scheduled next occurrence
- Notice: "Updated recurring pattern time. All future instances now appear at this time."
What a drop changes depends on where the instance lands:

- **Same day, another time**: updates the time in the recurrence rule's `DTSTART`, so every later pattern instance appears at the new time. The independently scheduled next occurrence keeps its own time. Notice: "Series time changed to 14:00. Later occurrences now appear at this time; the next occurrence keeps its own time."
- **Another day, or between the all-day row and a time slot**: moves only that instance. TaskNotes creates an [occurrence note](../features/recurring-tasks.md#materialized-occurrence-notes) for the instance's date, scheduled where you dropped it, and leaves the recurrence rule unchanged. Notice: "Moved the Nov 29, 2026 occurrence to Nov 30, 2026 09:00. Other occurrences are unchanged." Undo deletes the new occurrence note.
- **Same day and time**: nothing changes.

Resizing a pattern instance changes the task's time estimate, which every instance uses.

#### Flexible Scheduling

Expand Down
192 changes: 192 additions & 0 deletions e2e/issues/issue-2631-projected-occurrence-drop.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { test, expect, type Page } from '@playwright/test';
import { launchObsidian, closeObsidian, type ObsidianApp } from '../obsidian';

// #2631: dragging a projected (dashed) occurrence of a recurring task to another
// day showed "<title> · <new day>" but left it on its original day, and could
// rewrite the series' DTSTART. A cross-day drop now creates that occurrence's
// note at the drop position; a same-day time change still edits the series.
let instance: ObsidianApp;
const stamp = Date.now();
const prefix = `Issue 2631 ${stamp}`;
const folder = `e2e-2631-${stamp}`;
const basePath = `${folder}/Week.base`;
const created: string[] = [basePath];
// Next occurrence Sunday 10 Jan 2027; the dragged projection is Sunday 17 Jan.
const SUNDAY = '2027-01-17';
const MONDAY = '2027-01-18';

const taskPath = (name: string) => `${folder}/${prefix} ${name}.md`;

async function createTask(page: Page, name: string, hour: string) {
const path = taskPath(name);
created.push(path);
await page.evaluate(async ({ path, title, hour }) => {
await (window as any).app.vault.create(path, `---
title: ${title}
status: open
priority: normal
tags: [task]
scheduled: 2027-01-10T${hour}:00
recurrence: DTSTART:20270103T${hour}0000Z;FREQ=WEEKLY;BYDAY=SU
---
`);
}, { path, title: `${prefix} ${name}`, hour });
await expect.poll(() => page.evaluate(async path =>
Boolean(await (window as any).app.plugins.plugins.tasknotes.cacheManager.getTaskInfo(path)), path)).toBe(true);
return path;
}

/** Calendar items for a task path: [start, recurringKind]. */
async function items(page: Page, path: string): Promise<string[]> {
return page.evaluate(({ path, basePath }) => {
const app = (window as any).app;
const view = app.workspace.getLeavesOfType('bases')
.find((leaf: any) => leaf.view.file?.path === basePath)?.view.controller.view;
if (!view?.calendar) return [];
return Array.from(view.calendar.store.all())
.map((entry: any) => entry.item)
.filter((item: any) => item.data?.taskInfo?.path === path ||
String(item.data?.taskInfo?.recurrence_parent ?? '').includes(path.replace(/\.md$/, '')))
.map((item: any) => `${String(item.start).slice(0, 16)} ${item.data?.modelEntry?.recurringKind ?? 'note'}`)
.sort();
}, { path, basePath });
}

async function frontmatter(page: Page, path: string) {
return page.evaluate(path => {
const app = (window as any).app;
return app.metadataCache.getFileCache(app.vault.getAbstractFileByPath(path))?.frontmatter;
}, path);
}

/** Occurrence notes of a parent; they live in the tasks folder, not next to it. */
async function occurrenceNotes(page: Page, parentPath: string) {
const notes = await page.evaluate(async parent => {
const plugin = (window as any).app.plugins.plugins.tasknotes;
return (await plugin.cacheManager.getAllTasks())
.filter((task: any) => task.occurrence_date && String(task.recurrence_parent ?? '').includes(parent))
.map((task: any) => ({ path: task.path, scheduled: task.scheduled, occurrence_date: task.occurrence_date }));
}, parentPath.replace(/\.md$/, ''));
for (const note of notes) if (!created.includes(note.path)) created.push(note.path);
return notes;
}

/** Drags the projected Sunday item of `name` with a real pointer. */
async function drag(page: Page, name: string, target: { day: string; hour?: number; allDay?: boolean }) {
const title = `${prefix} ${name}`;
const event = page.locator('.tnc-item').filter({ hasText: title })
.and(page.locator(`[data-id^="recurring-"][data-id$="-${SUNDAY}"]`));
// The calendar re-renders after each edit, so take the item's box once it settles.
let box: { x: number; y: number; width: number; height: number } | null = null;
await expect.poll(async () => {
box = await event.boundingBox({ timeout: 1000 }).catch(() => null);
return Boolean(box);
}).toBe(true);
if (!box) throw new Error(`No projected item for ${title}`);
const geometry = await page.evaluate(({ from, to }) => {
const column = (date: string) => Array.from(document.querySelectorAll(`.tnc-tg-cols [data-date="${date}"]`))
.map(el => el.getBoundingClientRect()).find(rect => rect.height > 100);
const fromCol = column(from)!;
const toCol = column(to)!;
// The all-day row is one layer across the week; the column picks the day.
const allDay = document.querySelector('.tnc-tg-allday .tnc-allday-layer')!.getBoundingClientRect();
return { fromX: fromCol.x, toX: toCol.x, hour: fromCol.height / 24, top: fromCol.y, allDay };
}, { from: SUNDAY, to: target.day });
const startX = box.x + box.width / 2;
const startY = box.y + 6;
const endX = startX + (geometry.toX - geometry.fromX);
const endY = target.allDay
? geometry.allDay.y + geometry.allDay.height / 2
: target.hour === undefined ? startY : startY + (target.hour - Number(name === 'filter' ? 11 : 9)) * geometry.hour;
await page.mouse.move(startX, startY);
await page.mouse.down();
await page.mouse.move(startX + 4, startY + 4, { steps: 3 });
await page.mouse.move(endX, endY, { steps: 15 });
await page.mouse.up();
}

test.beforeAll(async () => {
instance = await launchObsidian();
const page = instance.page;
await page.evaluate(async ({ folder, prefix, basePath }) => {
const app = (window as any).app;
app.plugins.plugins.tasknotes.settings.googleCalendarExport.enabled = false;
await app.vault.createFolder(folder);
await app.vault.create(basePath, `filters:
and:
- file.name.startsWith("${prefix}")
views:
- type: tasknotesCalendar
name: Week
calendarView: timeGridWeek
firstDay: 0
showScheduled: true
showDue: true
showRecurring: true
showTimeEntries: false
showTimeblocks: false
showPropertyBasedEvents: false
`);
}, { folder, prefix, basePath });
});

test.afterAll(async () => {
if (!instance) return;
try {
await instance.page.evaluate(async paths => {
const app = (window as any).app;
for (const path of paths) {
const file = app.vault.getAbstractFileByPath(path);
if (file) await app.vault.delete(file, true);
}
}, [...created, folder]);
} finally { await closeObsidian(instance); }
});

test('dropping a projected occurrence on another day moves only that occurrence', async () => {
const page = instance.page;
const water = await createTask(page, 'water', '09');
const filter = await createTask(page, 'filter', '11');
const post = await createTask(page, 'post', '09');
await page.evaluate(async basePath => {
const app = (window as any).app;
await app.workspace.getLeaf(false).openFile(app.vault.getAbstractFileByPath(basePath));
}, basePath);
await expect.poll(() => page.evaluate(basePath => Boolean((window as any).app.workspace.getLeavesOfType('bases')
.find((leaf: any) => leaf.view.file?.path === basePath)?.view.controller.view?.calendar), basePath)).toBe(true);
await page.evaluate(({ basePath, day }) => (window as any).app.workspace.getLeavesOfType('bases')
.find((leaf: any) => leaf.view.file?.path === basePath).view.controller.view.calendar.gotoDate(day),
{ basePath, day: SUNDAY });
await expect.poll(() => items(page, water)).toEqual([`${SUNDAY}T09:00 pattern`]);

// Another day, same time: an occurrence note on Monday; the rule is untouched.
await drag(page, 'water', { day: MONDAY });
await expect.poll(() => occurrenceNotes(page, water)).toEqual([
expect.objectContaining({ occurrence_date: SUNDAY, scheduled: `${MONDAY}T09:00` }),
]);
await expect.poll(async () => (await frontmatter(page, water))?.recurrence).toBe('DTSTART:20270103T090000Z;FREQ=WEEKLY;BYDAY=SU');
await expect.poll(() => items(page, water)).toEqual([`${MONDAY}T09:00 note`]);
const moved = page.locator('.tn-toast').filter({ hasText: `${prefix} water` });
await expect(moved).toContainText('occurrence to');
await expect(moved).toContainText('Other occurrences are unchanged.');
// Undo removes the occurrence note, so the projection is back on Sunday.
await moved.getByRole('button', { name: 'Undo', exact: true }).click();
await expect.poll(() => occurrenceNotes(page, water)).toEqual([]);
await expect.poll(() => items(page, water)).toEqual([`${SUNDAY}T09:00 pattern`]);

// Same day, another time: the series' time changes, and the notice says so.
await drag(page, 'filter', { day: SUNDAY, hour: 14 });
await expect.poll(async () => (await frontmatter(page, filter))?.recurrence)
.toBe('DTSTART:20270103T140000Z;FREQ=WEEKLY;BYDAY=SU');
await expect.poll(async () => (await frontmatter(page, filter))?.scheduled).toBe('2027-01-10T11:00');
expect(await occurrenceNotes(page, filter)).toEqual([]);
await expect(page.locator('.tn-toast').filter({ hasText: `${prefix} filter` }))
.toContainText('Series time changed to 14:00');

// Another day's all-day row: a date-only occurrence note; the rule keeps its time.
await drag(page, 'post', { day: MONDAY, allDay: true });
await expect.poll(() => occurrenceNotes(page, post)).toEqual([
expect.objectContaining({ occurrence_date: SUNDAY, scheduled: MONDAY }),
]);
await expect.poll(async () => (await frontmatter(page, post))?.recurrence).toBe('DTSTART:20270103T090000Z;FREQ=WEEKLY;BYDAY=SU');
});
55 changes: 53 additions & 2 deletions src/bases/calendarMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import type { TaskInfo } from "../types";
import type { CalendarEventChange } from "./calendarEngine";
import { format } from "date-fns";
import { formatUIDate } from "../i18n/formatters";
import { formatTime } from "../utils/dateUtils";
import { formatTime, parseDateToLocal } from "../utils/dateUtils";
import { msg } from "@lingui/core/macro";
import { uiText } from "../i18n/runtime";
import { planCalendarPatternGesture } from "./calendarPatternGesture";
import { TFile } from "obsidian";
import {
handleTimeblockDrop,
Expand Down Expand Up @@ -276,6 +279,46 @@ async function applyTaskCalendarGesture(
const start = info.event.start.toISOString();
const current = await context.plugin.cacheManager.getTaskInfo(taskInfo.path);
if (!current) throw new Error(`Missing task: ${taskInfo.path}`);
const change = { kind, start, end: info.event.end?.toISOString(), allDay: info.event.allDay };
const timeFormat = (context.options.timeFormat ?? context.plugin.settings.calendarViewSettings?.timeFormat) === "12" ? "12" : "24";
const when = (value: string) => {
const date = parseDateToLocal(value);
return `${formatUIDate(date, "PP")}${value.includes("T") ? ` ${formatTime(date, timeFormat)}` : ""}`;
};
// A projected occurrence follows the series' rule, so the drop position is not
// what changes: either this occurrence becomes a note, or the series time moves.
const pattern = planCalendarPatternGesture(current, modelEntry, change, context.timezone);
if (pattern?.kind === "unchanged") {
info.revert();
return;
}
if (pattern?.kind === "occurrence") {
info.revert();
const occurrence = await context.plugin.taskService.materializeOccurrence(
current,
pattern.occurrenceDate,
pattern.overrides
);
await context.refreshTask(current);
const moved = uiText(
msg({
message: "Moved the {from} occurrence to {to}. Other occurrences are unchanged.",
context: "calendar recurring occurrence drop feedback",
}),
{
from: formatUIDate(parseDateToLocal(pattern.occurrenceDate), "PP"),
to: when(occurrence.scheduled ?? pattern.overrides.scheduled ?? pattern.occurrenceDate),
}
);
showTaskUndo(
[() => context.plugin.taskService.deleteTask(occurrence)],
false,
1,
context.plugin.app.vault,
`${current.title} · ${moved}`
);
return;
}
const result = await captureTaskUndo(context.plugin, current, () => context.plugin.taskService.applyCalendarEdit(
current,
modelEntry,
Expand All @@ -291,7 +334,15 @@ async function applyTaskCalendarGesture(
await context.refreshTask(result.task);
const feedback = kind === "resize" && info.event.end
? calendarResizeFeedback(result.task.title, info.event.start, info.event.end)
: `${result.task.title} · ${formatUIDate(info.event.start, "PP")}${info.event.allDay ? "" : ` ${formatTime(info.event.start, (context.options.timeFormat ?? context.plugin.settings.calendarViewSettings?.timeFormat) === "12" ? "12" : "24")}`}`;
: pattern?.kind === "series-time"
? `${result.task.title} · ${uiText(
msg({
message: "Series time changed to {time}. Later occurrences now appear at this time; the next occurrence keeps its own time.",
context: "calendar recurring pattern drop feedback",
}),
{ time: formatTime(info.event.start, timeFormat) }
)}`
: `${result.task.title} · ${formatUIDate(info.event.start, "PP")}${info.event.allDay ? "" : ` ${formatTime(info.event.start, timeFormat)}`}`;
showTaskUndo(result.undo ? [result.undo] : [], false, 1, context.plugin.app.vault, feedback);
}
else info.revert();
Expand Down
Loading
Loading