-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathsettings.ts
More file actions
287 lines (258 loc) · 9.61 KB
/
settings.ts
File metadata and controls
287 lines (258 loc) · 9.61 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import { Algorithm } from "src/algorithms/base/isrs-algorithm";
import { DataStoreName } from "src/data-stores/base/data-store";
import { t } from "src/lang/helpers";
import { pathMatchesPattern } from "src/utils/fs";
export interface SRSettings {
// flashcards
flashcardTags: string[];
flashcardTagsToIgnore: string[];
convertFoldersToDecks: boolean;
burySiblingCards: boolean;
randomizeCardOrder: boolean | undefined;
flashcardCardOrder: string;
flashcardDeckOrder: string;
convertClozePatternsToInputs: boolean;
convertHighlightsToClozes: boolean;
convertBoldTextToClozes: boolean;
convertCurlyBracketsToClozes: boolean;
clozePatterns: string[];
singleLineCardSeparator: string;
singleLineReversedCardSeparator: string;
multilineCardSeparator: string;
multilineReversedCardSeparator: string;
multilineCardEndMarker: string;
editLaterTag: string;
// notes
enableNoteReviewPaneOnStartup: boolean;
tagsToReview: string[];
noteTagsToIgnore: string[];
noteFoldersToIgnore: string[];
openRandomNote: boolean;
autoNextNote: boolean;
disableFileMenuReviewOptions: boolean | undefined;
showFileMenuReviewOptions: boolean;
deleteTagsOnSchedulingDataDeletion: boolean;
maxNDaysNotesReviewQueue: number;
// UI preferences
showRibbonIcon: boolean;
showStatusBar: boolean;
showCardStatusBarItem: boolean;
showNoteStatusBarItem: boolean;
showUpdateAvailableStatusBarItem: boolean;
initiallyExpandAllSubdecksInTree: boolean;
showContextInCards: boolean;
showIntervalInReviewButtons: boolean;
flashcardHeightPercentage: number;
flashcardWidthPercentage: number;
flashcardHeightPercentageMobile: number;
flashcardWidthPercentageMobile: number;
flashcardAgainText: string;
flashcardEasyText: string;
flashcardGoodText: string;
flashcardHardText: string;
reviewButtonDelay: number;
openViewInNewTabMobile: boolean;
showDeleteButtonInCardView: boolean;
showDeleteButtonInFileMenu: boolean;
openViewInNewTab: boolean;
useCustomHotkeys: boolean;
// algorithm
algorithm: string;
baseEase: number;
lapsesIntervalChange: number;
easyBonus: number;
loadBalance: boolean;
maximumInterval: number;
maxLinkFactor: number;
fsrsDesiredRetention: number;
startOfDay: string;
// storage
dataStore: string;
cardCommentOnSameLine: boolean;
// logging
showSchedulingDebugMessages: boolean;
showParserDebugMessages: boolean;
preferredDateFormatForNoteReviewQueue: string;
}
export const DEFAULT_SETTINGS: SRSettings = {
// flashcards
flashcardTags: ["#flashcards"],
flashcardTagsToIgnore: [],
convertFoldersToDecks: false,
burySiblingCards: false,
flashcardCardOrder: "DueFirstRandom",
flashcardDeckOrder: "PrevDeckComplete_Sequential",
convertClozePatternsToInputs: false,
convertHighlightsToClozes: true,
convertBoldTextToClozes: false,
convertCurlyBracketsToClozes: false,
clozePatterns: ["==[123;;]answer[;;hint]=="],
singleLineCardSeparator: "::",
singleLineReversedCardSeparator: ":::",
multilineCardSeparator: "?",
multilineReversedCardSeparator: "??",
multilineCardEndMarker: "",
editLaterTag: "#edit-later",
randomizeCardOrder: undefined,
// notes
enableNoteReviewPaneOnStartup: true,
tagsToReview: ["#review"],
noteTagsToIgnore: [],
noteFoldersToIgnore: ["**/*.excalidraw.md"],
openRandomNote: false,
autoNextNote: false,
disableFileMenuReviewOptions: undefined,
showFileMenuReviewOptions: true,
deleteTagsOnSchedulingDataDeletion: false,
maxNDaysNotesReviewQueue: 365,
// UI settings
showRibbonIcon: true,
showStatusBar: true,
showCardStatusBarItem: true,
showNoteStatusBarItem: true,
showUpdateAvailableStatusBarItem: true,
initiallyExpandAllSubdecksInTree: true,
showContextInCards: true,
showIntervalInReviewButtons: true,
flashcardHeightPercentage: 60,
flashcardWidthPercentage: 60,
flashcardHeightPercentageMobile: 100,
flashcardWidthPercentageMobile: 100,
flashcardAgainText: t("AGAIN"),
flashcardEasyText: t("EASY"),
flashcardGoodText: t("GOOD"),
flashcardHardText: t("HARD"),
reviewButtonDelay: 0,
showDeleteButtonInCardView: false,
showDeleteButtonInFileMenu: false,
openViewInNewTab: false,
openViewInNewTabMobile: false,
useCustomHotkeys: false,
// algorithm
algorithm: Algorithm.SM_2_OSR,
baseEase: 250,
lapsesIntervalChange: 0.5,
easyBonus: 1.3,
loadBalance: true,
maximumInterval: 36525,
maxLinkFactor: 1.0,
fsrsDesiredRetention: 0.9,
startOfDay: "00:00:00",
// storage
dataStore: DataStoreName.NOTES,
cardCommentOnSameLine: false,
// logging
showSchedulingDebugMessages: false,
showParserDebugMessages: false,
preferredDateFormatForNoteReviewQueue: "MMM DD YYYY",
};
export function upgradeSettings(settings: SRSettings) {
if (
settings.randomizeCardOrder !== null &&
settings.randomizeCardOrder !== undefined &&
(settings.flashcardCardOrder === null || settings.flashcardCardOrder === undefined) &&
(settings.flashcardDeckOrder === null || settings.flashcardDeckOrder === undefined)
) {
settings.flashcardCardOrder = settings.randomizeCardOrder
? "DueFirstRandom"
: "DueFirstSequential";
settings.flashcardDeckOrder = "PrevDeckComplete_Sequential";
// After the upgrade, we don't need the old attribute any more
settings.randomizeCardOrder = undefined;
}
if (settings.clozePatterns === null || settings.clozePatterns === undefined) {
settings.clozePatterns = [];
if (settings.convertHighlightsToClozes)
settings.clozePatterns.push("==[123;;]answer[;;hint]==");
if (settings.convertBoldTextToClozes)
settings.clozePatterns.push("**[123;;]answer[;;hint]**");
if (settings.convertCurlyBracketsToClozes)
settings.clozePatterns.push("{{[123;;]answer[;;hint]}}");
}
if (settings.disableFileMenuReviewOptions !== undefined) {
settings.disableFileMenuReviewOptions = undefined;
}
if (settings.fsrsDesiredRetention === null || settings.fsrsDesiredRetention === undefined) {
settings.fsrsDesiredRetention = DEFAULT_SETTINGS.fsrsDesiredRetention;
}
}
export class SettingsUtil {
static isFlashcardTag(settings: SRSettings, tag: string): boolean {
return SettingsUtil.isTagInList(settings.flashcardTags, tag);
}
static isPathInNoteIgnoreFolder(settings: SRSettings, path: string): boolean {
return settings.noteFoldersToIgnore.some((folder) => pathMatchesPattern(path, folder));
}
static isAnyTagANoteReviewTag(settings: SRSettings, tags: string[]): boolean {
for (const tag of tags) {
if (
settings.tagsToReview.some((tagToReview) =>
this.isSubTagContainedInTag(tagToReview, tag),
)
) {
return true;
}
}
return false;
}
static isAnyTagIgnoredForFlashcards(settings: SRSettings, tags: string[]): boolean {
return tags.some((tag) => SettingsUtil.isTagInList(settings.flashcardTagsToIgnore, tag));
}
static isAnyTagIgnoredForNotes(settings: SRSettings, tags: string[]): boolean {
return tags.some((tag) => SettingsUtil.isTagInList(settings.noteTagsToIgnore, tag));
}
// Given a list of tags, return the subset that is in settings.tagsToReview
static filterForNoteReviewTag(settings: SRSettings, tags: string[]): string[] {
const result: string[] = [];
for (const tagToReview of settings.tagsToReview) {
if (tags.some((tag) => this.isSubTagContainedInTag(tagToReview, tag))) {
result.push(tagToReview);
}
}
return result;
}
/**
* Checks if the tag is in the tagList.
*
* @param tagList - The list of tags to check.
* @param tag - The tag to check.
* @param exactMatch - Whether to match the tag exactly or if it should be a sub tag.
* @returns true if the tag is in the tagList, false otherwise.
*/
public static isTagInList(
tagList: string[],
tag: string,
exactMatch: boolean = false,
): boolean {
// This should be true, if the tag is fully contained in a tag from the list
for (const tagFromList of tagList) {
if (exactMatch) {
if (tagFromList === tag) {
// The tag from the list is the same as the current tag, so it is contained in it
return true;
}
} else {
// In this case we need to look more in detail to see if the tag is fully contained in the tag from the list
if (this.isSubTagContainedInTag(tagFromList, tag)) {
// The tag from the list is contained in the current tag, so it is contained in it
return true;
}
}
}
return false;
}
/**
* Checks if the subTag is contained in the tag.
*
* @param tag - The tag to check.
* @param subTag - The subTag to check.
* @returns true if the subTag is contained in the tag, false otherwise.
*/
public static isSubTagContainedInTag(tag: string, subTag: string): boolean {
if (tag === subTag || subTag.startsWith(tag + "/")) {
// The tag is the same as the sub tag, or the sub tag is contained in the tag
return true;
}
return false;
}
}