Skip to content

Commit c86b0ff

Browse files
committed
ThemeChooser 1.10.1
1 parent f7e122c commit c86b0ff

File tree

4 files changed

+54
-8
lines changed

4 files changed

+54
-8
lines changed

np.ThemeChooser/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# np.ThemeChooser Changelog
22

3+
## [1.10.0] 2026-03-26 @dwertheimer
4+
5+
- Add **Refresh Current Theme** command: re-applies the active theme (`Editor.setTheme` with the current file) to reload theme CSS after editing a theme
6+
- **setTheme** / frontmatter theme change: apply with `Editor.setTheme(filename)` directly after lookup (avoid routing through `chooseTheme`) so the theme does not snap back
7+
38
## [1.9.1] 2025-02-20 @dwertheimer
49

510
- Add support for Eduard's hex colors in frontmatter (do not quote the hex color even though it's illegal YAML)

np.ThemeChooser/plugin.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"noteplan.minAppVersion": "3.7.2",
55
"plugin.id": "np.ThemeChooser",
66
"plugin.name": "🎨 Theme Chooser",
7-
"plugin.version": "1.9.1",
8-
"plugin.lastUpdateInfo": "1.9.1 Add support for Eduard's hex colors in frontmatter.\nPreviously: Add color picker to choose colors and write to frontmatter",
7+
"plugin.version": "1.10.1",
8+
"plugin.lastUpdateInfo": "1.10.1 Add /Reload Page with Current Theme to re-apply the active theme and reload CSS.\nPreviously: Add /Refresh Current Theme to re-apply the active theme and reload CSS.",
99
"plugin.description": "Choose from your favorite themes",
1010
"plugin.author": "dwertheimer",
1111
"plugin.dependencies": [],
@@ -39,6 +39,15 @@
3939
"theme name"
4040
]
4141
},
42+
{
43+
"name": "Reload Page with Current Theme",
44+
"description": "Re-apply the active theme to reload theme CSS (e.g. after editing the theme file)",
45+
"jsFunction": "refreshCurrentTheme",
46+
"alias": [
47+
"rthm", "refresh"
48+
],
49+
"arguments": []
50+
},
4251
{
4352
"name": "Choose HTML Color for Background",
4453
"description": "Choose a color and either save to the clipboard or write to frontmatter",

np.ThemeChooser/src/NPThemeChooser.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function chooseTheme(
6868
logDebug(pluginJson, `chooseTheme: "${themeName}" chosen`)
6969
const selected = await getThemeObj(themeName)
7070
if (selected && selected.filename) {
71-
logDebug(pluginJson, `chooseTheme: About to Editor.setTheme(${selected.filename}) Editor.setTheme(${selected.name})`)
71+
logDebug(pluginJson, `chooseTheme: About to Editor.setTheme(${selected.filename}) Theme name: ${selected.name}`)
7272
Editor.setTheme(selected.filename)
7373
} else {
7474
logError(pluginJson, `chooseTheme filename does not exist: selected=${JSP(selected)}`)
@@ -268,6 +268,29 @@ export async function toggleTheme() {
268268
}
269269
}
270270

271+
/**
272+
* Re-apply the active theme so NotePlan reloads theme CSS (same as `Editor.setTheme` with the current theme file).
273+
* Plugin entrypoint for "/Refresh Current Theme"
274+
* @returns {void}
275+
*/
276+
export function refreshCurrentTheme(): void {
277+
try {
278+
if (!Editor) {
279+
showMessage(`You must be in the Editor with a document open to run this command`)
280+
return
281+
}
282+
const filename = Editor.currentTheme?.filename
283+
if (filename?.length) {
284+
logDebug(pluginJson, `refreshCurrentTheme: Editor.setTheme(${filename})`)
285+
Editor.setTheme(filename)
286+
} else {
287+
logError(pluginJson, `refreshCurrentTheme: no current theme filename`)
288+
}
289+
} catch (error) {
290+
logError(pluginJson, JSP(error))
291+
}
292+
}
293+
271294
/**
272295
* Change theme from frontmatter:
273296
* triggers: onOpen => np.ThemeChooser.setTheme
@@ -281,12 +304,13 @@ export async function changeThemeFromFrontmatter() {
281304
logDebug(pluginJson, `changeThemeFromFrontmatter running`)
282305
const frontMatter = getFrontmatterAttributes(Editor)
283306
if (frontMatter && frontMatter.theme) {
284-
const themeName = frontMatter.theme
285-
// validate that a theme of that name exists
307+
const themeName = String(frontMatter.theme).trim()
308+
// validate that a theme of that name exists, then set by filename (avoid chooseTheme name/early-exit + double lookup)
286309
logDebug(pluginJson, `changeThemeFromFrontmatter: themeName="${themeName}"`)
287310
const themeObj = getThemeObjByName(themeName)
288-
if (themeObj) {
289-
await chooseTheme(themeName)
311+
if (themeObj && themeObj.filename) {
312+
logDebug(pluginJson, `changeThemeFromFrontmatter: Editor.setTheme(${themeObj.filename})`)
313+
Editor.setTheme(themeObj.filename)
290314
} else {
291315
logDebug(pluginJson, `changeThemeFromFrontmatter: 'Theme named: "${themeName}" does not exist. Please check the exact name of the theme'`)
292316
await showMessage(`Theme named: "${themeName}" does not exist. Please check the exact name of the theme`)

np.ThemeChooser/src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// @flow
22

3-
export { chooseTheme, setDefaultLightDarkTheme, toggleTheme, copyCurrentTheme, changeThemeFromFrontmatter, addThemeFrontmatter } from './NPThemeChooser' // add one of these for every command specifified in plugin.json (the function could be in any file as long as it's exported)
3+
export {
4+
chooseTheme,
5+
setDefaultLightDarkTheme,
6+
toggleTheme,
7+
copyCurrentTheme,
8+
changeThemeFromFrontmatter,
9+
addThemeFrontmatter,
10+
refreshCurrentTheme,
11+
} from './NPThemeChooser' // add one of these for every command specifified in plugin.json (the function could be in any file as long as it's exported)
412
export { copyThemeStyle, editStyleAttribute, createThemeSamples, setColor, removeStyle } from './NPThemeCustomizer'
513
export { changePreset, runPreset01, runPreset02, runPreset03, runPreset04, runPreset05 } from './NPThemePresets'
614
export { onOpenTheme, onOpenRefreshPage, onEdit, onSave, onUpdateOrInstall, init, onSettingsUpdated } from './NPThemeHooks'

0 commit comments

Comments
 (0)