From 9240de93ebae076a8b1d107d4cb9fe5b2c31f7c5 Mon Sep 17 00:00:00 2001 From: mgmeyers Date: Thu, 2 May 2024 10:00:18 -0700 Subject: [PATCH] Fix #581; Note folder dropdown is empty after folder has been moved --- src/settingHelpers.ts | 53 ++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/settingHelpers.ts b/src/settingHelpers.ts index 42978715..d58de8c1 100644 --- a/src/settingHelpers.ts +++ b/src/settingHelpers.ts @@ -92,29 +92,36 @@ export function createSearchSelect({ el.win.setTimeout(() => { let list = choices; - const [value, defaultVal] = manager.getSetting(key, local); - - if (defaultVal) { - const index = choices.findIndex((f) => f.value === defaultVal); - const choice = choices[index]; + const [value, globalValue] = manager.getSetting(key, local); + + let didSetPlaceholder = false; + if (globalValue) { + const index = list.findIndex((f) => f.value === globalValue); + + if (index > -1) { + didSetPlaceholder = true; + const choice = choices[index]; + + list = update(list, { + $splice: [[index, 1]], + $unshift: [ + update(choice, { + placeholder: { + $set: true, + }, + value: { + $set: '', + }, + label: { + $apply: (v) => `${v} (${t('default')})`, + }, + }), + ], + }); + } + } - list = update(list, { - $splice: [[index, 1]], - $unshift: [ - update(choice, { - placeholder: { - $set: true, - }, - value: { - $set: '', - }, - label: { - $apply: (v) => `${v} (${t('default')})`, - }, - }), - ], - }); - } else { + if (!didSetPlaceholder) { list = update(list, { $unshift: [ { @@ -136,7 +143,7 @@ export function createSearchSelect({ choices: list, }).setChoiceByValue(''); - if (value && typeof value === 'string') { + if (value && typeof value === 'string' && list.findIndex((f) => f.value === value) > -1) { c.setChoiceByValue(value); }