Skip to content

Commit 064ea16

Browse files
cbenmarijnh
authored andcommitted
[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.
1 parent b60e456 commit 064ea16

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

demo/theme.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,18 @@ <h2>Theme Demo</h2>
183183
function selectTheme() {
184184
var theme = input.options[input.selectedIndex].textContent;
185185
editor.setOption("theme", theme);
186-
location.hash = "#" + theme;
186+
location.hash = "#" + encodeURIComponent(theme);
187187
}
188-
var choice = (location.hash && location.hash.slice(1)) ||
188+
var choice = (location.hash &&
189+
decodeURIComponent(location.hash.slice(1))) ||
189190
(document.location.search &&
190191
decodeURIComponent(document.location.search.slice(1)));
191192
if (choice) {
192193
input.value = choice;
193194
editor.setOption("theme", choice);
194195
}
195196
CodeMirror.on(window, "hashchange", function() {
196-
var theme = location.hash.slice(1);
197+
var theme = decodeURIComponent(location.hash.slice(1));
197198
if (theme) { input.value = theme; selectTheme(); }
198199
});
199200
</script>

0 commit comments

Comments
 (0)