diff --git a/apps/remix-ide-e2e/src/tests/gist.test.ts b/apps/remix-ide-e2e/src/tests/gist.test.ts index b495527eab..2cbefb4d0c 100644 --- a/apps/remix-ide-e2e/src/tests/gist.test.ts +++ b/apps/remix-ide-e2e/src/tests/gist.test.ts @@ -145,6 +145,18 @@ module.exports = { .openFile(`gist-${testData.validGistId}/README.txt`) .waitForElementVisible(`div[data-path='default_workspace/gist-${testData.validGistId}/README.txt']`) .assert.containsText(`div[data-path='default_workspace/gist-${testData.validGistId}/README.txt'] > span`, 'README.txt') - .end() - } + }, + + 'Load Gist from URL and verify truncated files are loaded #group3': function (browser: NightwatchBrowser) { + const gistId = '1b179bf1b92c8b0664b4cbe61774e15d' + browser + .url('http://127.0.0.1:8080/#gist=' + gistId) + .refreshPage() + .waitForElementVisible('*[data-id="remixIdeIconPanel"]', 15000) + .waitForElementVisible(`#fileExplorerView li[data-path='gist-${gistId}/README.txt']`, 30000) + .openFile(`gist-${gistId}/scripts/deploy_with_ethers.ts`) + .getEditorValue((content) => { + browser.assert.ok(content !== '') + }) + } } diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 1395ae06d4..5bdd0df427 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -402,6 +402,7 @@ export const handleClickFile = async (path: string, type: 'file' | 'folder' | 'g if (type === 'file' && path.endsWith('.md')) { // just opening the preview await plugin.call('doc-viewer' as any, 'viewDocs', [path]) + plugin.call('tabs' as any, 'focus', 'doc-viewer') } else { await plugin.fileManager.open(path) dispatch(focusElement([{ key: path, type }])) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 3a932a8f9d..c3187c745a 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -308,11 +308,21 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe } const obj = {} - Object.keys(data.files).forEach((element) => { + for (const [element] of Object.entries(data.files)) { const path = element.replace(/\.\.\./g, '/') + let value + if (data.files[element].truncated) { + const response: AxiosResponse = await axios.get(data.files[element].raw_url) + value = { content: response.data } + } else { + value = { content: data.files[element].content } + } - obj['/' + 'gist-' + gistId + '/' + path] = data.files[element] - }) + if (data.files[element].type === 'application/json') { + obj['/' + 'gist-' + gistId + '/' + path] = { content: JSON.stringify(value.content, null, '\t') } + } else + obj['/' + 'gist-' + gistId + '/' + path] = value + } plugin.fileManager.setBatchFiles(obj, 'workspace', true, (errorLoadingFile) => { if (errorLoadingFile) { dispatch(displayNotification('', errorLoadingFile.message || errorLoadingFile, 'OK', null, () => {}, null))