From d29d7417c04a467dafe859517a2619bdb4e616ce Mon Sep 17 00:00:00 2001 From: Beni Cherniavsky-Paskin Date: Mon, 11 Mar 2019 20:02:26 +0200 Subject: [PATCH] [theme demo] Fix dropdown losing choice on solarized light / dark Choosing "solarized dark" correctly sets .cm-s-solarized .cm-s-dark (as documented https://codemirror.net/doc/manual.html#option_theme). It then sets URL fragment to #solarized%20dark, which was looking for `solarized%20dark` in dropdown and failing. This commit makes both setting and getting URL fragment reliable. --- demo/theme.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/demo/theme.html b/demo/theme.html index e394aa266b..5fe7a57547 100644 --- a/demo/theme.html +++ b/demo/theme.html @@ -183,9 +183,10 @@

Theme Demo

function selectTheme() { var theme = input.options[input.selectedIndex].textContent; editor.setOption("theme", theme); - location.hash = "#" + theme; + location.hash = "#" + encodeURIComponent(theme); } - var choice = (location.hash && location.hash.slice(1)) || + var choice = (location.hash && + decodeURIComponent(location.hash.slice(1))) || (document.location.search && decodeURIComponent(document.location.search.slice(1))); if (choice) { @@ -193,7 +194,7 @@

Theme Demo

editor.setOption("theme", choice); } CodeMirror.on(window, "hashchange", function() { - var theme = location.hash.slice(1); + var theme = decodeURIComponent(location.hash.slice(1)); if (theme) { input.value = theme; selectTheme(); } });