view src/settings.ts @ 40:96e86650043b

Fix issues with files opened in multiple panes. The previous code was problematic since it opened files at the top for no obvious reason. Now we always restore any saved state if we have it, and if not we restore the current state from another pane if we find the same file is already open.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 20 Sep 2023 17:18:47 -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();
					}
				}));
	}
}