release v1.8.0: reuse open tabs for periodic notes

This commit is contained in:
olivier committed 2026-10-08 16:36:47 -04:00
1 parent 695141383f
commit 984a0ab44f
10 files changed
+75 -32

No files matched your search

+20 -5
View File
@@ -738,13 +738,14 @@ export default class WaypointPlugin extends Plugin {
* Open (creating if needed) the note `system` holds for `date`.
*
* `opts.title` fills the `{title}` token of a many-per-date system and is
* ignored by systems without one. Opens in `opts.leaf` when given,
* otherwise in the active leaf.
* ignored by systems without one. An explicit `opts.leaf` takes precedence;
* otherwise `opts.reuseExistingLeaf` reveals an open Markdown tab for the
* exact file path, falling back to the active leaf when none is open.
*/
async openDateSystemNote(
system: DateSystemSettings,
date: moment.Moment,
opts?: { title?: string; leaf?: WorkspaceLeaf },
opts?: { title?: string; leaf?: WorkspaceLeaf; reuseExistingLeaf?: boolean },
): Promise<void> {
if (!formatHasDateToken(system.nameFormat)) {
@@ -777,16 +778,30 @@ export default class WaypointPlugin extends Plugin {
if (!file) return;
}
if (opts?.reuseExistingLeaf && !opts.leaf) {
// View state also identifies deferred tabs whose view is not loaded yet.
const existing = this.app.workspace.getLeavesOfType('markdown')
.find(leaf => leaf.getViewState().state?.file === file.path);
if (existing) {
await this.app.workspace.revealLeaf(existing);
this.app.workspace.setActiveLeaf(existing, { focus: true });
return;
}
}
const target = opts?.leaf || this.app.workspace.getLeaf(false);
await target.openFile(file);
}
/**
* Open (creating if needed) the period note for `date`.
* Opens in `leaf` when given, otherwise in the active leaf.
* An explicit `leaf` wins; otherwise reuse an open tab when enabled.
*/
async openPeriodNote(period: PeriodKey, date: moment.Moment, leaf?: WorkspaceLeaf): Promise<void> {
await this.openDateSystemNote(this.periodAsDateSystem(period), date, { leaf });
await this.openDateSystemNote(this.periodAsDateSystem(period), date, {
leaf,
reuseExistingLeaf: this.settings.reusePeriodicNoteTabs,
});
}
/**