From 3f0974285ec37ddc5f5350dbd2dadc2ac237551e Mon Sep 17 00:00:00 2001 From: nguyenvanduocit+ Date: Tue, 28 Feb 2023 22:03:36 +0700 Subject: [PATCH] fix: leaf is not open on 1st click --- src/fns/openView.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/fns/openView.ts b/src/fns/openView.ts index cef1d2e..8356de0 100644 --- a/src/fns/openView.ts +++ b/src/fns/openView.ts @@ -7,16 +7,17 @@ export const openView = async ( ): Promise => { let leaf: WorkspaceLeaf let leafs = workspace.getLeavesOfType(id) - if (leafs.length == 0) { - createView(workspace, id, position) + if (leafs.length > 0) { + workspace.revealLeaf(leafs[0]) return } - leaf = workspace.getLeavesOfType(id)[0] + leaf = await createView(workspace, id, position) workspace.revealLeaf(leaf) + return } -const createView = ( +const createView = async ( workspace: Workspace, id: string, position?: GateFrameOptionType @@ -34,6 +35,6 @@ const createView = ( leaf = workspace.getRightLeaf(false) break } - - leaf?.setViewState({ type: id, active: true }) + await leaf?.setViewState({ type: id, active: true }) + return leaf }