Skip to content

Commit 59f9cf2

Browse files
committed
Set preferred-dark-theme to the last dark theme
If the user doesn't have a preferred dark theme but is already using a dark theme, set the preferred dark theme to be that theme
1 parent db7c8f4 commit 59f9cf2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/librustdoc/html/static/storage.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// From rust:
22
/* global resourcesSuffix */
33

4+
var darkThemes = ["dark", "ayu"];
45
var currentTheme = document.getElementById("themeStyle");
56
var mainTheme = document.getElementById("mainThemeStyle");
7+
var localStoredTheme = getCurrentValue("rustdoc-theme");
68

79
var savedHref = [];
810

@@ -179,6 +181,14 @@ var updateSystemTheme = (function() {
179181
})();
180182

181183
if (getCurrentValue("rustdoc-use-system-theme") !== "false" && window.matchMedia) {
184+
// update the preferred dark theme if the user is already using a dark theme
185+
// See https://github.com/rust-lang/rust/pull/77809#issuecomment-707875732
186+
if (getCurrentValue("rustdoc-use-system-theme") === null
187+
&& getCurrentValue("rustdoc-preferred-dark-theme") === null
188+
&& darkThemes.indexOf(localStoredTheme) >= 0) {
189+
updateLocalStorage("rustdoc-preferred-dark-theme", localStoredTheme);
190+
}
191+
182192
// call the function to initialize the theme at least once!
183193
updateSystemTheme();
184194
} else {

0 commit comments

Comments
 (0)