release v1.9.0: date picker and open-date command, recent files opened/changed with background dot and type icons, mobile layout
This commit is contained in:
1 parent
984a0ab44f
commit
ff15470a06
14 files changed
+626
-175
No files matched your search
+100
-27
@@ -13,8 +13,10 @@ import {
|
||||
import { WaypointSettings, DEFAULT_SETTINGS, DateSystemSettings, DEFAULT_DATE_SYSTEM } from 'src/settings';
|
||||
import { WaypointSettingTab } from 'src/settings-tab';
|
||||
import { WaypointView, WAYPOINT_VIEW_TYPE } from 'src/views/waypoint-view';
|
||||
import { BookmarkItem, WaypointData } from 'src/models/bookmark';
|
||||
import { BookmarkItem, RecentFileEntry, WaypointData } from 'src/models/bookmark';
|
||||
import { DatePickerModal } from 'src/modals/date-picker-modal';
|
||||
import { remapRenamedPath } from 'src/utils/path-utils';
|
||||
import { recentFilesFor, trimRecentFiles } from 'src/utils/recent-files';
|
||||
import {
|
||||
splitNameFormat,
|
||||
isInFolder,
|
||||
@@ -52,7 +54,7 @@ export interface DateSystemIndicator {
|
||||
export default class WaypointPlugin extends Plugin {
|
||||
public settings: WaypointSettings;
|
||||
public waypointData: WaypointData;
|
||||
public recentFiles: { path: string; basename: string }[] = [];
|
||||
public recentFiles: RecentFileEntry[] = [];
|
||||
private recentFilesSaveTimer: number | undefined;
|
||||
/** Serializes writes to data.json so overlapping saves cannot lose updates. */
|
||||
private savePromise: Promise<void> = Promise.resolve();
|
||||
@@ -67,6 +69,13 @@ export default class WaypointPlugin extends Plugin {
|
||||
* even if this session never triggers another settings write.
|
||||
*/
|
||||
private indicatorModeMigrated = false;
|
||||
/**
|
||||
* The file that was active just before the current one. Its editor may
|
||||
* still flush a pending save after the switch, which is the user's own
|
||||
* edit and must not be flagged as a background change.
|
||||
*/
|
||||
private previouslyActive: { path: string; until: number } | null = null;
|
||||
private activePath: string | null = null;
|
||||
|
||||
async onload(): Promise<void> {
|
||||
console.debug('Waypoint: loading plugin v' + this.manifest.version);
|
||||
@@ -178,6 +187,17 @@ export default class WaypointPlugin extends Plugin {
|
||||
},
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: 'waypoint-open-date',
|
||||
name: 'Open daily note for a date…',
|
||||
callback: () => {
|
||||
new DatePickerModal(this.app, moment(), (date) => {
|
||||
this.showDateInViews(date);
|
||||
void this.openPeriodNote('day', date);
|
||||
}).open();
|
||||
},
|
||||
});
|
||||
|
||||
// ── Period navigation commands (no hotkeys) ──
|
||||
|
||||
const directions = ['next', 'prev'] as const;
|
||||
@@ -216,7 +236,7 @@ export default class WaypointPlugin extends Plugin {
|
||||
this.app.vault.on('rename', (file, oldPath) => this.onRename(file, oldPath)),
|
||||
);
|
||||
this.registerEvent(
|
||||
this.app.vault.on('modify', (file: TAbstractFile) => this.onFileModify(file)),
|
||||
this.app.vault.on('modify', (file: TAbstractFile) => this.onFileChange(file)),
|
||||
);
|
||||
|
||||
// Auto-open view on first load
|
||||
@@ -265,6 +285,14 @@ export default class WaypointPlugin extends Plugin {
|
||||
const s = (saved?.settings || {}) as Partial<WaypointSettings>;
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, s);
|
||||
this.settings.recentFiles = Object.assign({}, DEFAULT_SETTINGS.recentFiles, s.recentFiles || {});
|
||||
// `filterTags` (pill names only) became `types` (name + icon), and the
|
||||
// single `updateOn` mode became the header filter `show`.
|
||||
const legacyRecent = this.settings.recentFiles as Partial<{ filterTags: string[]; updateOn: string }>;
|
||||
this.settings.recentFiles.types = Array.isArray(s.recentFiles?.types)
|
||||
? s.recentFiles.types.map(t => ({ ...t }))
|
||||
: (legacyRecent.filterTags ?? []).map(type => ({ type, icon: '' }));
|
||||
delete legacyRecent.filterTags;
|
||||
delete legacyRecent.updateOn;
|
||||
this.settings.calendar = Object.assign({}, DEFAULT_SETTINGS.calendar, s.calendar || {});
|
||||
this.settings.display = Object.assign({}, DEFAULT_SETTINGS.display, s.display || {});
|
||||
for (const key of PERIOD_SETTING_KEYS) {
|
||||
@@ -306,14 +334,20 @@ export default class WaypointPlugin extends Plugin {
|
||||
recentFiles: Array.isArray(d.recentFiles) ? d.recentFiles : [],
|
||||
};
|
||||
|
||||
// Load persisted recent files
|
||||
this.recentFiles = this.waypointData.recentFiles;
|
||||
|
||||
// Apply current limit (in case maxItems was reduced since last save)
|
||||
if (this.recentFiles.length > this.settings.recentFiles.maxItems) {
|
||||
this.recentFiles = this.recentFiles.slice(0, this.settings.recentFiles.maxItems);
|
||||
this.waypointData.recentFiles = this.recentFiles;
|
||||
}
|
||||
// Entries saved before per-kind timestamps carry only their order and
|
||||
// the old single tracking mode. Small descending stamps keep that order
|
||||
// and sort them after anything recorded from now on.
|
||||
const legacy = (saved?.settings as { recentFiles?: { updateOn?: string } } | undefined)?.recentFiles?.updateOn;
|
||||
const legacyKind = legacy === 'file-edit' ? 'changedAt' : 'openedAt';
|
||||
const count = this.waypointData.recentFiles.length;
|
||||
this.recentFiles = trimRecentFiles(
|
||||
this.waypointData.recentFiles.map((entry, i) =>
|
||||
entry.openedAt === undefined && entry.changedAt === undefined
|
||||
? { ...entry, [legacyKind]: count - i }
|
||||
: entry),
|
||||
this.settings.recentFiles.maxItems,
|
||||
);
|
||||
this.waypointData.recentFiles = this.recentFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,8 +387,9 @@ export default class WaypointPlugin extends Plugin {
|
||||
* Called when the maxItems setting changes.
|
||||
*/
|
||||
enforceRecentFilesLimit(): void {
|
||||
if (this.recentFiles.length > this.settings.recentFiles.maxItems) {
|
||||
this.recentFiles = this.recentFiles.slice(0, this.settings.recentFiles.maxItems);
|
||||
const trimmed = trimRecentFiles(this.recentFiles, this.settings.recentFiles.maxItems);
|
||||
if (trimmed.length !== this.recentFiles.length) {
|
||||
this.recentFiles = trimmed;
|
||||
this.persistRecentFiles();
|
||||
}
|
||||
}
|
||||
@@ -373,31 +408,55 @@ export default class WaypointPlugin extends Plugin {
|
||||
// ── Recent Files ──
|
||||
|
||||
private onFileOpen(file: TFile): void {
|
||||
if (this.settings.recentFiles.updateOn !== 'file-open') return;
|
||||
this.addToRecentFiles(file);
|
||||
if (this.activePath && this.activePath !== file.path) {
|
||||
this.previouslyActive = { path: this.activePath, until: Date.now() + PENDING_SAVE_GRACE_MS };
|
||||
}
|
||||
this.activePath = file.path;
|
||||
this.recordRecentFile(file, 'opened');
|
||||
}
|
||||
|
||||
private onFileModify(file: TAbstractFile): void {
|
||||
if (this.settings.recentFiles.updateOn !== 'file-edit') return;
|
||||
/** Vault `modify`, and `create` once the layout is ready (sync, other plugins). */
|
||||
private onFileChange(file: TAbstractFile): void {
|
||||
if (!(file instanceof TFile)) return;
|
||||
// Already the most recent entry: nothing to reorder or redraw.
|
||||
if (this.recentFiles.length > 0 && this.recentFiles[0].path === file.path) return;
|
||||
this.addToRecentFiles(file);
|
||||
this.recordRecentFile(file, 'changed', this.isBackgroundChange(file));
|
||||
}
|
||||
|
||||
addToRecentFiles(file: TFile): void {
|
||||
/** A change the user did not make in the editor: the file is neither active nor just left. */
|
||||
private isBackgroundChange(file: TFile): boolean {
|
||||
if (this.app.workspace.getActiveFile()?.path === file.path) return false;
|
||||
const prev = this.previouslyActive;
|
||||
return !(prev && prev.path === file.path && Date.now() < prev.until);
|
||||
}
|
||||
|
||||
/** Stamp `file` as just opened or just changed. Opening clears the background dot. */
|
||||
private recordRecentFile(file: TFile, kind: 'opened' | 'changed', background = false): void {
|
||||
if (this.isOmittedFromRecentFiles(file)) return;
|
||||
|
||||
this.recentFiles = this.recentFiles.filter(f => f.path !== file.path);
|
||||
this.recentFiles.unshift({ path: file.path, basename: file.basename });
|
||||
let entry = this.recentFiles.find(f => f.path === file.path);
|
||||
// The editor saves every couple of seconds while you type. When this
|
||||
// file already leads both orderings and the dot is unchanged, only the
|
||||
// timestamp moves, so the sidebar does not need a rebuild.
|
||||
const quiet = kind === 'changed'
|
||||
&& entry !== undefined
|
||||
&& this.recentFiles[0] === entry
|
||||
&& recentFilesFor(this.recentFiles, 'changed')[0] === entry
|
||||
&& !(background && !entry.changedInBackground);
|
||||
|
||||
// Apply max items limit
|
||||
if (this.recentFiles.length > this.settings.recentFiles.maxItems) {
|
||||
this.recentFiles = this.recentFiles.slice(0, this.settings.recentFiles.maxItems);
|
||||
if (!entry) {
|
||||
entry = { path: file.path, basename: file.basename };
|
||||
this.recentFiles.push(entry);
|
||||
}
|
||||
if (kind === 'opened') {
|
||||
entry.openedAt = Date.now();
|
||||
delete entry.changedInBackground;
|
||||
} else {
|
||||
entry.changedAt = Date.now();
|
||||
if (background) entry.changedInBackground = true;
|
||||
}
|
||||
|
||||
this.recentFiles = trimRecentFiles(this.recentFiles, this.settings.recentFiles.maxItems);
|
||||
this.persistRecentFiles();
|
||||
this.broadcastRedraw();
|
||||
if (!quiet) this.broadcastRedraw();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -476,6 +535,8 @@ export default class WaypointPlugin extends Plugin {
|
||||
this.markdownBasenames.add(file.basename);
|
||||
this.invalidateDateSystemIndicators();
|
||||
}
|
||||
// The initial vault scan fires `create` for every file before layout-ready.
|
||||
if (this.app.workspace.layoutReady) this.onFileChange(file);
|
||||
this.broadcastRedraw();
|
||||
}
|
||||
|
||||
@@ -972,6 +1033,15 @@ export default class WaypointPlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Point every Waypoint calendar at `date`'s month and mark that day. */
|
||||
showDateInViews(date: moment.Moment): void {
|
||||
for (const leaf of this.app.workspace.getLeavesOfType(WAYPOINT_VIEW_TYPE)) {
|
||||
if (leaf.view instanceof WaypointView) {
|
||||
leaf.view.showDate(date);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Module helpers ──
|
||||
@@ -999,6 +1069,9 @@ function basenameFromPath(path: string): string {
|
||||
/** Notices that carry a diagnosis need longer on screen than the default. */
|
||||
const DIAGNOSTIC_NOTICE_MS = 10000;
|
||||
|
||||
/** How long after leaving a file its editor's last save still counts as the user's edit. */
|
||||
const PENDING_SAVE_GRACE_MS = 5000;
|
||||
|
||||
function describeError(err: unknown): string {
|
||||
return err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user