From b9f005e3247bce27837fe3b9714cfd0968221384 Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Fri, 20 Jan 2023 05:12:46 -0500 Subject: [PATCH] Patch highlighting color scheme setting bug (#4622) --- static/settings.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/static/settings.ts b/static/settings.ts index 903d7e06f15..54854315e2e 100644 --- a/static/settings.ts +++ b/static/settings.ts @@ -30,7 +30,7 @@ import {themes, Themes} from './themes'; import {AppTheme, ColourScheme, ColourSchemeInfo} from './colour'; import {Hub} from './hub'; import {EventHub} from './event-hub'; -import {keys} from '../lib/common-utils'; +import {keys, isString} from '../lib/common-utils'; import {assert, unwrapString} from './assert'; import {LanguageKey} from '../types/languages.interfaces'; @@ -459,12 +459,16 @@ export class Settings { const themeSelect = this.root.find('.theme'); const colourSchemeSelect = this.root.find('.colourScheme'); - if (!colourSchemeSelect.val()) { - return; - } - const oldScheme = unwrapString(colourSchemeSelect.val()); + const oldScheme = colourSchemeSelect.val(); const newTheme = unwrapString(themeSelect.val()); + // Small check to make sure we aren't getting something completely unexpected, like a string[] or number + assert( + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + isString(oldScheme) || oldScheme === undefined || oldScheme == null, + 'Unexpected value received from colourSchemeSelect.val()' + ); + this.fillColourSchemeSelector(colourSchemeSelect, newTheme); const newThemeStoredScheme = $.data(themeSelect, 'theme-' + newTheme) as colour.AppTheme | undefined; @@ -473,7 +477,7 @@ export class Settings { // If we have one old one stored, check if it's still valid and set it if so if (newThemeStoredScheme && this.selectorHasOption(colourSchemeSelect, newThemeStoredScheme)) { newScheme = newThemeStoredScheme; - } else if (this.selectorHasOption(colourSchemeSelect, oldScheme)) { + } else if (isString(oldScheme) && this.selectorHasOption(colourSchemeSelect, oldScheme)) { newScheme = oldScheme; }