mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-22 12:57:01 -04:00
fix(ShikiCodeblocks): spoilers (#298)
* fix(ShikiCodeblocks): spoilers * fix a settings bug i thikn
This commit is contained in:
parent
2d08dd8a9c
commit
2de461985d
3 changed files with 25 additions and 9 deletions
|
@ -17,17 +17,28 @@
|
|||
*/
|
||||
|
||||
import { useSettings } from "@api/settings";
|
||||
import { React } from "@webpack/common";
|
||||
|
||||
import { shiki } from "../api/shiki";
|
||||
import { ShikiSettings } from "../types";
|
||||
|
||||
export function useShikiSettings(settingKeys: (keyof ShikiSettings)[], overrides?: Record<string, any>) {
|
||||
const settings = useSettings(settingKeys.map(key => `plugins.ShikiCodeblocks.${key}`)).plugins.ShikiCodeblocks as ShikiSettings;
|
||||
const [isLoading, setLoading] = React.useState(false);
|
||||
|
||||
const withOverrides = { ...settings, ...overrides };
|
||||
|
||||
const themeUrl = withOverrides.customTheme || withOverrides.theme;
|
||||
if (themeUrl !== shiki.currentThemeUrl) shiki.setTheme(themeUrl);
|
||||
|
||||
if (overrides) {
|
||||
const willChangeTheme = shiki.currentThemeUrl && themeUrl !== shiki.currentThemeUrl;
|
||||
const noOverrides = Object.keys(overrides).length === 0;
|
||||
|
||||
if (isLoading && (!willChangeTheme || noOverrides)) setLoading(false);
|
||||
if ((!isLoading && willChangeTheme)) {
|
||||
setLoading(true);
|
||||
shiki.setTheme(themeUrl);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...withOverrides,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue