Skip to content

Commit

Permalink
feat(demo): add reset layout button
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Mar 15, 2024
1 parent 4d7eeae commit c72bed6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions demo/src/main.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ void getApi().then(async vscode => {
window.location.href = url.toString()
})

document.querySelector('#resetLayout')!.addEventListener('click', async () => {
const url = new URL(window.location.href)
url.searchParams.set('resetLayout', 'true')
window.location.href = url.toString()
})

document.querySelector('#filesystem')!.addEventListener('click', async () => {
const dirHandle = await window.showDirectoryPicker()

Expand Down
10 changes: 8 additions & 2 deletions demo/src/setup.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,15 @@ window.MonacoEnvironment = {
}
}

const params = new URL(document.location.href).searchParams
const url = new URL(document.location.href)
const params = url.searchParams
export const remoteAuthority = params.get('remoteAuthority') ?? undefined
export const connectionToken = params.get('connectionToken') ?? undefined
export const remotePath = remoteAuthority != null ? params.get('remotePath') ?? undefined : undefined
export const resetLayout = params.has('resetLayout')
params.delete('resetLayout')

window.history.replaceState({}, document.title, url.href)

// Set configuration before initializing service so it's directly available (especially for the theme, to prevent a flicker)
export const workspaceFile = monaco.Uri.file('/workspace.code-workspace')
Expand Down Expand Up @@ -235,7 +240,8 @@ export const constructOptions: IWorkbenchConstructionOptions = {
},
views: [{
id: 'custom-view'
}]
}],
force: resetLayout
},
welcomeBanner: {
message: 'Welcome in monaco-vscode-api demo'
Expand Down
1 change: 1 addition & 0 deletions demo/src/setup.views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ container.innerHTML = `
<button id="filesystem">Attach filesystem</button>
<button id="customEditorPanel">Open custom editor panel</button>
<button id="clearStorage">Clear user data</button>
<button id="resetLayout">Reset layout</button>
<button id="toggleFullWorkbench">Switch to full workbench mode</button>
<br />
<button id="togglePanel">Toggle Panel</button>
Expand Down
1 change: 1 addition & 0 deletions demo/src/setup.workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ buttons.innerHTML = `
<button id="filesystem">Attach filesystem</button>
<button id="customEditorPanel">Open custom editor panel</button>
<button id="clearStorage">Clear user data</button>
<button id="resetLayout">Reset layout</button>
<button id="toggleFullWorkbench">Switch to custom rendering mode</button>
<br />
<button id="togglePanel">Toggle Panel</button>
Expand Down

0 comments on commit c72bed6

Please sign in to comment.