-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.ts
74 lines (69 loc) · 1.95 KB
/
settings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import joplin from "api";
import { SettingItem, SettingItemType, SettingStorage } from "api/types";
import { PluginSettings } from "./types";
export const registerSettings = async (applySettings: (settings: PluginSettings)=>void) => {
const sectionName = 'codemirror6-extended-options';
await joplin.settings.registerSection(sectionName, {
label: 'Extra editor settings',
description: 'Additional settings for Joplin\'s beta and mobile markdown editors.',
iconName: 'fas fa-edit',
});
const defaultSettingOptions = {
section: sectionName,
public: true,
type: SettingItemType.Bool,
storage: SettingStorage.File,
};
const settingsSpec: Record<keyof PluginSettings, SettingItem> = {
lineNumbers: {
...defaultSettingOptions,
value: true,
label: 'Show line numbers',
},
codeFolding: {
...defaultSettingOptions,
value: false,
label: 'Enable code folding',
},
enableAutocomplete: {
...defaultSettingOptions,
value: false,
label: 'Enable autocomplete',
},
highlightActiveLineGutter: {
...defaultSettingOptions,
value: true,
label: 'Highlight the gutter for the active line',
description: 'Requires "show line numbers" to be enabled.',
},
highlightActiveLine: {
...defaultSettingOptions,
value: false,
label: 'Highlight active line',
},
highlightSpaces: {
...defaultSettingOptions,
value: false,
label: 'Highlight spaces',
},
highlightTrailingSpaces: {
...defaultSettingOptions,
value: false,
label: 'Highlight trailing spaces',
},
};
const readSettings = async () => {
const result: Record<string, any> = {};
for (const key in settingsSpec) {
result[key] = (await joplin.settings.value(key)) ?? true;
}
return result as PluginSettings;
};
await joplin.settings.registerSettings(settingsSpec);
await joplin.settings.onChange(async () => {
applySettings(await readSettings());
});
const settings = await readSettings();
applySettings(settings);
return settings;
};