Skip to content

Build your personal knowledge base with Trilium Notes

client: Fix flicker of font selection

Elian Doran41e3163595e5
diff --git a/src/public/app/widgets/note_context_aware_widget.js b/src/public/app/widgets/note_context_aware_widget.js
index 76b3ab1bbd..06e6219e4e 100644
--- a/src/public/app/widgets/note_context_aware_widget.js
+++ b/src/public/app/widgets/note_context_aware_widget.js
@@ -50,6 +50,9 @@ class NoteContextAwareWidget extends BasicWidget {
/**
* @inheritdoc
*
+ * <p>
+ * If the widget is not enabled, it will not receive `refreshWithNote` updates.
+ *
* @returns {boolean} true when an active note exists
*/
isEnabled() {
diff --git a/src/public/app/widgets/type_widgets/options/appearance/fonts.js b/src/public/app/widgets/type_widgets/options/appearance/fonts.js
index fdc096f433..44c709f8e5 100644
--- a/src/public/app/widgets/type_widgets/options/appearance/fonts.js
+++ b/src/public/app/widgets/type_widgets/options/appearance/fonts.js
@@ -133,14 +133,17 @@ export default class FontsOptions extends OptionsWidget {
this.$widget.find(".reload-frontend-button").on("click", () => utils.reloadFrontendApp("changes from appearance options"));
}
+ isEnabled() {
+ return this._isEnabled;
+ }
+
async optionsLoaded(options) {
- if (options.overrideThemeFonts !== 'true') {
- this.toggleInt(false);
+ this._isEnabled = (options.overrideThemeFonts === 'true');
+ this.toggleInt(this._isEnabled);
+ if (!this._isEnabled) {
return;
}
- this.toggleInt(true);
-
this.$mainFontSize.val(options.mainFontSize);
this.fillFontFamilyOptions(this.$mainFontFamily, options.mainFontFamily);
diff --git a/src/public/app/widgets/type_widgets/options/options_widget.js b/src/public/app/widgets/type_widgets/options/options_widget.js
index bfbcb86573..0119fa5d9c 100644
--- a/src/public/app/widgets/type_widgets/options/options_widget.js
+++ b/src/public/app/widgets/type_widgets/options/options_widget.js
@@ -44,6 +44,20 @@ export default class OptionsWidget extends NoteContextAwareWidget {
optionsLoaded(options) {}
+ async refresh() {
+ this.toggleInt(this.isEnabled());
+ try {
+ await this.refreshWithNote(this.note);
+ } catch (e) {
+ // Ignore errors when user is refreshing or navigating away.
+ if (e === "rejected by browser") {
+ return;
+ }
+
+ throw e;
+ }
+ }
+
async refreshWithNote(note) {
const options = await server.get('options');