view src/settings.ts @ 28:fbaf7c7126be

Don't restore file state if we're just switching to another pane To do this we have to track the opened file path in the new editor view and check if it matches the last file path we knew for that view.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 14 Jul 2022 14:36:44 -0700
parents 815b93d13e0f
children 7e981d54a055
line wrap: on
line source

import {
	App,
	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: string) => {
					const intValue = parseInt(value);
					if (!isNaN(intValue)) {
						this.plugin.settings.rememberMaxFiles = intValue;
						await this.plugin.saveSettings();
					}
				}));
	}
}