diff options
Diffstat (limited to 'src/vs/workbench/contrib/notebook/common/notebookCommon.ts')
-rw-r--r-- | src/vs/workbench/contrib/notebook/common/notebookCommon.ts | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index 8e13cf654cd..7eca3e5a6cf 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { VSBuffer } from 'vs/base/common/buffer'; +import { decodeBase64, encodeBase64, VSBuffer } from 'vs/base/common/buffer'; import { CancellationToken } from 'vs/base/common/cancellation'; import { IDiffResult } from 'vs/base/common/diff/diff'; import { Event } from 'vs/base/common/event'; @@ -524,33 +524,45 @@ export namespace CellUri { export const scheme = Schemas.vscodeNotebookCell; - const _regex = /^ch(\d{7,})/; + + const _lengths = ['W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f']; + const _padRegexp = new RegExp(`^[${_lengths.join('')}]+`); + const _radix = 7; export function generate(notebook: URI, handle: number): URI { - return notebook.with({ - scheme, - fragment: `ch${handle.toString().padStart(7, '0')}${notebook.scheme !== Schemas.file ? notebook.scheme : ''}` - }); + + const s = handle.toString(_radix); + const p = s.length < _lengths.length ? _lengths[s.length - 1] : 'z'; + + const fragment = `${p}${s}s${encodeBase64(VSBuffer.fromString(notebook.scheme), true, true)}`; + return notebook.with({ scheme, fragment }); } export function parse(cell: URI): { notebook: URI; handle: number } | undefined { if (cell.scheme !== scheme) { return undefined; } - const match = _regex.exec(cell.fragment); - if (!match) { + + const idx = cell.fragment.indexOf('s'); + if (idx < 0) { + return undefined; + } + + const handle = parseInt(cell.fragment.substring(0, idx).replace(_padRegexp, ''), _radix); + const _scheme = decodeBase64(cell.fragment.substring(idx + 1)).toString(); + + if (isNaN(handle)) { return undefined; } - const handle = Number(match[1]); return { handle, - notebook: cell.with({ - scheme: cell.fragment.substring(match[0].length) || Schemas.file, - fragment: null - }) + notebook: cell.with({ scheme: _scheme, fragment: null }) }; } + + const _regex = /^(\d{8,})(\w[\w\d+.-]*)$/; + export function generateCellOutputUri(notebook: URI, outputId?: string) { return notebook.with({ scheme: Schemas.vscodeNotebookCellOutput, |