Skip to content

Commit

Permalink
fix #99152
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jun 3, 2020
1 parent b3361d1 commit ceb87a1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/vs/workbench/contrib/notebook/common/notebookCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,26 +385,28 @@ export interface NotebookDataDto {
export namespace CellUri {

export const scheme = 'vscode-notebook-cell';
const _regex = /^\d{7,}/;

export function generate(notebook: URI, handle: number): URI {
return notebook.with({
scheme,
fragment: `${handle}${notebook.scheme !== Schemas.file ? notebook.scheme : ''}`
fragment: `${handle.toString().padStart(7, '0')}${notebook.scheme !== Schemas.file ? notebook.scheme : ''}`
});
}

export function parse(cell: URI): { notebook: URI, handle: number } | undefined {
if (cell.scheme !== scheme) {
return undefined;
}
const handle = parseInt(cell.fragment);
if (isNaN(handle)) {
const match = _regex.exec(cell.fragment);
if (!match) {
return undefined;
}
const handle = Number(match[0]);
return {
handle,
notebook: cell.with({
scheme: cell.fragment.substr(handle.toString().length) || Schemas.file,
scheme: cell.fragment.substr(match[0].length) || Schemas.file,
fragment: null
})
};
Expand Down

0 comments on commit ceb87a1

Please sign in to comment.