mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 07:08:55 +02:00
feat(mermaid): react to layout change immediately
This commit is contained in:
parent
cf874b5ee8
commit
4860594758
@ -6,6 +6,7 @@ import Split from "split.js";
|
||||
import { DEFAULT_GUTTER_SIZE } from "../../services/resizer.js";
|
||||
import options from "../../services/options.js";
|
||||
import type SwitchSplitOrientationButton from "../floating_buttons/switch_layout_button.js";
|
||||
import type { EventData } from "../../components/app_context.js";
|
||||
|
||||
const TPL = `\
|
||||
<div class="note-detail-split note-detail-printable">
|
||||
@ -106,7 +107,7 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
||||
private $editor!: JQuery<HTMLElement>;
|
||||
private $errorContainer!: JQuery<HTMLElement>;
|
||||
private editorTypeWidget: EditableCodeTypeWidget;
|
||||
private layoutOrientation!: "horizontal" | "vertical";
|
||||
private layoutOrientation?: "horizontal" | "vertical";
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@ -118,17 +119,13 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
||||
doRender(): void {
|
||||
this.$widget = $(TPL);
|
||||
|
||||
const layoutOrientation = options.get("splitEditorOrientation") ?? "horizontal";
|
||||
this.$widget.addClass(`split-${layoutOrientation}`);
|
||||
this.layoutOrientation = layoutOrientation as ("horizontal" | "vertical");
|
||||
|
||||
this.$firstCol = this.$widget.find(".note-detail-split-first-col");
|
||||
this.$secondCol = this.$widget.find(".note-detail-split-second-col");
|
||||
this.$preview = this.$widget.find(".note-detail-split-preview");
|
||||
this.$editor = this.$widget.find(".note-detail-split-editor");
|
||||
this.$editor.append(this.editorTypeWidget.render());
|
||||
this.$errorContainer = this.$widget.find(".note-detail-error-container");
|
||||
this.#setupResizer();
|
||||
this.#adjustLayoutOrientation();
|
||||
|
||||
super.doRender();
|
||||
}
|
||||
@ -139,6 +136,8 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
||||
}
|
||||
|
||||
async doRefresh(note: FNote | null | undefined) {
|
||||
this.#adjustLayoutOrientation();
|
||||
|
||||
await this.editorTypeWidget.initialized;
|
||||
|
||||
if (note) {
|
||||
@ -148,6 +147,18 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
||||
}
|
||||
}
|
||||
|
||||
#adjustLayoutOrientation() {
|
||||
const layoutOrientation = options.get("splitEditorOrientation") ?? "horizontal";
|
||||
if (this.layoutOrientation === layoutOrientation) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.$widget.toggleClass("split-horizontal", layoutOrientation === "horizontal");
|
||||
this.$widget.toggleClass("split-vertical", layoutOrientation === "vertical");
|
||||
this.layoutOrientation = layoutOrientation as ("horizontal" | "vertical");
|
||||
this.#setupResizer();
|
||||
}
|
||||
|
||||
#setupResizer() {
|
||||
if (!utils.isDesktop()) {
|
||||
return;
|
||||
@ -188,4 +199,10 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
||||
return this.editorTypeWidget.getData();
|
||||
}
|
||||
|
||||
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
||||
if (loadResults.isOptionReloaded("splitEditorOrientation")) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user