From c208f24086e4660109b4a1617ef4d2cd86bdb852 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Tue, 6 Aug 2024 16:49:19 +1000 Subject: [PATCH 1/3] Hide unmodified cells in nb diff view (#224908) Hide unmodified notebook cells in diff view --- .../notebook/browser/diff/diffComponents.ts | 124 ++++++++++++------ .../browser/diff/diffElementViewModel.ts | 18 ++- .../notebook/browser/diff/notebookDiff.css | 7 + .../browser/diff/notebookDiffEditor.ts | 3 + .../browser/diff/notebookDiffEditorBrowser.ts | 3 + .../notebook/browser/diff/notebookDiffList.ts | 4 + 6 files changed, 117 insertions(+), 42 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts b/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts index 263d08b0c14f1..f70ad440b2ad8 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts @@ -239,6 +239,8 @@ abstract class AbstractElementRenderer extends Disposable { protected readonly _outputLocalDisposable = this._register(new DisposableStore()); protected _ignoreMetadata: boolean = false; protected _ignoreOutputs: boolean = false; + protected _cellHeaderContainer!: HTMLElement; + protected _cellHeader!: PropertyHeader; protected _metadataHeaderContainer!: HTMLElement; protected _metadataHeader!: PropertyHeader; protected _metadataInfoContainer!: HTMLElement; @@ -321,6 +323,9 @@ abstract class AbstractElementRenderer extends Disposable { this.styleContainer(this._diffEditorContainer); this.updateSourceEditor(); + if (this.cell.modified) { + this._register(this.cell.modified.textModel.onDidChangeContent(() => this._cellHeader.refresh())); + } this._ignoreMetadata = this.configurationService.getValue('notebook.diff.ignoreMetadata'); if (this._ignoreMetadata) { @@ -828,6 +833,7 @@ abstract class SingleSideDiffElement extends AbstractElementRenderer { _disposeMetadata() { this.cell.metadataStatusHeight = 0; this.cell.metadataHeight = 0; + this.templateData.cellHeaderContainer.style.display = 'none'; this.templateData.metadataHeaderContainer.style.display = 'none'; this.templateData.metadataInfoContainer.style.display = 'none'; this._metadataEditor = undefined; @@ -1221,7 +1227,6 @@ export class ModifiedElement extends AbstractElementRenderer { private _editor?: DiffEditorWidget; private _editorViewStateChanged: boolean; private _editorContainer!: HTMLElement; - private _inputToolbarContainer!: HTMLElement; protected _toolbar!: ToolBar; protected _menu!: IMenu; @@ -1491,63 +1496,100 @@ export class ModifiedElement extends AbstractElementRenderer { } updateSourceEditor(): void { + this._cellHeaderContainer = this.templateData.cellHeaderContainer; + this._cellHeaderContainer.style.display = 'flex'; + this._cellHeaderContainer.innerText = ''; const modifiedCell = this.cell.modified; - const lineCount = modifiedCell.textModel.textBuffer.getLineCount(); - const lineHeight = this.notebookEditor.getLayoutInfo().fontInfo.lineHeight || 17; - - const editorHeight = this.cell.layoutInfo.editorHeight !== 0 ? this.cell.layoutInfo.editorHeight : lineCount * lineHeight + fixedEditorPadding.top + fixedEditorPadding.bottom; this._editorContainer = this.templateData.editorContainer; - this._editor = this.templateData.sourceEditor; - this._editorContainer.classList.add('diff'); - this._editor.layout({ - width: this.notebookEditor.getLayoutInfo().width - 2 * DIFF_CELL_MARGIN, - height: editorHeight - }); + const renderSourceEditor = () => { + if (this.cell.cellFoldingState === PropertyFoldingState.Collapsed) { + this._editorContainer.style.display = 'none'; + this.cell.editorHeight = 0; + return; + } - this._editorContainer.style.height = `${editorHeight}px`; + const lineCount = modifiedCell.textModel.textBuffer.getLineCount(); + const lineHeight = this.notebookEditor.getLayoutInfo().fontInfo.lineHeight || 17; + const editorHeight = this.cell.layoutInfo.editorHeight !== 0 ? this.cell.layoutInfo.editorHeight : (lineCount * lineHeight) + fixedEditorPadding.top + fixedEditorPadding.bottom; - this._register(this._editor.onDidContentSizeChange((e) => { - if (e.contentHeightChanged && this.cell.layoutInfo.editorHeight !== e.contentHeight) { - this.cell.editorHeight = e.contentHeight; + this._editorContainer.style.height = `${editorHeight}px`; + this._editorContainer.style.display = 'block'; + + if (this._editor) { + const contentHeight = this._editor.getContentHeight(); + if (contentHeight >= 0) { + this.cell.editorHeight = contentHeight; + } + return; } - })); - this._initializeSourceDiffEditor(); - const scopedContextKeyService = this.contextKeyService.createScoped(this.templateData.inputToolbarContainer); + this._editor = this.templateData.sourceEditor; + this._editor.layout({ + width: this.notebookEditor.getLayoutInfo().width - 2 * DIFF_CELL_MARGIN, + height: editorHeight + }); + this._register(this._editor.onDidContentSizeChange((e) => { + if (this.cell.cellFoldingState === PropertyFoldingState.Expanded && e.contentHeightChanged && this.cell.layoutInfo.editorHeight !== e.contentHeight) { + this.cell.editorHeight = e.contentHeight; + } + })); + this._initializeSourceDiffEditor(); + }; + + this._cellHeader = this._register(this.instantiationService.createInstance( + PropertyHeader, + this.cell, + this._cellHeaderContainer, + this.notebookEditor, + { + updateInfoRendering: () => renderSourceEditor(), + checkIfModified: (cell) => { + return cell.modified?.textModel.getValue() !== cell.original?.textModel.getValue() ? { reason: undefined } : false; + }, + getFoldingState: (cell) => cell.cellFoldingState, + updateFoldingState: (cell, state) => cell.cellFoldingState = state, + unChangedLabel: 'Cell', + changedLabel: 'Cell changed', + prefix: 'cell', + menuId: MenuId.NotebookDiffCellInputTitle + } + )); + this._cellHeader.buildHeader(); + renderSourceEditor(); + + const scopedContextKeyService = this.contextKeyService.createScoped(this._cellHeaderContainer); this._register(scopedContextKeyService); const inputChanged = NOTEBOOK_DIFF_CELL_INPUT.bindTo(scopedContextKeyService); + inputChanged.set(this.cell.modified.textModel.getValue() !== this.cell.original.textModel.getValue()); - this._inputToolbarContainer = this.templateData.inputToolbarContainer; this._toolbar = this.templateData.toolbar; this._toolbar.context = { cell: this.cell }; - if (this.cell.modified.textModel.getValue() !== this.cell.original.textModel.getValue()) { - this._inputToolbarContainer.style.display = 'block'; - inputChanged.set(true); - } else { - this._inputToolbarContainer.style.display = 'none'; - inputChanged.set(false); - } + const actions: IAction[] = []; + + const refreshToolbar = () => { + const hasChanges = this.cell.modified.textModel.getValue() !== this.cell.original.textModel.getValue(); + inputChanged.set(hasChanges); + + if (!actions.length) { + const menu = this.menuService.getMenuActions(MenuId.NotebookDiffCellInputTitle, scopedContextKeyService, { shouldForwardArgs: true }); + createAndFillInActionBarActions(menu, actions); + } - this._register(this.cell.modified.textModel.onDidChangeContent(() => { - if (this.cell.modified.textModel.getValue() !== this.cell.original.textModel.getValue()) { - this._inputToolbarContainer.style.display = 'block'; - inputChanged.set(true); + if (hasChanges) { + this._toolbar.setActions(actions); } else { - this._inputToolbarContainer.style.display = 'none'; - inputChanged.set(false); + this._toolbar.setActions([]); } - })); + }; - const menu = this.menuService.getMenuActions(MenuId.NotebookDiffCellInputTitle, scopedContextKeyService, { shouldForwardArgs: true }); - const actions: IAction[] = []; - createAndFillInActionBarActions(menu, actions); - this._toolbar.setActions(actions); + this._register(this.cell.modified.textModel.onDidChangeContent(() => refreshToolbar())); + refreshToolbar(); } private async _initializeSourceDiffEditor() { @@ -1597,17 +1639,17 @@ export class ModifiedElement extends AbstractElementRenderer { layout(state: IDiffElementLayoutState) { DOM.scheduleAtNextAnimationFrame(DOM.getWindow(this._diffEditorContainer), () => { - if (state.editorHeight) { + if (state.editorHeight && this._editor) { this._editorContainer.style.height = `${this.cell.layoutInfo.editorHeight}px`; - this._editor!.layout({ + this._editor.layout({ width: this._editor!.getViewWidth(), height: this.cell.layoutInfo.editorHeight }); } - if (state.outerWidth) { + if (state.outerWidth && this._editor) { this._editorContainer.style.height = `${this.cell.layoutInfo.editorHeight}px`; - this._editor!.layout(); + this._editor.layout(); } if (state.metadataHeight || state.outerWidth) { diff --git a/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.ts b/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.ts index fd3336fc32b20..52617b470fc1a 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.ts @@ -34,6 +34,7 @@ interface ILayoutInfoDelta extends ILayoutInfoDelta0 { } export abstract class DiffElementViewModelBase extends Disposable { + public cellFoldingState: PropertyFoldingState; public metadataFoldingState: PropertyFoldingState; public outputFoldingState: PropertyFoldingState; protected _layoutInfoEmitter = this._register(new Emitter()); @@ -132,21 +133,24 @@ export abstract class DiffElementViewModelBase extends Disposable { ) { super(); const editorHeight = this._estimateEditorHeight(initData.fontInfo); + const cellStatusHeight = 25; this._layoutInfo = { width: 0, editorHeight: editorHeight, editorMargin: 0, metadataHeight: 0, + cellStatusHeight, metadataStatusHeight: 25, rawOutputHeight: 0, outputTotalHeight: 0, outputStatusHeight: 25, outputMetadataHeight: 0, bodyMargin: 32, - totalHeight: 82 + editorHeight, + totalHeight: 82 + cellStatusHeight + editorHeight, layoutState: CellLayoutState.Uninitialized }; + this.cellFoldingState = modified?.textModel?.getValue() !== original?.textModel?.getValue() ? PropertyFoldingState.Expanded : PropertyFoldingState.Collapsed; this.metadataFoldingState = PropertyFoldingState.Collapsed; this.outputFoldingState = PropertyFoldingState.Collapsed; @@ -185,6 +189,7 @@ export abstract class DiffElementViewModelBase extends Disposable { const editorHeight = delta.editorHeight !== undefined ? delta.editorHeight : this._layoutInfo.editorHeight; const editorMargin = delta.editorMargin !== undefined ? delta.editorMargin : this._layoutInfo.editorMargin; const metadataHeight = delta.metadataHeight !== undefined ? delta.metadataHeight : this._layoutInfo.metadataHeight; + const cellStatusHeight = delta.cellStatusHeight !== undefined ? delta.cellStatusHeight : this._layoutInfo.cellStatusHeight; const metadataStatusHeight = delta.metadataStatusHeight !== undefined ? delta.metadataStatusHeight : this._layoutInfo.metadataStatusHeight; const rawOutputHeight = delta.rawOutputHeight !== undefined ? delta.rawOutputHeight : this._layoutInfo.rawOutputHeight; const outputStatusHeight = delta.outputStatusHeight !== undefined ? delta.outputStatusHeight : this._layoutInfo.outputStatusHeight; @@ -194,6 +199,7 @@ export abstract class DiffElementViewModelBase extends Disposable { const totalHeight = editorHeight + editorMargin + + cellStatusHeight + metadataHeight + metadataStatusHeight + outputHeight @@ -205,6 +211,7 @@ export abstract class DiffElementViewModelBase extends Disposable { editorHeight: editorHeight, editorMargin: editorMargin, metadataHeight: metadataHeight, + cellStatusHeight, metadataStatusHeight: metadataStatusHeight, outputTotalHeight: outputHeight, outputStatusHeight: outputStatusHeight, @@ -239,6 +246,11 @@ export abstract class DiffElementViewModelBase extends Disposable { somethingChanged = true; } + if (newLayout.cellStatusHeight !== this._layoutInfo.cellStatusHeight) { + changeEvent.cellStatusHeight = true; + somethingChanged = true; + } + if (newLayout.metadataStatusHeight !== this._layoutInfo.metadataStatusHeight) { changeEvent.metadataStatusHeight = true; somethingChanged = true; @@ -288,6 +300,7 @@ export abstract class DiffElementViewModelBase extends Disposable { const totalHeight = editorHeight + this._layoutInfo.editorMargin + this._layoutInfo.metadataHeight + + this._layoutInfo.cellStatusHeight + this._layoutInfo.metadataStatusHeight + this._layoutInfo.outputTotalHeight + this._layoutInfo.outputStatusHeight @@ -410,6 +423,7 @@ export class SideBySideDiffElementViewModel extends DiffElementViewModelBase { this.modified = modified; this.type = type; + this.cellFoldingState = modified.textModel.getValue() !== original.textModel.getValue() ? PropertyFoldingState.Expanded : PropertyFoldingState.Collapsed; this.metadataFoldingState = PropertyFoldingState.Collapsed; this.outputFoldingState = PropertyFoldingState.Collapsed; @@ -491,6 +505,7 @@ export class SideBySideDiffElementViewModel extends DiffElementViewModelBase { return this._layoutInfo.editorHeight + this._layoutInfo.editorMargin + this._layoutInfo.metadataHeight + + this._layoutInfo.cellStatusHeight + this._layoutInfo.metadataStatusHeight + this._layoutInfo.outputStatusHeight + this._layoutInfo.bodyMargin / 2 @@ -599,6 +614,7 @@ export class SingleSideDiffElementViewModel extends DiffElementViewModelBase { return this._layoutInfo.editorHeight + this._layoutInfo.editorMargin + this._layoutInfo.metadataHeight + + this._layoutInfo.cellStatusHeight + this._layoutInfo.metadataStatusHeight + this._layoutInfo.outputStatusHeight + this._layoutInfo.bodyMargin / 2 diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css index a0a89a75d844c..40de8285bcac7 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css @@ -99,6 +99,7 @@ width: 50%; } +.notebook-text-diff-editor .cell-diff-editor-container .cell-header-container, .notebook-text-diff-editor .cell-diff-editor-container .output-header-container, .notebook-text-diff-editor .cell-diff-editor-container .metadata-header-container { display: flex; @@ -107,6 +108,7 @@ cursor: default; } +.notebook-text-diff-editor .cell-diff-editor-container .cell-header-container .property-folding-indicator .codicon, .notebook-text-diff-editor .cell-diff-editor-container .output-header-container .property-folding-indicator .codicon, .notebook-text-diff-editor .cell-diff-editor-container .metadata-header-container .property-folding-indicator .codicon { visibility: visible; @@ -114,6 +116,7 @@ cursor: pointer; } +.notebook-text-diff-editor .cell-diff-editor-container .cell-header-container, .notebook-text-diff-editor .cell-diff-editor-container .output-header-container, .notebook-text-diff-editor .cell-diff-editor-container .metadata-header-container { display: flex; @@ -121,22 +124,26 @@ align-items: center; } +.notebook-text-diff-editor .cell-diff-editor-container .cell-header-container .property-toolbar, .notebook-text-diff-editor .cell-diff-editor-container .output-header-container .property-toolbar, .notebook-text-diff-editor .cell-diff-editor-container .metadata-header-container .property-toolbar { margin-left: auto; } +.notebook-text-diff-editor .cell-diff-editor-container .cell-header-container .property-status, .notebook-text-diff-editor .cell-diff-editor-container .output-header-container .property-status, .notebook-text-diff-editor .cell-diff-editor-container .metadata-header-container .property-status { font-size: 12px; } +.notebook-text-diff-editor .cell-diff-editor-container .cell-header-container .property-status span, .notebook-text-diff-editor .cell-diff-editor-container .output-header-container .property-status span, .notebook-text-diff-editor .cell-diff-editor-container .metadata-header-container .property-status span { margin: 0 0 0 8px; line-height: 21px; } +.notebook-text-diff-editor .cell-diff-editor-container .cell-header-container .property-status span.property-description, .notebook-text-diff-editor .cell-diff-editor-container .output-header-container .property-status span.property-description, .notebook-text-diff-editor .cell-diff-editor-container .metadata-header-container .property-status span.property-description { font-style: italic; diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts index dd98ad9d3a4ba..590b3c0482690 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts @@ -334,6 +334,9 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD this._register(this._list.onMouseUp(e => { if (e.element) { + if (typeof e.index === 'number') { + this._list.setFocus([e.index]); + } this._onMouseUp.fire({ event: e.browserEvent, target: e.element }); } })); diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.ts index 031c2afdc7f31..1fd8eb929cad3 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.ts @@ -72,6 +72,7 @@ export interface CellDiffSingleSideRenderTemplate extends CellDiffCommonRenderTe readonly diffEditorContainer: HTMLElement; readonly diagonalFill: HTMLElement; readonly elementDisposables: DisposableStore; + readonly cellHeaderContainer: HTMLElement; readonly sourceEditor: CodeEditorWidget; readonly metadataHeaderContainer: HTMLElement; readonly metadataInfoContainer: HTMLElement; @@ -85,6 +86,7 @@ export interface CellDiffSideBySideRenderTemplate extends CellDiffCommonRenderTe readonly body: HTMLElement; readonly diffEditorContainer: HTMLElement; readonly elementDisposables: DisposableStore; + readonly cellHeaderContainer: HTMLElement; readonly sourceEditor: DiffEditorWidget; readonly editorContainer: HTMLElement; readonly inputToolbarContainer: HTMLElement; @@ -101,6 +103,7 @@ export interface IDiffElementLayoutInfo { editorHeight: number; editorMargin: number; metadataHeight: number; + cellStatusHeight: number; metadataStatusHeight: number; rawOutputHeight: number; outputMetadataHeight: number; diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.ts index a3cfecd2a6f6d..e2edb9b1b2701 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.ts @@ -82,6 +82,7 @@ export class CellDiffSingleSideRenderer implements IListRenderer Date: Tue, 6 Aug 2024 17:53:22 +1000 Subject: [PATCH 2/3] Support for inline diffing of notebook cells with hiding of unchanged lines (#224917) * Hide unmodified notebook cells in diff view * Inline diff nb view with ability to hide unmodified lines in cell --- .../browser/diff/diffCellEditorOptions.ts | 3 +- .../notebook/browser/diff/diffComponents.ts | 50 ++++++++++++++++++- .../browser/diff/notebookDiffActions.ts | 31 ++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.ts b/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.ts index c2b1d9cf2524d..cc1137f6a7e3b 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.ts @@ -29,8 +29,7 @@ export const fixedEditorOptions: IEditorOptions = { selectOnLineNumbers: false, wordWrap: 'off', lineNumbers: 'off', - lineDecorationsWidth: 0, - glyphMargin: false, + glyphMargin: true, fixedOverflowWidgets: true, minimap: { enabled: false }, renderValidationDecorations: 'on', diff --git a/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts b/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts index f70ad440b2ad8..04488e0f8f67e 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as DOM from 'vs/base/browser/dom'; -import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; +import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle'; import { Schemas } from 'vs/base/common/network'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { DiffElementViewModelBase, getFormattedMetadataJSON, getFormattedOutputJSON, OutputComparison, outputEqual, OUTPUT_EDITOR_HEIGHT_MAGIC, PropertyFoldingState, SideBySideDiffElementViewModel, SingleSideDiffElementViewModel } from 'vs/workbench/contrib/notebook/browser/diff/diffElementViewModel'; @@ -515,6 +515,8 @@ abstract class AbstractElementRenderer extends Disposable { originalEditor: getOptimizedNestedCodeEditorWidgetOptions(), modifiedEditor: getOptimizedNestedCodeEditorWidgetOptions() }); + + this._metadataEditorDisposeStore.add(this.updateEditorOptions(this._metadataEditor!, ['renderSideBySide', 'useInlineViewWhenSpaceIsLimited'])); this.layout({ metadataHeight: true }); this._metadataEditorDisposeStore.add(this._metadataEditor); @@ -628,6 +630,7 @@ abstract class AbstractElementRenderer extends Disposable { originalEditor: getOptimizedNestedCodeEditorWidgetOptions(), modifiedEditor: getOptimizedNestedCodeEditorWidgetOptions() }); + this._outputEditorDisposeStore.add(this.updateEditorOptions(this._outputEditor!, ['renderSideBySide', 'useInlineViewWhenSpaceIsLimited'])); this._outputEditorDisposeStore.add(this._outputEditor); this._outputEditorContainer?.classList.add('diff'); @@ -718,6 +721,46 @@ abstract class AbstractElementRenderer extends Disposable { abstract updateSourceEditor(): void; abstract layout(state: IDiffElementLayoutState): void; + + protected updateEditorOptions(editor: DiffEditorWidget, optionsToUpdate: ('hideUnchangedRegions' | 'renderSideBySide' | 'useInlineViewWhenSpaceIsLimited')[]): IDisposable { + if (!optionsToUpdate.length) { + return Disposable.None; + } + + const options: { + renderSideBySide?: boolean; + useInlineViewWhenSpaceIsLimited?: boolean; + hideUnchangedRegions?: { enabled: boolean }; + } = {}; + + if (optionsToUpdate.includes('renderSideBySide')) { + options.renderSideBySide = this.configurationService.getValue('diffEditor.renderSideBySide'); + } + if (optionsToUpdate.includes('hideUnchangedRegions')) { + const enabled = this.configurationService.getValue('diffEditor.hideUnchangedRegions.enabled'); + options.hideUnchangedRegions = { enabled }; + } + if (optionsToUpdate.includes('useInlineViewWhenSpaceIsLimited')) { + options.useInlineViewWhenSpaceIsLimited = this.configurationService.getValue('diffEditor.useInlineViewWhenSpaceIsLimited'); + } + + editor.updateOptions(options); + + return this.configurationService.onDidChangeConfiguration(e => { + if (e.affectsConfiguration('diffEditor.hideUnchangedRegions.enabled')) { + const enabled = this.configurationService.getValue('diffEditor.hideUnchangedRegions.enabled'); + editor.updateOptions({ hideUnchangedRegions: { enabled } }); + } + if (e.affectsConfiguration('diffEditor.renderSideBySide')) { + const renderSideBySide = this.configurationService.getValue('diffEditor.renderSideBySide'); + editor.updateOptions({ renderSideBySide }); + } + if (e.affectsConfiguration('diffEditor.useInlineViewWhenSpaceIsLimited')) { + const useInlineViewWhenSpaceIsLimited = this.configurationService.getValue('diffEditor.useInlineViewWhenSpaceIsLimited'); + editor.updateOptions({ useInlineViewWhenSpaceIsLimited }); + } + }); + } } abstract class SingleSideDiffElement extends AbstractElementRenderer { @@ -755,7 +798,7 @@ abstract class SingleSideDiffElement extends AbstractElementRenderer { notificationService, menuService, contextKeyService, - configurationService + configurationService, ); this.cell = cell; this.templateData = templateData; @@ -1441,6 +1484,8 @@ export class ModifiedElement extends AbstractElementRenderer { originalEditor: getOptimizedNestedCodeEditorWidgetOptions(), modifiedEditor: getOptimizedNestedCodeEditorWidgetOptions() }); + + this._register(this.updateEditorOptions(this._outputMetadataEditor, ['renderSideBySide', 'useInlineViewWhenSpaceIsLimited'])); this._register(this._outputMetadataEditor); const originalOutputMetadataSource = JSON.stringify(this.cell.original.outputs[0].metadata ?? {}, undefined, '\t'); const modifiedOutputMetadataSource = JSON.stringify(this.cell.modified.outputs[0].metadata ?? {}, undefined, '\t'); @@ -1623,6 +1668,7 @@ export class ModifiedElement extends AbstractElementRenderer { } }; + this._register(this.updateEditorOptions(this._editor!, ['hideUnchangedRegions', 'renderSideBySide', 'useInlineViewWhenSpaceIsLimited'])); this._register(this._editor!.getOriginalEditor().onDidChangeCursorSelection(handleViewStateChange)); this._register(this._editor!.getOriginalEditor().onDidScrollChange(handleScrollChange)); this._register(this._editor!.getModifiedEditor().onDidChangeCursorSelection(handleViewStateChange)); diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts index f7cfcf23fec84..d1ea8b55dd018 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts @@ -62,6 +62,37 @@ registerAction2(class extends Action2 { } }); +registerAction2(class extends Action2 { + constructor() { + super({ + id: 'notebook.toggle.diff.renderSideBySide', + title: localize('inlineView', "Inline View"), + toggled: ContextKeyExpr.equals('config.diffEditor.renderSideBySide', false), + precondition: ActiveEditorContext.isEqualTo(NotebookTextDiffEditor.ID), + menu: [{ + id: MenuId.EditorTitle, + order: 0, + group: '1_diff', + when: ActiveEditorContext.isEqualTo(NotebookTextDiffEditor.ID) + }] + }); + } + + async run(accessor: ServicesAccessor): Promise { + const editorService = accessor.get(IEditorService); + const activeEditor = editorService.activeEditorPane; + if (activeEditor && activeEditor instanceof NotebookTextDiffEditor) { + const diffEditorInput = activeEditor.input as NotebookDiffEditorInput; + if (diffEditorInput.resource) { + const configurationService = accessor.get(IConfigurationService); + + const oldValue = configurationService.getValue('diffEditor.renderSideBySide'); + configurationService.updateValue('diffEditor.renderSideBySide', !oldValue); + } + } + } +}); + registerAction2(class extends Action2 { constructor() { super( From c23e35103f1255c2a2037d261aab081c474d705a Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Tue, 6 Aug 2024 10:55:35 +0200 Subject: [PATCH 3/3] BUILD: skip "check object leaks" test (#224923) --- test/smoke/src/areas/notebook/notebook.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/smoke/src/areas/notebook/notebook.test.ts b/test/smoke/src/areas/notebook/notebook.test.ts index da4d527fe4fb4..130b49a1473ae 100644 --- a/test/smoke/src/areas/notebook/notebook.test.ts +++ b/test/smoke/src/areas/notebook/notebook.test.ts @@ -34,7 +34,7 @@ export function setup(logger: Logger) { }); }); - it('check object leaks', async function () { + it.skip('check object leaks', async function () { const app = this.app as Application; await app.profiler.checkObjectLeaks(['NotebookTextModel', 'NotebookCellTextModel', 'NotebookEventDispatcher'], async () => { await app.workbench.notebook.openNotebook();