fix(options): "Override theme fonts" not reflecting immediately

This commit is contained in:
Elian Doran 2025-04-07 22:34:47 +03:00
parent d33162785e
commit c74f51472e
No known key found for this signature in database
2 changed files with 20 additions and 11 deletions

View File

@ -137,6 +137,12 @@ const CONTENT_WIDGETS: Record<string, (typeof NoteContextAwareWidget)[]> = {
] ]
}; };
/**
* Type widget that displays one or more widgets based on the type of note, generally used for options and other interactive notes such as the backend log.
*
* One important aspect is that, like its parent {@link TypeWidget}, the content widgets don't receive all events by default and they must be manually added
* to the propagation list in {@link TypeWidget.handleEventInChildren}.
*/
export default class ContentWidgetTypeWidget extends TypeWidget { export default class ContentWidgetTypeWidget extends TypeWidget {
private $content!: JQuery<HTMLElement>; private $content!: JQuery<HTMLElement>;
private widget?: BasicWidget; private widget?: BasicWidget;
@ -177,12 +183,4 @@ export default class ContentWidgetTypeWidget extends TypeWidget {
} }
} }
async handleEventInChildren<T extends EventNames>(name: T, data: EventData<T>) {
if (this.widget && this.widget.handleEvent) {
return this.widget.handleEvent(name, data);
}
return super.handleEventInChildren(name, data);
}
} }

View File

@ -4,6 +4,9 @@ import type FNote from "../../entities/fnote.js";
import type NoteDetailWidget from "../note_detail.js"; import type NoteDetailWidget from "../note_detail.js";
import type SpacedUpdate from "../../services/spaced_update.js"; import type SpacedUpdate from "../../services/spaced_update.js";
/**
* The base class for all the note types.
*/
export default abstract class TypeWidget extends NoteContextAwareWidget { export default abstract class TypeWidget extends NoteContextAwareWidget {
spacedUpdate!: SpacedUpdate; spacedUpdate!: SpacedUpdate;
@ -17,7 +20,7 @@ export default abstract class TypeWidget extends NoteContextAwareWidget {
return super.doRender(); return super.doRender();
} }
doRefresh(note: FNote | null | undefined) {} doRefresh(note: FNote | null | undefined): void | Promise<void> {}
async refresh() { async refresh() {
const thisWidgetType = (this.constructor as any).getType(); const thisWidgetType = (this.constructor as any).getType();
@ -61,12 +64,20 @@ export default abstract class TypeWidget extends NoteContextAwareWidget {
} }
} }
// events should be propagated manually to the children widgets /**
* {@inheritdoc}
*
* By default:
*
* - `activeContextChanged` is intercepted and converted to a `setNoteContext` event to avoid `refresh()`.
* - `entitiesReloaded` and `refreshData` are passed as-is.
* - any other event is not passed to the children.
*/
handleEventInChildren<T extends EventNames>(name: T, data: EventData<T>) { handleEventInChildren<T extends EventNames>(name: T, data: EventData<T>) {
if (["activeContextChanged", "setNoteContext"].includes(name)) { if (["activeContextChanged", "setNoteContext"].includes(name)) {
// won't trigger .refresh(); // won't trigger .refresh();
return super.handleEventInChildren("setNoteContext", data as EventData<"activeContextChanged">); return super.handleEventInChildren("setNoteContext", data as EventData<"activeContextChanged">);
} else if (name === "entitiesReloaded") { } else if (name === "entitiesReloaded" || name === "refreshData") {
return super.handleEventInChildren(name, data); return super.handleEventInChildren(name, data);
} else { } else {
return Promise.resolve(); return Promise.resolve();