view src/settings.ts @ 6:114d7e6d2633

Fix various issues around keeping references to editor objects - Don't keep references to view. Instead, generate unique view IDs and use that to find the correct uninstaller when needed. - Don't keep a reference to the plugin itself in registered callbacks on views because that could keep the plugin alive after it has been unloaded.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 14 Feb 2022 12:35:45 -0800
parents 7975d7c73f8a
children 815b93d13e0f
line wrap: on
line source

import {
	PluginSettingTab,
	Setting
} from 'obsidian';

import {
	RememberFileStatePlugin
} from './main'

export interface RememberFileStatePluginSettings {
	rememberMaxFiles: number;
}

export const DEFAULT_SETTINGS: RememberFileStatePluginSettings = {
	// Matches the number of files Obsidian remembers the undo/redo 
	// history for by default (at least as of 0.13.17).
	rememberMaxFiles: 20 
}

export class RememberFileStatePluginSettingTab extends PluginSettingTab {
	plugin: RememberFileStatePlugin;

	constructor(app: App, plugin: RememberFileStatePlugin) {
		super(app, plugin);
		this.plugin = plugin;
	}

	display(): void {
		const {containerEl} = this;

		containerEl.empty();

		new Setting(containerEl)
			.setName('Remember files')
			.setDesc('How many files to remember at most')
			.addText(text => text
				.setValue(this.plugin.settings.rememberMaxFiles?.toString()))
				.onChange(async (value) => {
					const intValue = parseInt(value);
					if (!isNaN(intValue)) {
						this.plugin.settings.rememberMaxFiles = intValue;
						await this.plugin.saveSettings();
					}
				});
	}
}