Skip to content

Build your personal knowledge base with Trilium Notes

fix(leftpaneVisibility): Make leftpane visibility switch no longer depend on entitiesReloadedEvent

SiriusXT025c6a4e0ebe
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts
index 1855876d36..b646780119 100644
--- a/apps/client/src/components/app_context.ts
+++ b/apps/client/src/components/app_context.ts
@@ -283,6 +283,9 @@ export type CommandMappings = {
type EventMappings = {
initialRenderComplete: {};
frocaReloaded: {};
+ setLeftPaneVisibility: {
+ leftPaneVisible: boolean | null;
+ }
protectedSessionStarted: {};
notesReloaded: {
noteIds: string[];
diff --git a/apps/client/src/components/root_command_executor.ts b/apps/client/src/components/root_command_executor.ts
index 1e16fae81e..8e7df94940 100644
--- a/apps/client/src/components/root_command_executor.ts
+++ b/apps/client/src/components/root_command_executor.ts
@@ -78,15 +78,15 @@ export default class RootCommandExecutor extends Component {
}
hideLeftPaneCommand() {
- options.save(`leftPaneVisible`, "false");
+ appContext.triggerEvent("setLeftPaneVisibility", { leftPaneVisible: false });
}
showLeftPaneCommand() {
- options.save(`leftPaneVisible`, "true");
+ appContext.triggerEvent("setLeftPaneVisibility", { leftPaneVisible: true });
}
toggleLeftPaneCommand() {
- options.toggle("leftPaneVisible");
+ appContext.triggerEvent("setLeftPaneVisibility", { leftPaneVisible: null });
}
async showBackendLogCommand() {
diff --git a/apps/client/src/widgets/buttons/left_pane_toggle.ts b/apps/client/src/widgets/buttons/left_pane_toggle.ts
index 99fa0530b8..22a9026221 100644
--- a/apps/client/src/widgets/buttons/left_pane_toggle.ts
+++ b/apps/client/src/widgets/buttons/left_pane_toggle.ts
@@ -35,13 +35,9 @@ export default class LeftPaneToggleWidget extends CommandButtonWidget {
super.refreshIcon();
splitService.setupLeftPaneResizer(this.currentLeftPaneVisible);
}
-
- entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
- if (loadResults.isOptionReloaded("leftPaneVisible") && document.hasFocus()) {
- // options.is("leftPaneVisible") changed — it may or may not be the same as currentLeftPaneVisible, but as long as the window is focused, the left pane visibility should be toggled.
- // See PR description for detailed explanation of multi-window edge cases: https://github.com/TriliumNext/Notes/pull/1962
- this.currentLeftPaneVisible = !this.currentLeftPaneVisible;
- this.refreshIcon();
- }
+
+ setLeftPaneVisibilityEvent({ leftPaneVisible }: EventData<"setLeftPaneVisibility">) {
+ this.currentLeftPaneVisible = leftPaneVisible ?? !this.currentLeftPaneVisible;
+ this.refreshIcon();
}
}
diff --git a/apps/client/src/widgets/containers/left_pane_container.ts b/apps/client/src/widgets/containers/left_pane_container.ts
index c9016b8aec..d95f5091a0 100644
--- a/apps/client/src/widgets/containers/left_pane_container.ts
+++ b/apps/client/src/widgets/containers/left_pane_container.ts
@@ -20,18 +20,17 @@ export default class LeftPaneContainer extends FlexContainer<Component> {
return super.isEnabled() && this.currentLeftPaneVisible;
}
- entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
- if (loadResults.isOptionReloaded("leftPaneVisible") && document.hasFocus()) {
- // options.is("leftPaneVisible") changed — it may or may not be the same as currentLeftPaneVisible, but as long as the window is focused, the left pane visibility should be toggled.
- this.currentLeftPaneVisible = !this.currentLeftPaneVisible;
- const visible = this.isEnabled();
- this.toggleInt(visible);
+ setLeftPaneVisibilityEvent({ leftPaneVisible }: EventData<"setLeftPaneVisibility">) {
+ this.currentLeftPaneVisible = leftPaneVisible ?? !this.currentLeftPaneVisible;
+ const visible = this.isEnabled();
+ this.toggleInt(visible);
- if (visible) {
- this.triggerEvent("focusTree", {});
- } else {
- this.triggerEvent("focusOnDetail", { ntxId: appContext.tabManager.getActiveContext()?.ntxId });
- }
+ if (visible) {
+ this.triggerEvent("focusTree", {});
+ } else {
+ this.triggerEvent("focusOnDetail", { ntxId: appContext.tabManager.getActiveContext()?.ntxId });
}
+
+ options.save("leftPaneVisible", this.currentLeftPaneVisible.toString());
}
}