You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
This commit is contained in:
@@ -522,6 +522,13 @@ describe('models/Setting', () => {
|
|||||||
expect(Setting.value('revisionService.ttlDays')).toBe(1);
|
expect(Setting.value('revisionService.ttlDays')).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not fail to save settings that can conflict with uninstalled plugin settings', async () => {
|
||||||
|
Setting.setValue('editor.imageRendering', true);
|
||||||
|
expect(Setting.value('editor.imageRendering')).toBe(true);
|
||||||
|
Setting.setValue('editor.imageRendering', false);
|
||||||
|
expect(Setting.value('editor.imageRendering')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
test('should adjust settings to avoid conflicts', async () => {
|
test('should adjust settings to avoid conflicts', async () => {
|
||||||
const testSettingId = 'plugin-plugin.calebjohn.rich-markdown.inlineImages';
|
const testSettingId = 'plugin-plugin.calebjohn.rich-markdown.inlineImages';
|
||||||
await Setting.registerSetting(testSettingId, {
|
await Setting.registerSetting(testSettingId, {
|
||||||
|
|||||||
@@ -808,15 +808,20 @@ class Setting extends BaseModel {
|
|||||||
this.scheduleChangeEvent();
|
this.scheduleChangeEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setValueInternalIfExists = <Key extends string> (key: Key, value: SettingValueType<Key>) => {
|
||||||
|
if (!this.keyExists(key)) return;
|
||||||
|
setValueInternal(key, value);
|
||||||
|
};
|
||||||
|
|
||||||
setValueInternal(key, value);
|
setValueInternal(key, value);
|
||||||
|
|
||||||
// Prevent conflicts. Use setValueInternal to avoid infinite recursion in the case
|
// Prevent conflicts. Use setValueInternal to avoid infinite recursion in the case
|
||||||
// where conflictingSettings has invalid data.
|
// where conflictingSettings has invalid data.
|
||||||
for (const conflict of conflictingSettings) {
|
for (const conflict of conflictingSettings) {
|
||||||
if (conflict.key1 === key && conflict.value1 === value) {
|
if (conflict.key1 === key && conflict.value1 === value) {
|
||||||
setValueInternal(conflict.key2, conflict.alternate2);
|
setValueInternalIfExists(conflict.key2, conflict.alternate2);
|
||||||
} else if (conflict.key2 === key && conflict.value2 === value) {
|
} else if (conflict.key2 === key && conflict.value2 === value) {
|
||||||
setValueInternal(conflict.key1, conflict.alternate1);
|
setValueInternalIfExists(conflict.key1, conflict.alternate1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user