fix: native template autocomplete and durable indicator migration
Template file fields used an unstyled <datalist>, not Obsidian's native suggest popup. Replace it with TemplateFileSuggest, an AbstractInputSuggest<TFile> matching Templater's own FileSuggest/FolderSuggest pattern exactly. Requires Obsidian >=1.4.10; minAppVersion corrected. The coloured-indicator default never reached existing installs: every install that loaded before that default changed had already persisted the prior default (indicatorMode: 'any') to data.json as if it were a deliberate choice, and Object.assign-based settings merging always prefers a value already on disk over a new code default. Hand-editing data.json directly does not fix this durably either -- Obsidian holds settings in memory while a vault is open and overwrites external edits on its own save cycle. Add a one-time, code-level migration: on load, an install with a persisted indicatorMode of 'any' and no indicatorModeMigrated flag is promoted to 'systems' and the flag is persisted immediately, so it survives even a session with no further settings changes. Any indicatorMode chosen after the flag exists, any (deliberately) included, is never touched again.
This commit is contained in:
1 parent
e8ba4cd2ad
commit
621bef0d29
5 files changed
+94
-59
No files matched your search
+34
-3
@@ -61,14 +61,26 @@ export default class WaypointPlugin extends Plugin {
|
||||
/** Results for the displayed month; invalidated by markdown-file changes. */
|
||||
private dateSystemIndicators: Map<string, DateSystemIndicator[]> | null = null;
|
||||
private dateSystemIndicatorKey = '';
|
||||
/**
|
||||
* True once `data.json` carries the post-migration schema. Set on every
|
||||
* load and included in every save, so a single migration run is durable
|
||||
* even if this session never triggers another settings write.
|
||||
*/
|
||||
private indicatorModeMigrated = false;
|
||||
|
||||
async onload(): Promise<void> {
|
||||
console.debug('Waypoint: loading plugin v' + this.manifest.version);
|
||||
|
||||
// Load persisted data — data.json is read exactly once here.
|
||||
const saved = await this.loadData() as Record<string, unknown> | null;
|
||||
this.applySettings(saved);
|
||||
const migrated = this.applySettings(saved);
|
||||
this.applyWaypointData(saved);
|
||||
if (migrated) {
|
||||
// Persist immediately: an install that only ever reads data.json
|
||||
// (never changes a setting or bookmark this session) must still
|
||||
// keep the migrated value instead of re-migrating every load.
|
||||
void this.persistAll();
|
||||
}
|
||||
|
||||
// Register the sidebar view
|
||||
this.registerView(
|
||||
@@ -245,9 +257,11 @@ export default class WaypointPlugin extends Plugin {
|
||||
/**
|
||||
* Merge persisted settings over the defaults. Nested objects are merged
|
||||
* individually so existing configs keep their values while picking up
|
||||
* fields added in newer versions.
|
||||
* fields added in newer versions. Returns true the one time a one-off
|
||||
* migration (see `indicatorModeMigrated` below) actually changes a value,
|
||||
* so the caller can persist that change immediately.
|
||||
*/
|
||||
private applySettings(saved: Record<string, unknown> | null): void {
|
||||
private applySettings(saved: Record<string, unknown> | null): boolean {
|
||||
const s = (saved?.settings || {}) as Partial<WaypointSettings>;
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, s);
|
||||
this.settings.recentFiles = Object.assign({}, DEFAULT_SETTINGS.recentFiles, s.recentFiles || {});
|
||||
@@ -267,6 +281,22 @@ export default class WaypointPlugin extends Plugin {
|
||||
return Object.assign({}, builtIn || DEFAULT_DATE_SYSTEM, sys);
|
||||
})
|
||||
: DEFAULT_SETTINGS.dateSystems.map(sys => Object.assign({}, sys));
|
||||
|
||||
// `indicatorMode` shipped with a default of 'any' before per-system
|
||||
// colours existed, so every install that loaded before that default
|
||||
// changed silently persisted 'any' to disk as if it were a deliberate
|
||||
// choice — changing DEFAULT_SETTINGS alone can never reach an install
|
||||
// that already has an explicit value on disk. Promote that one-time
|
||||
// default to the current default exactly once; any choice made after
|
||||
// this flag is set is real and must never be touched again.
|
||||
const alreadyMigrated = saved?.indicatorModeMigrated === true;
|
||||
let didMigrateValue = false;
|
||||
if (!alreadyMigrated && s.calendar?.indicatorMode === 'any') {
|
||||
this.settings.calendar.indicatorMode = 'systems';
|
||||
didMigrateValue = true;
|
||||
}
|
||||
this.indicatorModeMigrated = true;
|
||||
return didMigrateValue;
|
||||
}
|
||||
|
||||
private applyWaypointData(saved: Record<string, unknown> | null): void {
|
||||
@@ -301,6 +331,7 @@ export default class WaypointPlugin extends Plugin {
|
||||
return this.saveData({
|
||||
settings: this.settings,
|
||||
waypointData: this.waypointData,
|
||||
indicatorModeMigrated: this.indicatorModeMigrated,
|
||||
});
|
||||
});
|
||||
// Keep the queue usable after a failed write without leaving an
|
||||
|
||||
Reference in new issue
Block a user