From 1c198c5a77a6daa37042e54d1718ca5b4646be41 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 25 Oct 2023 17:08:35 +0200 Subject: [PATCH] fix open default file --- .../src/lib/components/homeTabFile.tsx | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx b/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx index 769d31daeb..41d0e13f23 100644 --- a/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx +++ b/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx @@ -134,22 +134,29 @@ function HomeTabFile({ plugin }: HomeTabFileProps) { const wName = 'Playground' const workspaces = await plugin.call('filePanel', 'getWorkspaces') + let createFile = true if (!workspaces.find((workspace) => workspace.name === wName)) { await plugin.call('filePanel', 'createWorkspace', wName, 'playground') + createFile = false } await plugin.call('filePanel', 'switchToWorkspace', { name: wName, isLocalHost: false }) await plugin.call('filePanel', 'switchToWorkspace', { name: wName, isLocalHost: false }) // calling once is not working. const content = `// SPDX-License-Identifier: MIT - pragma solidity >=0.6.12 <0.9.0; + pragma solidity >=0.6.12 <0.9.0; - contract HelloWorld { - function print() public pure returns (string memory) { - return "Hello World!"; + contract HelloWorld { + function print() public pure returns (string memory) { + return "Hello World!"; + } } + ` + if (createFile) { + const { newPath } = await plugin.call('fileManager', 'writeFileNoRewrite', '/contracts/helloWorld.sol', content) + await plugin.call('fileManager', 'open', newPath) + } else { + await plugin.call('fileManager', 'open', '/contracts/helloWorld.sol') } - ` - const { newPath } = await plugin.call('fileManager', 'writeFileNoRewrite', '/contracts/helloWorld.sol', content) - await plugin.call('fileManager', 'open', newPath) + } const uploadFile = async (target) => {