Mercurial > obsidian-remember-file-state
annotate 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 |
rev | line source |
---|---|
0 | 1 import { |
21
815b93d13e0f
Improve typescript compliance
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
2 App, |
0 | 3 PluginSettingTab, |
4 Setting | |
5 } from 'obsidian'; | |
6 | |
21
815b93d13e0f
Improve typescript compliance
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
7 import RememberFileStatePlugin from './main'; |
0 | 8 |
9 export interface RememberFileStatePluginSettings { | |
10 rememberMaxFiles: number; | |
11 } | |
12 | |
13 export const DEFAULT_SETTINGS: RememberFileStatePluginSettings = { | |
14 // Matches the number of files Obsidian remembers the undo/redo | |
15 // history for by default (at least as of 0.13.17). | |
16 rememberMaxFiles: 20 | |
17 } | |
18 | |
19 export class RememberFileStatePluginSettingTab extends PluginSettingTab { | |
20 plugin: RememberFileStatePlugin; | |
21 | |
22 constructor(app: App, plugin: RememberFileStatePlugin) { | |
23 super(app, plugin); | |
24 this.plugin = plugin; | |
25 } | |
26 | |
27 display(): void { | |
28 const {containerEl} = this; | |
29 | |
30 containerEl.empty(); | |
31 | |
32 new Setting(containerEl) | |
33 .setName('Remember files') | |
34 .setDesc('How many files to remember at most') | |
35 .addText(text => text | |
21
815b93d13e0f
Improve typescript compliance
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
36 .setValue(this.plugin.settings.rememberMaxFiles?.toString()) |
815b93d13e0f
Improve typescript compliance
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
37 .onChange(async (value: string) => { |
0 | 38 const intValue = parseInt(value); |
39 if (!isNaN(intValue)) { | |
40 this.plugin.settings.rememberMaxFiles = intValue; | |
41 await this.plugin.saveSettings(); | |
42 } | |
21
815b93d13e0f
Improve typescript compliance
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
43 })); |
0 | 44 } |
45 } |