Commit 064ea16b for codemirror.net
commit 064ea16b7d1c0724ed1f63b2d6187435c9497a1e
Author: Beni Cherniavsky-Paskin <cben@redhat.com>
Date: Mon Mar 11 20:02:26 2019 +0200
[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.
diff --git a/demo/theme.html b/demo/theme.html
index e394aa26..5fe7a575 100644
--- a/demo/theme.html
+++ b/demo/theme.html
@@ -183,9 +183,10 @@ function findSequence(goal) {
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 @@ function findSequence(goal) {
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(); }
});
</script>