From d24ad98e3143a08605a5e2171b4ecbf03340c188 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 19 Feb 2021 17:01:31 -0800 Subject: [PATCH] Convert to switch/case This makes the logic more clear --- .../view/renderers/backLayerWebView.ts | 195 +++++++++++------- 1 file changed, 121 insertions(+), 74 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts index 607c59dd4bc..d64a6c6df63 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts @@ -755,97 +755,144 @@ var requirejs = (function() { return; } - if (data.__vscode_notebook_message) { - if (data.type === 'dimension') { - if (data.isOutput) { - const height = data.data.height; - const outputHeight = height; + if (!data.__vscode_notebook_message) { + this._onMessage.fire({ message: data }); + return; + } + switch (data.type) { + case 'dimension': + { + if (data.isOutput) { + const height = data.data.height; + const outputHeight = height; + + const resolvedResult = this.resolveOutputId(data.id); + if (resolvedResult) { + const { cellInfo, output } = resolvedResult; + this.notebookEditor.updateOutputHeight(cellInfo, output, outputHeight, !!data.init); + } + } else { + const cellId = data.id.substr(0, data.id.length - '_preview'.length); + this.notebookEditor.updateMarkdownCellHeight(cellId, data.data.height, !!data.init); + } + break; + } + case 'mouseenter': + { const resolvedResult = this.resolveOutputId(data.id); if (resolvedResult) { - const { cellInfo, output } = resolvedResult; - this.notebookEditor.updateOutputHeight(cellInfo, output, outputHeight, !!data.init); + const latestCell = this.notebookEditor.getCellByInfo(resolvedResult.cellInfo); + if (latestCell) { + latestCell.outputIsHovered = true; + } } - } else { - const cellId = data.id.substr(0, data.id.length - '_preview'.length); - this.notebookEditor.updateMarkdownCellHeight(cellId, data.data.height, !!data.init); + break; } - } else if (data.type === 'mouseenter') { - const resolvedResult = this.resolveOutputId(data.id); - if (resolvedResult) { - const latestCell = this.notebookEditor.getCellByInfo(resolvedResult.cellInfo); - if (latestCell) { - latestCell.outputIsHovered = true; + case 'mouseleave': + { + const resolvedResult = this.resolveOutputId(data.id); + if (resolvedResult) { + const latestCell = this.notebookEditor.getCellByInfo(resolvedResult.cellInfo); + if (latestCell) { + latestCell.outputIsHovered = false; + } } + break; + } + case 'scroll-ack': + { + // const date = new Date(); + // const top = data.data.top; + // console.log('ack top ', top, ' version: ', data.version, ' - ', date.getMinutes() + ':' + date.getSeconds() + ':' + date.getMilliseconds()); + break; + } + case 'did-scroll-wheel': + { + this.notebookEditor.triggerScroll({ + ...data.payload, + preventDefault: () => { }, + stopPropagation: () => { } + }); + break; } - } else if (data.type === 'mouseleave') { - const resolvedResult = this.resolveOutputId(data.id); - if (resolvedResult) { - const latestCell = this.notebookEditor.getCellByInfo(resolvedResult.cellInfo); - if (latestCell) { - latestCell.outputIsHovered = false; + case 'focus-editor': + { + const resolvedResult = this.resolveOutputId(data.id); + if (resolvedResult) { + const latestCell = this.notebookEditor.getCellByInfo(resolvedResult.cellInfo); + if (!latestCell) { + return; + } + + if (data.focusNext) { + this.notebookEditor.focusNextNotebookCell(latestCell, 'editor'); + } else { + this.notebookEditor.focusNotebookCell(latestCell, 'editor'); + } } + break; } - } else if (data.type === 'scroll-ack') { - // const date = new Date(); - // const top = data.data.top; - // console.log('ack top ', top, ' version: ', data.version, ' - ', date.getMinutes() + ':' + date.getSeconds() + ':' + date.getMilliseconds()); - } else if (data.type === 'did-scroll-wheel') { - this.notebookEditor.triggerScroll({ - ...data.payload, - preventDefault: () => { }, - stopPropagation: () => { } - }); - } else if (data.type === 'focus-editor') { - const resolvedResult = this.resolveOutputId(data.id); - if (resolvedResult) { - const latestCell = this.notebookEditor.getCellByInfo(resolvedResult.cellInfo); - if (!latestCell) { - return; + case 'clicked-data-url': + { + this._onDidClickDataLink(data); + break; + } + case 'customRendererMessage': + { + this._onMessage.fire({ message: data.message, forRenderer: data.rendererId }); + break; + } + case 'focusMarkdownPreview': + { + const cell = this.notebookEditor.getCellById(data.cellId); + if (cell) { + this.notebookEditor.focusNotebookCell(cell, 'container'); } - - if (data.focusNext) { - this.notebookEditor.focusNextNotebookCell(latestCell, 'editor'); - } else { - this.notebookEditor.focusNotebookCell(latestCell, 'editor'); + break; + } + case 'toggleMarkdownPreview': + { + this.notebookEditor.setMarkdownCellEditState(data.cellId, CellEditState.Editing); + break; + } + case 'mouseEnterMarkdownPreview': + { + const cell = this.notebookEditor.getCellById(data.cellId); + if (cell instanceof MarkdownCellViewModel) { + cell.cellIsHovered = true; } + break; } - } else if (data.type === 'clicked-data-url') { - this._onDidClickDataLink(data); - } else if (data.type === 'customRendererMessage') { - this._onMessage.fire({ message: data.message, forRenderer: data.rendererId }); - } else if (data.type === 'focusMarkdownPreview') { - const cell = this.notebookEditor.getCellById(data.cellId); - if (cell) { - this.notebookEditor.focusNotebookCell(cell, 'container'); + case 'mouseLeaveMarkdownPreview': + { + const cell = this.notebookEditor.getCellById(data.cellId); + if (cell instanceof MarkdownCellViewModel) { + cell.cellIsHovered = false; + } + break; } - } else if (data.type === 'toggleMarkdownPreview') { - this.notebookEditor.setMarkdownCellEditState(data.cellId, CellEditState.Editing); - } else if (data.type === 'mouseEnterMarkdownPreview') { - const cell = this.notebookEditor.getCellById(data.cellId); - if (cell instanceof MarkdownCellViewModel) { - cell.cellIsHovered = true; + case 'cell-drag-start': + { + this.notebookEditor.markdownCellDragStart(data.cellId, data.position); + break; } - } else if (data.type === 'mouseLeaveMarkdownPreview') { - const cell = this.notebookEditor.getCellById(data.cellId); - if (cell instanceof MarkdownCellViewModel) { - cell.cellIsHovered = false; + case 'cell-drag': + { + this.notebookEditor.markdownCellDrag(data.cellId, data.position); + break; + } + case 'cell-drag-end': + { + this.notebookEditor.markdownCellDragEnd(data.cellId, { + clientY: data.position.clientY, + ctrlKey: data.ctrlKey, + altKey: data.altKey, + }); + break; } - } else if (data.type === 'cell-drag-start') { - this.notebookEditor.markdownCellDragStart(data.cellId, data.position); - } else if (data.type === 'cell-drag') { - this.notebookEditor.markdownCellDrag(data.cellId, data.position); - } else if (data.type === 'cell-drag-end') { - this.notebookEditor.markdownCellDragEnd(data.cellId, { - clientY: data.position.clientY, - ctrlKey: data.ctrlKey, - altKey: data.altKey, - }); - } - return; } - this._onMessage.fire({ message: data }); })); } -- GitLab