From e0e970f76bc3746d159cefaef3b02b7ce7e18cb7 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Mon, 4 Sep 2023 22:45:27 +0200 Subject: [PATCH] Removes legacy diff editor. (#191989) * Removes legacy diff editor. * Fixes CI * Fixes CI --- .vscode/settings.json | 1 - build/monaco/monaco.d.ts.recipe | 1 - .../editor/browser/widget/diffEditorWidget.ts | 2802 ----------------- .../diffEditorWidget2/accessibleDiffViewer.ts | 12 +- .../diffEditorWidget2/diffEditorEditors.ts | 2 +- .../diffEditorWidget2/diffEditorWidget2.ts | 12 +- .../widget/diffEditorWidget2/renderLines.ts | 4 +- src/vs/editor/browser/widget/diffNavigator.ts | 278 -- src/vs/editor/browser/widget/diffReview.ts | 826 ----- .../widget/embeddedCodeEditorWidget.ts | 63 +- .../config/editorConfigurationSchema.ts | 16 +- src/vs/editor/editor.all.ts | 3 +- .../browser/standaloneCodeEditor.ts | 77 - .../standalone/browser/standaloneEditor.ts | 20 +- src/vs/monaco.d.ts | 15 - .../browser/parts/editor/textDiffEditor.ts | 22 +- .../codeEditor/browser/diffEditorHelper.ts | 4 +- .../notebook/browser/diff/diffComponents.ts | 16 +- .../browser/diff/diffElementViewModel.ts | 6 +- .../browser/diff/notebookDiffEditorBrowser.ts | 4 +- .../notebook/browser/diff/notebookDiffList.ts | 4 +- .../contrib/scm/browser/dirtydiffDecorator.ts | 8 +- 22 files changed, 57 insertions(+), 4139 deletions(-) delete mode 100644 src/vs/editor/browser/widget/diffEditorWidget.ts delete mode 100644 src/vs/editor/browser/widget/diffNavigator.ts delete mode 100644 src/vs/editor/browser/widget/diffReview.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 7eefe0c57f6..6925e3ed8c6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -151,5 +151,4 @@ "application.experimental.rendererProfiling": true, "editor.experimental.asyncTokenization": true, "editor.experimental.asyncTokenizationVerification": true, - "diffEditor.experimental.useVersion2": true, } diff --git a/build/monaco/monaco.d.ts.recipe b/build/monaco/monaco.d.ts.recipe index 759ba84e090..55efbe60085 100644 --- a/build/monaco/monaco.d.ts.recipe +++ b/build/monaco/monaco.d.ts.recipe @@ -89,7 +89,6 @@ declare namespace monaco { } declare namespace monaco.editor { -#include(vs/editor/browser/widget/diffNavigator): IDiffNavigator #includeAll(vs/editor/standalone/browser/standaloneEditor;languages.Token=>Token): #include(vs/editor/standalone/common/standaloneTheme): BuiltinTheme, IStandaloneThemeData, IColors #include(vs/editor/common/languages/supports/tokenization): ITokenThemeRule diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts deleted file mode 100644 index 47dba6865b7..00000000000 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ /dev/null @@ -1,2802 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as dom from 'vs/base/browser/dom'; -import { createFastDomNode, FastDomNode } from 'vs/base/browser/fastDomNode'; -import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent'; -import { createTrustedTypesPolicy } from 'vs/base/browser/trustedTypes'; -import { MOUSE_CURSOR_TEXT_CSS_CLASS_NAME } from 'vs/base/browser/ui/mouseCursor/mouseCursor'; -import { IBoundarySashes, ISashEvent, IVerticalSashLayoutProvider, Orientation, Sash, SashState } from 'vs/base/browser/ui/sash/sash'; -import * as assert from 'vs/base/common/assert'; -import { RunOnceScheduler } from 'vs/base/common/async'; -import { CancellationToken } from 'vs/base/common/cancellation'; -import { Codicon } from 'vs/base/common/codicons'; -import { Color } from 'vs/base/common/color'; -import { onUnexpectedError } from 'vs/base/common/errors'; -import { Emitter, Event } from 'vs/base/common/event'; -import { MarkdownString } from 'vs/base/common/htmlContent'; -import { Disposable } from 'vs/base/common/lifecycle'; -import { ThemeIcon } from 'vs/base/common/themables'; -import { Constants } from 'vs/base/common/uint'; -import { URI } from 'vs/base/common/uri'; -import 'vs/css!./media/diffEditor'; -import { applyFontInfo } from 'vs/editor/browser/config/domFontInfo'; -import { IEditorConstructionOptions } from 'vs/editor/browser/config/editorConfiguration'; -import { ElementSizeObserver } from 'vs/editor/browser/config/elementSizeObserver'; -import * as editorBrowser from 'vs/editor/browser/editorBrowser'; -import { EditorExtensionsRegistry, IDiffEditorContributionDescription } from 'vs/editor/browser/editorExtensions'; -import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; -import { StableEditorScrollState } from 'vs/editor/browser/stableEditorScroll'; -import { CodeEditorWidget, ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget'; -import { DiffNavigator } from 'vs/editor/browser/widget/diffNavigator'; -import { DiffReview } from 'vs/editor/browser/widget/diffReview'; -import { IDiffLinesChange, InlineDiffMargin } from 'vs/editor/browser/widget/inlineDiffMargin'; -import { WorkerBasedDocumentDiffProvider } from 'vs/editor/browser/widget/workerBasedDocumentDiffProvider'; -import { clampedFloat, clampedInt, EditorFontLigatures, EditorLayoutInfo, EditorOption, EditorOptions, IDiffEditorOptions, boolean as validateBooleanOption, stringSet as validateStringSetOption, ValidDiffEditorBaseOptions } from 'vs/editor/common/config/editorOptions'; -import { FontInfo } from 'vs/editor/common/config/fontInfo'; -import { IDimension } from 'vs/editor/common/core/dimension'; -import { IPosition, Position } from 'vs/editor/common/core/position'; -import { IRange, Range } from 'vs/editor/common/core/range'; -import { ISelection, Selection } from 'vs/editor/common/core/selection'; -import { StringBuilder } from 'vs/editor/common/core/stringBuilder'; -import { IChange, ICharChange, IDiffComputationResult, ILineChange } from 'vs/editor/common/diff/legacyLinesDiffComputer'; -import * as editorCommon from 'vs/editor/common/editorCommon'; -import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; -import { IModelDecorationsChangeAccessor, IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model'; -import { ModelDecorationOptions } from 'vs/editor/common/model/textModel'; -import { ILineBreaksComputer } from 'vs/editor/common/modelLineProjectionData'; -import { IViewLineTokens } from 'vs/editor/common/tokens/lineTokens'; -import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations'; -import { RenderLineInput, renderViewLine } from 'vs/editor/common/viewLayout/viewLineRenderer'; -import { IEditorWhitespace, InlineDecoration, InlineDecorationType, IViewModel, ViewLineRenderingData } from 'vs/editor/common/viewModel'; -import { OverviewRulerZone } from 'vs/editor/common/viewModel/overviewZoneManager'; -import * as nls from 'vs/nls'; -import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; -import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; -import { INotificationService } from 'vs/platform/notification/common/notification'; -import { IEditorProgressService, IProgressRunner } from 'vs/platform/progress/common/progress'; -import { defaultInsertColor, defaultRemoveColor, diffDiagonalFill, diffInserted, diffOverviewRulerInserted, diffOverviewRulerRemoved, diffRemoved } from 'vs/platform/theme/common/colorRegistry'; -import { registerIcon } from 'vs/platform/theme/common/iconRegistry'; -import { getThemeTypeSelector, IColorTheme, IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService'; - -export interface IDiffCodeEditorWidgetOptions { - originalEditor?: ICodeEditorWidgetOptions; - modifiedEditor?: ICodeEditorWidgetOptions; -} - -interface IEditorDiffDecorations { - decorations: IModelDeltaDecoration[]; - overviewZones: OverviewRulerZone[]; -} - -interface IEditorDiffDecorationsWithZones extends IEditorDiffDecorations { - zones: IMyViewZone[]; -} - -interface IEditorsDiffDecorationsWithZones { - original: IEditorDiffDecorationsWithZones; - modified: IEditorDiffDecorationsWithZones; -} - -interface IEditorsZones { - original: IMyViewZone[]; - modified: IMyViewZone[]; -} - -class VisualEditorState { - private _zones: string[]; - private _inlineDiffMargins: InlineDiffMargin[]; - private _zonesMap: { [zoneId: string]: boolean }; - private _decorations: string[]; - - constructor( - private _contextMenuService: IContextMenuService, - private _clipboardService: IClipboardService - ) { - this._zones = []; - this._inlineDiffMargins = []; - this._zonesMap = {}; - this._decorations = []; - } - - public getForeignViewZones(allViewZones: IEditorWhitespace[]): IEditorWhitespace[] { - return allViewZones.filter((z) => !this._zonesMap[String(z.id)]); - } - - public clean(editor: CodeEditorWidget): void { - // (1) View zones - if (this._zones.length > 0) { - editor.changeViewZones((viewChangeAccessor: editorBrowser.IViewZoneChangeAccessor) => { - for (const zoneId of this._zones) { - viewChangeAccessor.removeZone(zoneId); - } - }); - } - this._zones = []; - this._zonesMap = {}; - - // (2) Model decorations - editor.changeDecorations((changeAccessor) => { - this._decorations = changeAccessor.deltaDecorations(this._decorations, []); - }); - } - - public apply(editor: CodeEditorWidget, overviewRuler: editorBrowser.IOverviewRuler | null, newDecorations: IEditorDiffDecorationsWithZones, restoreScrollState: boolean): void { - - const scrollState = restoreScrollState ? StableEditorScrollState.capture(editor) : null; - - // view zones - editor.changeViewZones((viewChangeAccessor: editorBrowser.IViewZoneChangeAccessor) => { - for (const zoneId of this._zones) { - viewChangeAccessor.removeZone(zoneId); - } - for (const inlineDiffMargin of this._inlineDiffMargins) { - inlineDiffMargin.dispose(); - } - this._zones = []; - this._zonesMap = {}; - this._inlineDiffMargins = []; - for (let i = 0, length = newDecorations.zones.length; i < length; i++) { - const viewZone = newDecorations.zones[i]; - viewZone.suppressMouseDown = true; - viewZone.showInHiddenAreas = true; - const zoneId = viewChangeAccessor.addZone(viewZone); - this._zones.push(zoneId); - this._zonesMap[String(zoneId)] = true; - - if (newDecorations.zones[i].diff && viewZone.marginDomNode) { - viewZone.suppressMouseDown = false; - if (newDecorations.zones[i].diff?.originalModel.getValueLength() !== 0) { - // do not contribute diff margin actions for newly created files - this._inlineDiffMargins.push(new InlineDiffMargin(zoneId, viewZone.marginDomNode, editor, newDecorations.zones[i].diff!, this._contextMenuService, this._clipboardService)); - } - } - } - }); - - scrollState?.restore(editor); - - // decorations - editor.changeDecorations((changeAccessor) => { - this._decorations = changeAccessor.deltaDecorations(this._decorations, newDecorations.decorations); - }); - - // overview ruler - overviewRuler?.setZones(newDecorations.overviewZones); - } -} - -let DIFF_EDITOR_ID = 0; - - -const diffInsertIcon = registerIcon('diff-insert', Codicon.add, nls.localize('diffInsertIcon', 'Line decoration for inserts in the diff editor.')); -const diffRemoveIcon = registerIcon('diff-remove', Codicon.remove, nls.localize('diffRemoveIcon', 'Line decoration for removals in the diff editor.')); -export const diffEditorWidgetTtPolicy = createTrustedTypesPolicy('diffEditorWidget', { createHTML: value => value }); - -const ariaNavigationTip = nls.localize('diff-aria-navigation-tip', ' use Shift + F7 to navigate changes'); - -export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffEditor { - - private static readonly ONE_OVERVIEW_WIDTH = 15; - public static readonly ENTIRE_DIFF_OVERVIEW_WIDTH = 30; - private static readonly UPDATE_DIFF_DECORATIONS_DELAY = 200; // ms - - private readonly _onDidDispose: Emitter = this._register(new Emitter()); - public readonly onDidDispose: Event = this._onDidDispose.event; - - protected readonly _onDidChangeModel: Emitter = this._register(new Emitter()); - public readonly onDidChangeModel: Event = this._onDidChangeModel.event; - - private readonly _onDidUpdateDiff: Emitter = this._register(new Emitter()); - public readonly onDidUpdateDiff: Event = this._onDidUpdateDiff.event; - - private readonly _onDidContentSizeChange: Emitter = this._register(new Emitter()); - public readonly onDidContentSizeChange: Event = this._onDidContentSizeChange.event; - - private readonly _id: number; - private _state: editorBrowser.DiffEditorState; - private _updatingDiffProgress: IProgressRunner | null; - - private readonly _domElement: HTMLElement; - protected readonly _containerDomElement: HTMLElement; - private readonly _overviewDomElement: HTMLElement; - private readonly _overviewViewportDomElement: FastDomNode; - - private readonly _elementSizeObserver: ElementSizeObserver; - - private readonly _originalEditor: CodeEditorWidget; - private readonly _originalDomNode: HTMLElement; - private readonly _originalEditorState: VisualEditorState; - private _originalOverviewRuler: editorBrowser.IOverviewRuler | null; - - private readonly _modifiedEditor: CodeEditorWidget; - private readonly _modifiedDomNode: HTMLElement; - private readonly _modifiedEditorState: VisualEditorState; - private _modifiedOverviewRuler: editorBrowser.IOverviewRuler | null; - - private _currentlyChangingViewZones: boolean; - private _beginUpdateDecorationsTimeout: number; - private _diffComputationToken: number; - private _diffComputationResult: IDiffComputationResult | null; - - private _isVisible: boolean; - private _isHandlingScrollEvent: boolean; - - private _boundarySashes: IBoundarySashes | undefined; - - private _options: ValidDiffEditorBaseOptions; - - private _strategy!: DiffEditorWidgetStyle; - - private readonly _updateDecorationsRunner: RunOnceScheduler; - - private readonly _documentDiffProvider: WorkerBasedDocumentDiffProvider; - private readonly _contextKeyService: IContextKeyService; - private readonly _instantiationService: IInstantiationService; - private readonly _codeEditorService: ICodeEditorService; - private readonly _themeService: IThemeService; - private readonly _notificationService: INotificationService; - - private readonly _reviewPane: DiffReview; - - private isEmbeddedDiffEditorKey: IContextKey; - - private _diffNavigator: DiffNavigator | undefined; - - constructor( - domElement: HTMLElement, - options: Readonly, - codeEditorWidgetOptions: IDiffCodeEditorWidgetOptions, - @IClipboardService clipboardService: IClipboardService, - @IContextKeyService contextKeyService: IContextKeyService, - @IInstantiationService instantiationService: IInstantiationService, - @ICodeEditorService codeEditorService: ICodeEditorService, - @IThemeService themeService: IThemeService, - @INotificationService notificationService: INotificationService, - @IContextMenuService contextMenuService: IContextMenuService, - @IEditorProgressService private readonly _editorProgressService: IEditorProgressService - ) { - super(); - codeEditorService.willCreateDiffEditor(); - - this._documentDiffProvider = this._register(instantiationService.createInstance(WorkerBasedDocumentDiffProvider, options)); - this._register(this._documentDiffProvider.onDidChange(e => this._beginUpdateDecorationsSoon())); - - this._codeEditorService = codeEditorService; - this._contextKeyService = this._register(contextKeyService.createScoped(domElement)); - this._instantiationService = instantiationService.createChild(new ServiceCollection([IContextKeyService, this._contextKeyService])); - this._contextKeyService.createKey('isInDiffEditor', true); - this._themeService = themeService; - this._notificationService = notificationService; - - this._id = (++DIFF_EDITOR_ID); - this._state = editorBrowser.DiffEditorState.Idle; - this._updatingDiffProgress = null; - - this._domElement = domElement; - options = options || {}; - - this._options = validateDiffEditorOptions(options, { - enableSplitViewResizing: true, - splitViewDefaultRatio: 0.5, - renderSideBySide: true, - renderMarginRevertIcon: true, - maxComputationTime: 5000, - maxFileSize: 50, - ignoreTrimWhitespace: true, - renderIndicators: true, - originalEditable: false, - diffCodeLens: false, - renderOverviewRuler: true, - diffWordWrap: 'inherit', - diffAlgorithm: 'advanced', - accessibilityVerbose: false, - experimental: { - showEmptyDecorations: false, - showMoves: false, - }, - hideUnchangedRegions: { - enabled: false, - contextLineCount: 0, - minimumLineCount: 0, - revealLineCount: 0, - }, - isInEmbeddedEditor: false, - onlyShowAccessibleDiffViewer: false, - renderSideBySideInlineBreakpoint: 0, - useInlineViewWhenSpaceIsLimited: false, - }); - - this.isEmbeddedDiffEditorKey = EditorContextKeys.isEmbeddedDiffEditor.bindTo(this._contextKeyService); - this.isEmbeddedDiffEditorKey.set(typeof options.isInEmbeddedEditor !== 'undefined' ? options.isInEmbeddedEditor : false); - this._updateDecorationsRunner = this._register(new RunOnceScheduler(() => this._updateDecorations(), 0)); - - this._containerDomElement = document.createElement('div'); - this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getColorTheme(), this._options.renderSideBySide); - this._containerDomElement.style.position = 'relative'; - this._containerDomElement.style.height = '100%'; - this._domElement.appendChild(this._containerDomElement); - - this._overviewViewportDomElement = createFastDomNode(document.createElement('div')); - this._overviewViewportDomElement.setClassName('diffViewport'); - this._overviewViewportDomElement.setPosition('absolute'); - - this._overviewDomElement = document.createElement('div'); - this._overviewDomElement.className = 'diffOverview'; - this._overviewDomElement.style.position = 'absolute'; - - this._overviewDomElement.appendChild(this._overviewViewportDomElement.domNode); - - this._register(dom.addStandardDisposableListener(this._overviewDomElement, dom.EventType.POINTER_DOWN, (e) => { - this._modifiedEditor.delegateVerticalScrollbarPointerDown(e); - })); - this._register(dom.addDisposableListener(this._overviewDomElement, dom.EventType.MOUSE_WHEEL, (e: IMouseWheelEvent) => { - this._modifiedEditor.delegateScrollFromMouseWheelEvent(e); - }, { passive: false })); - if (this._options.renderOverviewRuler) { - this._containerDomElement.appendChild(this._overviewDomElement); - } - - // Create left side - this._originalDomNode = document.createElement('div'); - this._originalDomNode.className = 'editor original'; - this._originalDomNode.style.position = 'absolute'; - this._originalDomNode.style.height = '100%'; - this._containerDomElement.appendChild(this._originalDomNode); - - // Create right side - this._modifiedDomNode = document.createElement('div'); - this._modifiedDomNode.className = 'editor modified'; - this._modifiedDomNode.style.position = 'absolute'; - this._modifiedDomNode.style.height = '100%'; - this._containerDomElement.appendChild(this._modifiedDomNode); - - this._beginUpdateDecorationsTimeout = -1; - this._currentlyChangingViewZones = false; - this._diffComputationToken = 0; - - this._originalEditorState = new VisualEditorState(contextMenuService, clipboardService); - this._modifiedEditorState = new VisualEditorState(contextMenuService, clipboardService); - - this._isVisible = true; - this._isHandlingScrollEvent = false; - - this._elementSizeObserver = this._register(new ElementSizeObserver(this._containerDomElement, options.dimension)); - this._register(this._elementSizeObserver.onDidChange(() => this._onDidContainerSizeChanged())); - if (options.automaticLayout) { - this._elementSizeObserver.startObserving(); - } - - this._diffComputationResult = null; - - this._originalEditor = this._createLeftHandSideEditor(options, codeEditorWidgetOptions.originalEditor || {}); - this._modifiedEditor = this._createRightHandSideEditor(options, codeEditorWidgetOptions.modifiedEditor || {}); - - this._originalOverviewRuler = null; - this._modifiedOverviewRuler = null; - - this._reviewPane = instantiationService.createInstance(DiffReview, this); - this._containerDomElement.appendChild(this._reviewPane.domNode.domNode); - this._containerDomElement.appendChild(this._reviewPane.shadow.domNode); - this._containerDomElement.appendChild(this._reviewPane.actionBarContainer.domNode); - - if (this._options.renderSideBySide) { - this._setStrategy(new DiffEditorWidgetSideBySide(this._createDataSource(), this._options.enableSplitViewResizing, this._options.splitViewDefaultRatio)); - } else { - this._setStrategy(new DiffEditorWidgetInline(this._createDataSource(), this._options.enableSplitViewResizing)); - } - - this._register(themeService.onDidColorThemeChange(t => { - if (this._strategy && this._strategy.applyColors(t)) { - this._updateDecorationsRunner.schedule(); - } - this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getColorTheme(), this._options.renderSideBySide); - })); - - const contributions: IDiffEditorContributionDescription[] = EditorExtensionsRegistry.getDiffEditorContributions(); - for (const desc of contributions) { - try { - this._register(instantiationService.createInstance(desc.ctor, this)); - } catch (err) { - onUnexpectedError(err); - } - } - - this._codeEditorService.addDiffEditor(this); - } - - public get ignoreTrimWhitespace(): boolean { - return this._options.ignoreTrimWhitespace; - } - - public get maxComputationTime(): number { - return this._options.maxComputationTime; - } - - public get renderSideBySide(): boolean { - return this._options.renderSideBySide; - } - - public getContentHeight(): number { - return this._modifiedEditor.getContentHeight(); - } - - public getViewWidth(): number { - return this._elementSizeObserver.getWidth(); - } - - setBoundarySashes(sashes: IBoundarySashes) { - this._boundarySashes = sashes; - this._strategy.setBoundarySashes(sashes); - } - - private _setState(newState: editorBrowser.DiffEditorState): void { - if (this._state === newState) { - return; - } - this._state = newState; - - if (this._updatingDiffProgress) { - this._updatingDiffProgress.done(); - this._updatingDiffProgress = null; - } - - if (this._state === editorBrowser.DiffEditorState.ComputingDiff) { - this._updatingDiffProgress = this._editorProgressService.show(true, 1000); - } - } - - public hasWidgetFocus(): boolean { - return dom.isAncestor(document.activeElement, this._domElement); - } - - public accessibleDiffViewerNext(): void { - this._reviewPane.next(); - } - - public accessibleDiffViewerPrev(): void { - this._reviewPane.prev(); - } - - private static _getClassName(theme: IColorTheme, renderSideBySide: boolean): string { - let result = 'monaco-diff-editor monaco-editor-background '; - if (renderSideBySide) { - result += 'side-by-side '; - } - result += getThemeTypeSelector(theme.type); - return result; - } - - private _disposeOverviewRulers(): void { - if (this._originalOverviewRuler) { - this._overviewDomElement.removeChild(this._originalOverviewRuler.getDomNode()); - this._originalOverviewRuler.dispose(); - this._originalOverviewRuler = null; - } - if (this._modifiedOverviewRuler) { - this._overviewDomElement.removeChild(this._modifiedOverviewRuler.getDomNode()); - this._modifiedOverviewRuler.dispose(); - this._modifiedOverviewRuler = null; - } - } - - private _createOverviewRulers(): void { - if (!this._options.renderOverviewRuler) { - return; - } - - assert.ok(!this._originalOverviewRuler && !this._modifiedOverviewRuler); - - if (this._originalEditor.hasModel()) { - this._originalOverviewRuler = this._originalEditor.createOverviewRuler('original diffOverviewRuler')!; - this._overviewDomElement.appendChild(this._originalOverviewRuler.getDomNode()); - } - if (this._modifiedEditor.hasModel()) { - this._modifiedOverviewRuler = this._modifiedEditor.createOverviewRuler('modified diffOverviewRuler')!; - this._overviewDomElement.appendChild(this._modifiedOverviewRuler.getDomNode()); - } - - this._layoutOverviewRulers(); - } - - private _createLeftHandSideEditor(options: Readonly, codeEditorWidgetOptions: ICodeEditorWidgetOptions): CodeEditorWidget { - const editor = this._createInnerEditor(this._instantiationService, this._originalDomNode, this._adjustOptionsForLeftHandSide(options), codeEditorWidgetOptions); - - this._register(editor.onDidScrollChange((e) => { - if (this._isHandlingScrollEvent) { - return; - } - if (!e.scrollTopChanged && !e.scrollLeftChanged && !e.scrollHeightChanged) { - return; - } - this._isHandlingScrollEvent = true; - this._modifiedEditor.setScrollPosition({ - scrollLeft: e.scrollLeft, - scrollTop: e.scrollTop - }); - this._isHandlingScrollEvent = false; - - this._layoutOverviewViewport(); - })); - - this._register(editor.onDidChangeViewZones(() => { - this._onViewZonesChanged(); - })); - - this._register(editor.onDidChangeConfiguration((e) => { - if (!editor.getModel()) { - return; - } - if (e.hasChanged(EditorOption.fontInfo)) { - this._updateDecorationsRunner.schedule(); - } - if (e.hasChanged(EditorOption.wrappingInfo)) { - this._updateDecorationsRunner.cancel(); - this._updateDecorations(); - } - })); - - this._register(editor.onDidChangeHiddenAreas(() => { - this._updateDecorationsRunner.cancel(); - this._updateDecorations(); - })); - - this._register(editor.onDidChangeModelContent(() => { - if (this._isVisible) { - this._beginUpdateDecorationsSoon(); - } - })); - - const isInDiffLeftEditorKey = this._contextKeyService.createKey('isInDiffLeftEditor', editor.hasWidgetFocus()); - this._register(editor.onDidFocusEditorWidget(() => isInDiffLeftEditorKey.set(true))); - this._register(editor.onDidBlurEditorWidget(() => isInDiffLeftEditorKey.set(false))); - - this._register(editor.onDidContentSizeChange(e => { - const width = this._originalEditor.getContentWidth() + this._modifiedEditor.getContentWidth() + DiffEditorWidget.ONE_OVERVIEW_WIDTH; - const height = Math.max(this._modifiedEditor.getContentHeight(), this._originalEditor.getContentHeight()); - - this._onDidContentSizeChange.fire({ - contentHeight: height, - contentWidth: width, - contentHeightChanged: e.contentHeightChanged, - contentWidthChanged: e.contentWidthChanged - }); - })); - - return editor; - } - - private _createRightHandSideEditor(options: Readonly, codeEditorWidgetOptions: ICodeEditorWidgetOptions): CodeEditorWidget { - const editor = this._createInnerEditor(this._instantiationService, this._modifiedDomNode, this._adjustOptionsForRightHandSide(options), codeEditorWidgetOptions); - - this._register(editor.onDidScrollChange((e) => { - if (this._isHandlingScrollEvent) { - return; - } - if (!e.scrollTopChanged && !e.scrollLeftChanged && !e.scrollHeightChanged) { - return; - } - this._isHandlingScrollEvent = true; - this._originalEditor.setScrollPosition({ - scrollLeft: e.scrollLeft, - scrollTop: e.scrollTop - }); - this._isHandlingScrollEvent = false; - - this._layoutOverviewViewport(); - })); - - this._register(editor.onDidChangeViewZones(() => { - this._onViewZonesChanged(); - })); - - this._register(editor.onDidChangeConfiguration((e) => { - if (!editor.getModel()) { - return; - } - if (e.hasChanged(EditorOption.fontInfo)) { - this._updateDecorationsRunner.schedule(); - } - if (e.hasChanged(EditorOption.wrappingInfo)) { - this._updateDecorationsRunner.cancel(); - this._updateDecorations(); - } - })); - - this._register(editor.onDidChangeHiddenAreas(() => { - this._updateDecorationsRunner.cancel(); - this._updateDecorations(); - })); - - this._register(editor.onDidChangeModelContent(() => { - if (this._isVisible) { - this._beginUpdateDecorationsSoon(); - } - })); - - this._register(editor.onDidChangeModelOptions((e) => { - if (e.tabSize) { - this._updateDecorationsRunner.schedule(); - } - })); - - const isInDiffRightEditorKey = this._contextKeyService.createKey('isInDiffRightEditor', editor.hasWidgetFocus()); - this._register(editor.onDidFocusEditorWidget(() => isInDiffRightEditorKey.set(true))); - this._register(editor.onDidBlurEditorWidget(() => isInDiffRightEditorKey.set(false))); - - this._register(editor.onDidContentSizeChange(e => { - const width = this._originalEditor.getContentWidth() + this._modifiedEditor.getContentWidth() + DiffEditorWidget.ONE_OVERVIEW_WIDTH; - const height = Math.max(this._modifiedEditor.getContentHeight(), this._originalEditor.getContentHeight()); - - this._onDidContentSizeChange.fire({ - contentHeight: height, - contentWidth: width, - contentHeightChanged: e.contentHeightChanged, - contentWidthChanged: e.contentWidthChanged - }); - })); - - // Revert change when an arrow is clicked. - this._register(editor.onMouseDown(event => { - if (!event.event.rightButton && event.target.position && event.target.element?.className.includes('arrow-revert-change')) { - const lineNumber = event.target.position.lineNumber; - const viewZone = event.target as editorBrowser.IMouseTargetViewZone | undefined; - const change = this._diffComputationResult?.changes.find(c => - // delete change - viewZone?.detail.afterLineNumber === c.modifiedStartLineNumber || - // other changes - (c.modifiedEndLineNumber > 0 && c.modifiedStartLineNumber === lineNumber)); - if (change) { - this.revertChange(change); - } - event.event.stopPropagation(); - this._updateDecorations(); - return; - } - })); - - return editor; - } - - /** - * Reverts a change in the modified editor. - */ - revertChange(change: IChange) { - const editor = this._modifiedEditor; - const original = this._originalEditor.getModel(); - const modified = this._modifiedEditor.getModel(); - if (!original || !modified || !editor) { - return; - } - - const originalRange = change.originalEndLineNumber > 0 ? new Range(change.originalStartLineNumber, 1, change.originalEndLineNumber, original.getLineMaxColumn(change.originalEndLineNumber)) : null; - const originalContent = originalRange ? original.getValueInRange(originalRange) : null; - - const newRange = change.modifiedEndLineNumber > 0 ? new Range(change.modifiedStartLineNumber, 1, change.modifiedEndLineNumber, modified.getLineMaxColumn(change.modifiedEndLineNumber)) : null; - - const eol = modified.getEOL(); - - if (change.originalEndLineNumber === 0 && newRange) { - // Insert change. - // To revert: delete the new content and a linebreak (if possible) - - let range = newRange; - if (change.modifiedStartLineNumber > 1) { - // Try to include a linebreak from before. - range = newRange.setStartPosition(change.modifiedStartLineNumber - 1, modified.getLineMaxColumn(change.modifiedStartLineNumber - 1)); - } else if (change.modifiedEndLineNumber < modified.getLineCount()) { - // Try to include the linebreak from after. - range = newRange.setEndPosition(change.modifiedEndLineNumber + 1, 1); - } - editor.executeEdits('diffEditor', [{ - range, - text: '', - }]); - } else if (change.modifiedEndLineNumber === 0 && originalContent !== null) { - // Delete change. - // To revert: insert the old content and a linebreak. - - const insertAt = change.modifiedStartLineNumber < modified.getLineCount() ? new Position(change.modifiedStartLineNumber + 1, 1) : new Position(change.modifiedStartLineNumber, modified.getLineMaxColumn(change.modifiedStartLineNumber)); - editor.executeEdits('diffEditor', [{ - range: Range.fromPositions(insertAt, insertAt), - text: change.modifiedStartLineNumber < modified.getLineCount() ? originalContent + eol : eol + originalContent, - }]); - } else if (newRange && originalContent !== null) { - // Modified change. - editor.executeEdits('diffEditor', [{ - range: newRange, - text: originalContent, - }]); - } - } - - protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: Readonly, editorWidgetOptions: ICodeEditorWidgetOptions): CodeEditorWidget { - return instantiationService.createInstance(CodeEditorWidget, container, options, editorWidgetOptions); - } - - public override dispose(): void { - this._codeEditorService.removeDiffEditor(this); - - if (this._beginUpdateDecorationsTimeout !== -1) { - window.clearTimeout(this._beginUpdateDecorationsTimeout); - this._beginUpdateDecorationsTimeout = -1; - } - - this._cleanViewZonesAndDecorations(); - - if (this._originalOverviewRuler) { - this._overviewDomElement.removeChild(this._originalOverviewRuler.getDomNode()); - this._originalOverviewRuler.dispose(); - } - if (this._modifiedOverviewRuler) { - this._overviewDomElement.removeChild(this._modifiedOverviewRuler.getDomNode()); - this._modifiedOverviewRuler.dispose(); - } - this._overviewDomElement.removeChild(this._overviewViewportDomElement.domNode); - if (this._options.renderOverviewRuler) { - this._containerDomElement.removeChild(this._overviewDomElement); - } - - this._containerDomElement.removeChild(this._originalDomNode); - this._originalEditor.dispose(); - - this._containerDomElement.removeChild(this._modifiedDomNode); - this._modifiedEditor.dispose(); - - this._strategy.dispose(); - - this._containerDomElement.removeChild(this._reviewPane.domNode.domNode); - this._containerDomElement.removeChild(this._reviewPane.shadow.domNode); - this._containerDomElement.removeChild(this._reviewPane.actionBarContainer.domNode); - this._reviewPane.dispose(); - - this._domElement.removeChild(this._containerDomElement); - - this._onDidDispose.fire(); - - super.dispose(); - } - - //------------ begin IDiffEditor methods - - public getId(): string { - return this.getEditorType() + ':' + this._id; - } - - public getEditorType(): string { - return editorCommon.EditorType.IDiffEditor; - } - - public getLineChanges(): ILineChange[] | null { - if (!this._diffComputationResult) { - return null; - } - return this._diffComputationResult.changes; - } - - public getDiffComputationResult(): IDiffComputationResult | null { - return this._diffComputationResult; - } - - public getOriginalEditor(): editorBrowser.ICodeEditor { - return this._originalEditor; - } - - public getModifiedEditor(): editorBrowser.ICodeEditor { - return this._modifiedEditor; - } - - public updateOptions(_newOptions: Readonly): void { - const newOptions = validateDiffEditorOptions(_newOptions, this._options); - const changed = changedDiffEditorOptions(this._options, newOptions); - this._options = newOptions; - - this.isEmbeddedDiffEditorKey.set(typeof _newOptions.isInEmbeddedEditor !== 'undefined' ? _newOptions.isInEmbeddedEditor : false); - - const beginUpdateDecorations = (changed.ignoreTrimWhitespace || changed.renderIndicators || changed.renderMarginRevertIcon); - const beginUpdateDecorationsSoon = (this._isVisible && (changed.maxComputationTime || changed.maxFileSize)); - this._documentDiffProvider.setOptions(newOptions); - - if (beginUpdateDecorations) { - this._beginUpdateDecorations(); - } else if (beginUpdateDecorationsSoon) { - this._beginUpdateDecorationsSoon(); - } - - this._modifiedEditor.updateOptions(this._adjustOptionsForRightHandSide(_newOptions)); - this._originalEditor.updateOptions(this._adjustOptionsForLeftHandSide(_newOptions)); - - // enableSplitViewResizing - this._strategy.setEnableSplitViewResizing(this._options.enableSplitViewResizing, this._options.splitViewDefaultRatio); - - // renderSideBySide - if (changed.renderSideBySide) { - if (this._options.renderSideBySide) { - this._setStrategy(new DiffEditorWidgetSideBySide(this._createDataSource(), this._options.enableSplitViewResizing, this._options.splitViewDefaultRatio)); - } else { - this._setStrategy(new DiffEditorWidgetInline(this._createDataSource(), this._options.enableSplitViewResizing)); - } - // Update class name - this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getColorTheme(), this._options.renderSideBySide); - } - - // renderOverviewRuler - if (changed.renderOverviewRuler) { - if (this._options.renderOverviewRuler) { - this._containerDomElement.appendChild(this._overviewDomElement); - } else { - this._containerDomElement.removeChild(this._overviewDomElement); - } - } - } - - public getModel(): editorCommon.IDiffEditorModel { - return { - original: this._originalEditor.getModel()!, - modified: this._modifiedEditor.getModel()! - }; - } - - public createViewModel(model: editorCommon.IDiffEditorModel): editorCommon.IDiffEditorViewModel { - return { - model, - async waitForDiff() { - // noop - }, - }; - } - - public setModel(model: editorCommon.IDiffEditorModel | editorCommon.IDiffEditorViewModel | null): void { - if (model && 'model' in model) { - model = model.model; - } - - // Guard us against partial null model - if (model && (!model.original || !model.modified)) { - throw new Error(!model.original ? 'DiffEditorWidget.setModel: Original model is null' : 'DiffEditorWidget.setModel: Modified model is null'); - } - - // Remove all view zones & decorations - this._cleanViewZonesAndDecorations(); - - this._disposeOverviewRulers(); - - // Update code editor models - this._originalEditor.setModel(model ? model.original : null); - this._modifiedEditor.setModel(model ? model.modified : null); - this._updateDecorationsRunner.cancel(); - - // this.originalEditor.onDidChangeModelOptions - - if (model) { - this._originalEditor.setScrollTop(0); - this._modifiedEditor.setScrollTop(0); - } - - // Disable any diff computations that will come in - this._diffComputationResult = null; - this._diffComputationToken++; - this._setState(editorBrowser.DiffEditorState.Idle); - - if (model) { - this._createOverviewRulers(); - - // Begin comparing - this._beginUpdateDecorations(); - } - - this._layoutOverviewViewport(); - - this._onDidChangeModel.fire(); - - // Diff navigator - this._diffNavigator = this._register(this._instantiationService.createInstance(DiffNavigator, this, { - alwaysRevealFirst: false, - findResultLoop: this.getModifiedEditor().getOption(EditorOption.find).loop - })); - } - - public getContainerDomNode(): HTMLElement { - return this._domElement; - } - - // #region editorBrowser.IDiffEditor: Delegating to modified Editor - - public getVisibleColumnFromPosition(position: IPosition): number { - return this._modifiedEditor.getVisibleColumnFromPosition(position); - } - - public getStatusbarColumn(position: IPosition): number { - return this._modifiedEditor.getStatusbarColumn(position); - } - - public getPosition(): Position | null { - return this._modifiedEditor.getPosition(); - } - - public setPosition(position: IPosition, source: string = 'api'): void { - this._modifiedEditor.setPosition(position, source); - } - - public revealLine(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealLine(lineNumber, scrollType); - } - - public revealLineInCenter(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealLineInCenter(lineNumber, scrollType); - } - - public revealLineInCenterIfOutsideViewport(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealLineInCenterIfOutsideViewport(lineNumber, scrollType); - } - - public revealLineNearTop(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealLineNearTop(lineNumber, scrollType); - } - - public revealPosition(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealPosition(position, scrollType); - } - - public revealPositionInCenter(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealPositionInCenter(position, scrollType); - } - - public revealPositionInCenterIfOutsideViewport(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealPositionInCenterIfOutsideViewport(position, scrollType); - } - - public revealPositionNearTop(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealPositionNearTop(position, scrollType); - } - - public getSelection(): Selection | null { - return this._modifiedEditor.getSelection(); - } - - public getSelections(): Selection[] | null { - return this._modifiedEditor.getSelections(); - } - - public setSelection(range: IRange, source?: string): void; - public setSelection(editorRange: Range, source?: string): void; - public setSelection(selection: ISelection, source?: string): void; - public setSelection(editorSelection: Selection, source?: string): void; - public setSelection(something: any, source: string = 'api'): void { - this._modifiedEditor.setSelection(something, source); - } - - public setSelections(ranges: readonly ISelection[], source: string = 'api'): void { - this._modifiedEditor.setSelections(ranges, source); - } - - public revealLines(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealLines(startLineNumber, endLineNumber, scrollType); - } - - public revealLinesInCenter(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealLinesInCenter(startLineNumber, endLineNumber, scrollType); - } - - public revealLinesInCenterIfOutsideViewport(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealLinesInCenterIfOutsideViewport(startLineNumber, endLineNumber, scrollType); - } - - public revealLinesNearTop(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealLinesNearTop(startLineNumber, endLineNumber, scrollType); - } - - public revealRange(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth, revealVerticalInCenter: boolean = false, revealHorizontal: boolean = true): void { - this._modifiedEditor.revealRange(range, scrollType, revealVerticalInCenter, revealHorizontal); - } - - public revealRangeInCenter(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealRangeInCenter(range, scrollType); - } - - public revealRangeInCenterIfOutsideViewport(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealRangeInCenterIfOutsideViewport(range, scrollType); - } - - public revealRangeNearTop(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealRangeNearTop(range, scrollType); - } - - public revealRangeNearTopIfOutsideViewport(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealRangeNearTopIfOutsideViewport(range, scrollType); - } - - public revealRangeAtTop(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { - this._modifiedEditor.revealRangeAtTop(range, scrollType); - } - - public getSupportedActions(): editorCommon.IEditorAction[] { - return this._modifiedEditor.getSupportedActions(); - } - - public focus(): void { - this._modifiedEditor.focus(); - } - - public trigger(source: string | null | undefined, handlerId: string, payload: any): void { - this._modifiedEditor.trigger(source, handlerId, payload); - } - - public createDecorationsCollection(decorations?: IModelDeltaDecoration[]): editorCommon.IEditorDecorationsCollection { - return this._modifiedEditor.createDecorationsCollection(decorations); - } - - public changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any { - return this._modifiedEditor.changeDecorations(callback); - } - - // #endregion - - public saveViewState(): editorCommon.IDiffEditorViewState { - const originalViewState = this._originalEditor.saveViewState(); - const modifiedViewState = this._modifiedEditor.saveViewState(); - return { - original: originalViewState, - modified: modifiedViewState, - }; - } - - public restoreViewState(s: editorCommon.IDiffEditorViewState): void { - if (s && s.original && s.modified) { - const diffEditorState = s; - this._originalEditor.restoreViewState(diffEditorState.original); - this._modifiedEditor.restoreViewState(diffEditorState.modified); - } - } - - public layout(dimension?: IDimension): void { - this._elementSizeObserver.observe(dimension); - } - - - public hasTextFocus(): boolean { - return this._originalEditor.hasTextFocus() || this._modifiedEditor.hasTextFocus(); - } - - public onVisible(): void { - this._isVisible = true; - this._originalEditor.onVisible(); - this._modifiedEditor.onVisible(); - // Begin comparing - this._beginUpdateDecorations(); - } - - public onHide(): void { - this._isVisible = false; - this._originalEditor.onHide(); - this._modifiedEditor.onHide(); - // Remove all view zones & decorations - this._cleanViewZonesAndDecorations(); - } - - //------------ end IDiffEditor methods - - - - //------------ begin layouting methods - - private _onDidContainerSizeChanged(): void { - this._doLayout(); - } - - private _getReviewHeight(): number { - return this._reviewPane.isVisible() ? this._elementSizeObserver.getHeight() : 0; - } - - private _layoutOverviewRulers(): void { - if (!this._options.renderOverviewRuler) { - return; - } - - if (!this._originalOverviewRuler || !this._modifiedOverviewRuler) { - return; - } - const height = this._elementSizeObserver.getHeight(); - const reviewHeight = this._getReviewHeight(); - - const freeSpace = DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH - 2 * DiffEditorWidget.ONE_OVERVIEW_WIDTH; - const layoutInfo = this._modifiedEditor.getLayoutInfo(); - if (layoutInfo) { - this._originalOverviewRuler.setLayout({ - top: 0, - width: DiffEditorWidget.ONE_OVERVIEW_WIDTH, - right: freeSpace + DiffEditorWidget.ONE_OVERVIEW_WIDTH, - height: (height - reviewHeight) - }); - this._modifiedOverviewRuler.setLayout({ - top: 0, - right: 0, - width: DiffEditorWidget.ONE_OVERVIEW_WIDTH, - height: (height - reviewHeight) - }); - } - } - - //------------ end layouting methods - - private _onViewZonesChanged(): void { - if (this._currentlyChangingViewZones) { - return; - } - this._updateDecorationsRunner.schedule(); - } - - private _beginUpdateDecorationsSoon(): void { - // Clear previous timeout if necessary - if (this._beginUpdateDecorationsTimeout !== -1) { - window.clearTimeout(this._beginUpdateDecorationsTimeout); - this._beginUpdateDecorationsTimeout = -1; - } - this._beginUpdateDecorationsTimeout = window.setTimeout(() => this._beginUpdateDecorations(), DiffEditorWidget.UPDATE_DIFF_DECORATIONS_DELAY); - } - - private _lastOriginalWarning: URI | null = null; - private _lastModifiedWarning: URI | null = null; - - private static _equals(a: URI | null, b: URI | null): boolean { - if (!a && !b) { - return true; - } - if (!a || !b) { - return false; - } - return (a.toString() === b.toString()); - } - - private _beginUpdateDecorations(): void { - if (this._beginUpdateDecorationsTimeout !== -1) { - // Cancel any pending requests in case this method is called directly - window.clearTimeout(this._beginUpdateDecorationsTimeout); - this._beginUpdateDecorationsTimeout = -1; - } - const currentOriginalModel = this._originalEditor.getModel(); - const currentModifiedModel = this._modifiedEditor.getModel(); - if (!currentOriginalModel || !currentModifiedModel) { - return; - } - - // Prevent old diff requests to come if a new request has been initiated - // The best method would be to call cancel on the Promise, but this is not - // yet supported, so using tokens for now. - this._diffComputationToken++; - const currentToken = this._diffComputationToken; - - const diffLimit = this._options.maxFileSize * 1024 * 1024; // MB - const canSyncModelForDiff = (model: ITextModel): boolean => { - const bufferTextLength = model.getValueLength(); - return (diffLimit === 0 || bufferTextLength <= diffLimit); - }; - - if (!canSyncModelForDiff(currentOriginalModel) || !canSyncModelForDiff(currentModifiedModel)) { - if ( - !DiffEditorWidget._equals(currentOriginalModel.uri, this._lastOriginalWarning) - || !DiffEditorWidget._equals(currentModifiedModel.uri, this._lastModifiedWarning) - ) { - this._lastOriginalWarning = currentOriginalModel.uri; - this._lastModifiedWarning = currentModifiedModel.uri; - this._notificationService.warn(nls.localize("diff.tooLarge", "Cannot compare files because one file is too large.")); - } - return; - } - - this._setState(editorBrowser.DiffEditorState.ComputingDiff); - this._documentDiffProvider.computeDiff(currentOriginalModel, currentModifiedModel, { - ignoreTrimWhitespace: this._options.ignoreTrimWhitespace, - maxComputationTimeMs: this._options.maxComputationTime, - computeMoves: false, - }, CancellationToken.None).then(result => { - if (currentToken === this._diffComputationToken - && currentOriginalModel === this._originalEditor.getModel() - && currentModifiedModel === this._modifiedEditor.getModel() - ) { - this._setState(editorBrowser.DiffEditorState.DiffComputed); - this._diffComputationResult = { - identical: result.identical, - quitEarly: result.quitEarly, - changes2: result.changes, - changes: result.changes.map(m => { - // TODO don't do this translation, but use the diff result directly - let originalStartLineNumber: number; - let originalEndLineNumber: number; - let modifiedStartLineNumber: number; - let modifiedEndLineNumber: number; - let innerChanges = m.innerChanges; - - if (m.original.isEmpty) { - // Insertion - originalStartLineNumber = m.original.startLineNumber - 1; - originalEndLineNumber = 0; - innerChanges = undefined; - } else { - originalStartLineNumber = m.original.startLineNumber; - originalEndLineNumber = m.original.endLineNumberExclusive - 1; - } - - if (m.modified.isEmpty) { - // Deletion - modifiedStartLineNumber = m.modified.startLineNumber - 1; - modifiedEndLineNumber = 0; - innerChanges = undefined; - } else { - modifiedStartLineNumber = m.modified.startLineNumber; - modifiedEndLineNumber = m.modified.endLineNumberExclusive - 1; - } - - return { - originalStartLineNumber, - originalEndLineNumber, - modifiedStartLineNumber, - modifiedEndLineNumber, - charChanges: innerChanges?.map(m => ({ - originalStartLineNumber: m.originalRange.startLineNumber, - originalStartColumn: m.originalRange.startColumn, - originalEndLineNumber: m.originalRange.endLineNumber, - originalEndColumn: m.originalRange.endColumn, - modifiedStartLineNumber: m.modifiedRange.startLineNumber, - modifiedStartColumn: m.modifiedRange.startColumn, - modifiedEndLineNumber: m.modifiedRange.endLineNumber, - modifiedEndColumn: m.modifiedRange.endColumn, - })) - }; - }) - }; - this._updateDecorationsRunner.schedule(); - this._onDidUpdateDiff.fire(); - } - }, (error) => { - if (currentToken === this._diffComputationToken - && currentOriginalModel === this._originalEditor.getModel() - && currentModifiedModel === this._modifiedEditor.getModel() - ) { - this._setState(editorBrowser.DiffEditorState.DiffComputed); - this._diffComputationResult = null; - this._updateDecorationsRunner.schedule(); - } - }); - } - - private _cleanViewZonesAndDecorations(): void { - this._originalEditorState.clean(this._originalEditor); - this._modifiedEditorState.clean(this._modifiedEditor); - } - - private _updateDecorations(): void { - if (!this._originalEditor.getModel() || !this._modifiedEditor.getModel()) { - return; - } - - const lineChanges = (this._diffComputationResult ? this._diffComputationResult.changes : []); - - const foreignOriginal = this._originalEditorState.getForeignViewZones(this._originalEditor.getWhitespaces()); - const foreignModified = this._modifiedEditorState.getForeignViewZones(this._modifiedEditor.getWhitespaces()); - - const renderMarginRevertIcon = this._options.renderMarginRevertIcon && !this._modifiedEditor.getOption(EditorOption.readOnly); - const diffDecorations = this._strategy.getEditorsDiffDecorations(lineChanges, this._options.ignoreTrimWhitespace, this._options.renderIndicators, renderMarginRevertIcon, foreignOriginal, foreignModified); - - try { - this._currentlyChangingViewZones = true; - this._originalEditorState.apply(this._originalEditor, this._originalOverviewRuler, diffDecorations.original, false); - this._modifiedEditorState.apply(this._modifiedEditor, this._modifiedOverviewRuler, diffDecorations.modified, true); - } finally { - this._currentlyChangingViewZones = false; - } - } - - private _adjustOptionsForSubEditor(options: Readonly): IEditorConstructionOptions { - const clonedOptions = { ...options }; - clonedOptions.inDiffEditor = true; - clonedOptions.automaticLayout = false; - // Clone scrollbar options before changing them - clonedOptions.scrollbar = { ...(clonedOptions.scrollbar || {}) }; - clonedOptions.scrollbar.vertical = 'visible'; - clonedOptions.folding = false; - clonedOptions.codeLens = this._options.diffCodeLens; - clonedOptions.fixedOverflowWidgets = true; - // clonedOptions.lineDecorationsWidth = '2ch'; - // Clone minimap options before changing them - clonedOptions.minimap = { ...(clonedOptions.minimap || {}) }; - clonedOptions.minimap.enabled = false; - return clonedOptions; - } - - private _adjustOptionsForLeftHandSide(options: Readonly): IEditorConstructionOptions { - const result = this._adjustOptionsForSubEditor(options); - if (!this._options.renderSideBySide) { - // never wrap hidden editor - result.wordWrapOverride1 = 'off'; - result.wordWrapOverride2 = 'off'; - result.stickyScroll = { enabled: false }; - } else { - result.wordWrapOverride1 = this._options.diffWordWrap; - } - if (options.originalAriaLabel) { - result.ariaLabel = options.originalAriaLabel; - } - this._updateAriaLabel(result); - result.readOnly = !this._options.originalEditable; - result.dropIntoEditor = { enabled: !result.readOnly }; - result.extraEditorClassName = 'original-in-monaco-diff-editor'; - return { - ...result, - dimension: { - height: 0, - width: 0 - } - }; - } - - private _updateAriaLabel(options: IEditorConstructionOptions): void { - let ariaLabel = options.ariaLabel ?? ''; - if (this._options.accessibilityVerbose) { - ariaLabel += ariaNavigationTip; - } else if (ariaLabel) { - ariaLabel = ariaLabel.replaceAll(ariaNavigationTip, ''); - } - options.ariaLabel = ariaLabel; - } - - private _adjustOptionsForRightHandSide(options: Readonly): IEditorConstructionOptions { - const result = this._adjustOptionsForSubEditor(options); - if (options.modifiedAriaLabel) { - result.ariaLabel = options.modifiedAriaLabel; - } - this._updateAriaLabel(result); - result.wordWrapOverride1 = this._options.diffWordWrap; - result.revealHorizontalRightPadding = EditorOptions.revealHorizontalRightPadding.defaultValue + DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH; - result.scrollbar!.verticalHasArrows = false; - result.extraEditorClassName = 'modified-in-monaco-diff-editor'; - return { - ...result, - dimension: { - height: 0, - width: 0 - } - }; - } - - public doLayout(): void { - this._elementSizeObserver.observe(); - this._doLayout(); - } - - private _doLayout(): void { - const width = this._elementSizeObserver.getWidth(); - const height = this._elementSizeObserver.getHeight(); - const reviewHeight = this._getReviewHeight(); - - const splitPoint = this._strategy.layout(); - - this._originalDomNode.style.width = splitPoint + 'px'; - this._originalDomNode.style.left = '0px'; - - this._modifiedDomNode.style.width = (width - splitPoint - DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH) + 'px'; - this._modifiedDomNode.style.left = splitPoint + 'px'; - - this._overviewDomElement.style.top = '0px'; - this._overviewDomElement.style.height = (height - reviewHeight) + 'px'; - this._overviewDomElement.style.width = DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH + 'px'; - this._overviewDomElement.style.left = (width - DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH) + 'px'; - this._overviewViewportDomElement.setWidth(DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH); - this._overviewViewportDomElement.setHeight(30); - - this._originalEditor.layout({ width: splitPoint, height: (height - reviewHeight) }); - this._modifiedEditor.layout({ width: width - splitPoint - (this._options.renderOverviewRuler ? DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH : 0), height: (height - reviewHeight) }); - - if (this._originalOverviewRuler || this._modifiedOverviewRuler) { - this._layoutOverviewRulers(); - } - - this._reviewPane.layout(height - reviewHeight, width, reviewHeight); - - this._layoutOverviewViewport(); - } - - private _layoutOverviewViewport(): void { - const layout = this._computeOverviewViewport(); - if (!layout) { - this._overviewViewportDomElement.setTop(0); - this._overviewViewportDomElement.setHeight(0); - } else { - this._overviewViewportDomElement.setTop(layout.top); - this._overviewViewportDomElement.setHeight(layout.height); - } - } - - private _computeOverviewViewport(): { height: number; top: number } | null { - const layoutInfo = this._modifiedEditor.getLayoutInfo(); - if (!layoutInfo) { - return null; - } - - const scrollTop = this._modifiedEditor.getScrollTop(); - const scrollHeight = this._modifiedEditor.getScrollHeight(); - - const computedAvailableSize = Math.max(0, layoutInfo.height); - const computedRepresentableSize = Math.max(0, computedAvailableSize - 2 * 0); - const computedRatio = scrollHeight > 0 ? (computedRepresentableSize / scrollHeight) : 0; - - const computedSliderSize = Math.max(0, Math.floor(layoutInfo.height * computedRatio)); - const computedSliderPosition = Math.floor(scrollTop * computedRatio); - - return { - height: computedSliderSize, - top: computedSliderPosition - }; - } - - private _createDataSource(): IDataSource { - return { - getWidth: () => { - return this._elementSizeObserver.getWidth(); - }, - - getHeight: () => { - return (this._elementSizeObserver.getHeight() - this._getReviewHeight()); - }, - - getOptions: () => { - return { - renderOverviewRuler: this._options.renderOverviewRuler - }; - }, - - getContainerDomNode: () => { - return this._containerDomElement; - }, - - relayoutEditors: () => { - this._doLayout(); - }, - - getOriginalEditor: () => { - return this._originalEditor; - }, - - getModifiedEditor: () => { - return this._modifiedEditor; - } - }; - } - - private _setStrategy(newStrategy: DiffEditorWidgetStyle): void { - this._strategy?.dispose(); - - this._strategy = newStrategy; - - if (this._boundarySashes) { - newStrategy.setBoundarySashes(this._boundarySashes); - } - - newStrategy.applyColors(this._themeService.getColorTheme()); - - if (this._diffComputationResult) { - this._updateDecorations(); - } - - // Just do a layout, the strategy might need it - this._doLayout(); - } - - public goToDiff(target: 'previous' | 'next'): void { - if (target === 'next') { - this._diffNavigator?.next(); - } else { - this._diffNavigator?.previous(); - } - } - - public revealFirstDiff(): void { - // This is a hack, but it works. - if (this._diffNavigator) { - this._diffNavigator.revealFirst = true; - } - } -} - -interface IDataSource { - getWidth(): number; - getHeight(): number; - getOptions(): { renderOverviewRuler: boolean }; - getContainerDomNode(): HTMLElement; - relayoutEditors(): void; - - getOriginalEditor(): CodeEditorWidget; - getModifiedEditor(): CodeEditorWidget; -} - -abstract class DiffEditorWidgetStyle extends Disposable { - - protected _dataSource: IDataSource; - protected _insertColor: Color | null; - protected _removeColor: Color | null; - - constructor(dataSource: IDataSource) { - super(); - this._dataSource = dataSource; - this._insertColor = null; - this._removeColor = null; - } - - public applyColors(theme: IColorTheme): boolean { - const newInsertColor = theme.getColor(diffOverviewRulerInserted) || (theme.getColor(diffInserted) || defaultInsertColor).transparent(2); - const newRemoveColor = theme.getColor(diffOverviewRulerRemoved) || (theme.getColor(diffRemoved) || defaultRemoveColor).transparent(2); - const hasChanges = !newInsertColor.equals(this._insertColor) || !newRemoveColor.equals(this._removeColor); - this._insertColor = newInsertColor; - this._removeColor = newRemoveColor; - return hasChanges; - } - - public getEditorsDiffDecorations(lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, renderMarginRevertIcon: boolean, originalWhitespaces: IEditorWhitespace[], modifiedWhitespaces: IEditorWhitespace[]): IEditorsDiffDecorationsWithZones { - // Get view zones - modifiedWhitespaces = modifiedWhitespaces.sort((a, b) => { - return a.afterLineNumber - b.afterLineNumber; - }); - originalWhitespaces = originalWhitespaces.sort((a, b) => { - return a.afterLineNumber - b.afterLineNumber; - }); - const zones = this._getViewZones(lineChanges, originalWhitespaces, modifiedWhitespaces, renderIndicators); - - // Get decorations & overview ruler zones - const originalDecorations = this._getOriginalEditorDecorations(zones, lineChanges, ignoreTrimWhitespace, renderIndicators); - const modifiedDecorations = this._getModifiedEditorDecorations(zones, lineChanges, ignoreTrimWhitespace, renderIndicators, renderMarginRevertIcon); - - return { - original: { - decorations: originalDecorations.decorations, - overviewZones: originalDecorations.overviewZones, - zones: zones.original - }, - modified: { - decorations: modifiedDecorations.decorations, - overviewZones: modifiedDecorations.overviewZones, - zones: zones.modified - } - }; - } - - protected abstract _getViewZones(lineChanges: ILineChange[], originalForeignVZ: IEditorWhitespace[], modifiedForeignVZ: IEditorWhitespace[], renderIndicators: boolean): IEditorsZones; - protected abstract _getOriginalEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean): IEditorDiffDecorations; - protected abstract _getModifiedEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, renderMarginRevertIcon: boolean): IEditorDiffDecorations; - - public abstract setEnableSplitViewResizing(enableSplitViewResizing: boolean, defaultRatio: number): void; - public abstract layout(): number; - - setBoundarySashes(_sashes: IBoundarySashes): void { - // To be implemented by subclasses - } -} - -interface IMyViewZone { - shouldNotShrink?: boolean; - afterLineNumber: number; - afterColumn?: number; - heightInLines: number; - minWidthInPx?: number; - domNode: HTMLElement | null; - marginDomNode?: HTMLElement | null; - diff?: IDiffLinesChange; -} - -class ForeignViewZonesIterator { - - private _index: number; - private readonly _source: IEditorWhitespace[]; - public current: IEditorWhitespace | null; - - constructor(source: IEditorWhitespace[]) { - this._source = source; - this._index = -1; - this.current = null; - this.advance(); - } - - public advance(): void { - this._index++; - if (this._index < this._source.length) { - this.current = this._source[this._index]; - } else { - this.current = null; - } - } -} - -abstract class ViewZonesComputer { - - constructor( - private readonly _lineChanges: ILineChange[], - private readonly _originalForeignVZ: IEditorWhitespace[], - private readonly _modifiedForeignVZ: IEditorWhitespace[], - protected readonly _originalEditor: CodeEditorWidget, - protected readonly _modifiedEditor: CodeEditorWidget - ) { - } - - private static _getViewLineCount(editor: CodeEditorWidget, startLineNumber: number, endLineNumber: number): number { - const model = editor.getModel(); - const viewModel = editor._getViewModel(); - if (model && viewModel) { - const viewRange = getViewRange(model, viewModel, startLineNumber, endLineNumber); - return (viewRange.endLineNumber - viewRange.startLineNumber + 1); - } - - return (endLineNumber - startLineNumber + 1); - } - - public getViewZones(): IEditorsZones { - const originalLineHeight = this._originalEditor.getOption(EditorOption.lineHeight); - const modifiedLineHeight = this._modifiedEditor.getOption(EditorOption.lineHeight); - const originalHasWrapping = (this._originalEditor.getOption(EditorOption.wrappingInfo).wrappingColumn !== -1); - const modifiedHasWrapping = (this._modifiedEditor.getOption(EditorOption.wrappingInfo).wrappingColumn !== -1); - const hasWrapping = (originalHasWrapping || modifiedHasWrapping); - const originalModel = this._originalEditor.getModel()!; - const originalCoordinatesConverter = this._originalEditor._getViewModel()!.coordinatesConverter; - const modifiedCoordinatesConverter = this._modifiedEditor._getViewModel()!.coordinatesConverter; - - const result: { original: IMyViewZone[]; modified: IMyViewZone[] } = { - original: [], - modified: [] - }; - - let lineChangeModifiedLength: number = 0; - let lineChangeOriginalLength: number = 0; - let originalEquivalentLineNumber: number = 0; - let modifiedEquivalentLineNumber: number = 0; - let originalEndEquivalentLineNumber: number = 0; - let modifiedEndEquivalentLineNumber: number = 0; - - const sortMyViewZones = (a: IMyViewZone, b: IMyViewZone) => { - return a.afterLineNumber - b.afterLineNumber; - }; - - const addAndCombineIfPossible = (destination: IMyViewZone[], item: IMyViewZone) => { - if (item.domNode === null && destination.length > 0) { - const lastItem = destination[destination.length - 1]; - if (lastItem.afterLineNumber === item.afterLineNumber && lastItem.domNode === null) { - lastItem.heightInLines += item.heightInLines; - return; - } - } - destination.push(item); - }; - - const modifiedForeignVZ = new ForeignViewZonesIterator(this._modifiedForeignVZ); - const originalForeignVZ = new ForeignViewZonesIterator(this._originalForeignVZ); - - let lastOriginalLineNumber = 1; - let lastModifiedLineNumber = 1; - - // In order to include foreign view zones after the last line change, the for loop will iterate once more after the end of the `lineChanges` array - for (let i = 0, length = this._lineChanges.length; i <= length; i++) { - const lineChange = (i < length ? this._lineChanges[i] : null); - - if (lineChange !== null) { - originalEquivalentLineNumber = lineChange.originalStartLineNumber + (lineChange.originalEndLineNumber > 0 ? -1 : 0); - modifiedEquivalentLineNumber = lineChange.modifiedStartLineNumber + (lineChange.modifiedEndLineNumber > 0 ? -1 : 0); - lineChangeOriginalLength = (lineChange.originalEndLineNumber > 0 ? ViewZonesComputer._getViewLineCount(this._originalEditor, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber) : 0); - lineChangeModifiedLength = (lineChange.modifiedEndLineNumber > 0 ? ViewZonesComputer._getViewLineCount(this._modifiedEditor, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber) : 0); - originalEndEquivalentLineNumber = Math.max(lineChange.originalStartLineNumber, lineChange.originalEndLineNumber); - modifiedEndEquivalentLineNumber = Math.max(lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber); - } else { - // Increase to very large value to get the producing tests of foreign view zones running - originalEquivalentLineNumber += 10000000 + lineChangeOriginalLength; - modifiedEquivalentLineNumber += 10000000 + lineChangeModifiedLength; - originalEndEquivalentLineNumber = originalEquivalentLineNumber; - modifiedEndEquivalentLineNumber = modifiedEquivalentLineNumber; - } - - // Each step produces view zones, and after producing them, we try to cancel them out, to avoid empty-empty view zone cases - let stepOriginal: IMyViewZone[] = []; - let stepModified: IMyViewZone[] = []; - - // ---------------------------- PRODUCE VIEW ZONES - - // [PRODUCE] View zones due to line mapping differences (equal lines but wrapped differently) - if (hasWrapping) { - let count: number; - if (lineChange) { - if (lineChange.originalEndLineNumber > 0) { - count = lineChange.originalStartLineNumber - lastOriginalLineNumber; - } else { - count = lineChange.modifiedStartLineNumber - lastModifiedLineNumber; - } - } else { - // `lastOriginalLineNumber` has not been looked at yet - count = originalModel.getLineCount() - lastOriginalLineNumber + 1; - } - - for (let i = 0; i < count; i++) { - const originalLineNumber = lastOriginalLineNumber + i; - const modifiedLineNumber = lastModifiedLineNumber + i; - - const originalViewLineCount = originalCoordinatesConverter.getModelLineViewLineCount(originalLineNumber); - const modifiedViewLineCount = modifiedCoordinatesConverter.getModelLineViewLineCount(modifiedLineNumber); - - if (originalViewLineCount < modifiedViewLineCount) { - stepOriginal.push({ - afterLineNumber: originalLineNumber, - heightInLines: modifiedViewLineCount - originalViewLineCount, - domNode: null, - marginDomNode: null - }); - } else if (originalViewLineCount > modifiedViewLineCount) { - stepModified.push({ - afterLineNumber: modifiedLineNumber, - heightInLines: originalViewLineCount - modifiedViewLineCount, - domNode: null, - marginDomNode: null - }); - } - } - if (lineChange) { - lastOriginalLineNumber = (lineChange.originalEndLineNumber > 0 ? lineChange.originalEndLineNumber : lineChange.originalStartLineNumber) + 1; - lastModifiedLineNumber = (lineChange.modifiedEndLineNumber > 0 ? lineChange.modifiedEndLineNumber : lineChange.modifiedStartLineNumber) + 1; - } - } - - // [PRODUCE] View zone(s) in original-side due to foreign view zone(s) in modified-side - while (modifiedForeignVZ.current && modifiedForeignVZ.current.afterLineNumber <= modifiedEndEquivalentLineNumber) { - let viewZoneLineNumber: number; - if (modifiedForeignVZ.current.afterLineNumber <= modifiedEquivalentLineNumber) { - viewZoneLineNumber = originalEquivalentLineNumber - modifiedEquivalentLineNumber + modifiedForeignVZ.current.afterLineNumber; - } else { - viewZoneLineNumber = originalEndEquivalentLineNumber; - } - - let marginDomNode: HTMLDivElement | null = null; - if (lineChange && lineChange.modifiedStartLineNumber <= modifiedForeignVZ.current.afterLineNumber && modifiedForeignVZ.current.afterLineNumber <= lineChange.modifiedEndLineNumber) { - marginDomNode = this._createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(); - } - - stepOriginal.push({ - afterLineNumber: viewZoneLineNumber, - heightInLines: modifiedForeignVZ.current.height / modifiedLineHeight, - domNode: null, - marginDomNode: marginDomNode - }); - modifiedForeignVZ.advance(); - } - - // [PRODUCE] View zone(s) in modified-side due to foreign view zone(s) in original-side - while (originalForeignVZ.current && originalForeignVZ.current.afterLineNumber <= originalEndEquivalentLineNumber) { - let viewZoneLineNumber: number; - if (originalForeignVZ.current.afterLineNumber <= originalEquivalentLineNumber) { - viewZoneLineNumber = modifiedEquivalentLineNumber - originalEquivalentLineNumber + originalForeignVZ.current.afterLineNumber; - } else { - viewZoneLineNumber = modifiedEndEquivalentLineNumber; - } - stepModified.push({ - afterLineNumber: viewZoneLineNumber, - heightInLines: originalForeignVZ.current.height / originalLineHeight, - domNode: null - }); - originalForeignVZ.advance(); - } - - if (lineChange !== null && isChangeOrInsert(lineChange)) { - const r = this._produceOriginalFromDiff(lineChange, lineChangeOriginalLength, lineChangeModifiedLength); - if (r) { - stepOriginal.push(r); - } - } - - if (lineChange !== null && isChangeOrDelete(lineChange)) { - const r = this._produceModifiedFromDiff(lineChange, lineChangeOriginalLength, lineChangeModifiedLength); - if (r) { - stepModified.push(r); - } - } - - // ---------------------------- END PRODUCE VIEW ZONES - - - // ---------------------------- EMIT MINIMAL VIEW ZONES - - // [CANCEL & EMIT] Try to cancel view zones out - let stepOriginalIndex = 0; - let stepModifiedIndex = 0; - - stepOriginal = stepOriginal.sort(sortMyViewZones); - stepModified = stepModified.sort(sortMyViewZones); - - while (stepOriginalIndex < stepOriginal.length && stepModifiedIndex < stepModified.length) { - const original = stepOriginal[stepOriginalIndex]; - const modified = stepModified[stepModifiedIndex]; - - const originalDelta = original.afterLineNumber - originalEquivalentLineNumber; - const modifiedDelta = modified.afterLineNumber - modifiedEquivalentLineNumber; - - if (originalDelta < modifiedDelta) { - addAndCombineIfPossible(result.original, original); - stepOriginalIndex++; - } else if (modifiedDelta < originalDelta) { - addAndCombineIfPossible(result.modified, modified); - stepModifiedIndex++; - } else if (original.shouldNotShrink) { - addAndCombineIfPossible(result.original, original); - stepOriginalIndex++; - } else if (modified.shouldNotShrink) { - addAndCombineIfPossible(result.modified, modified); - stepModifiedIndex++; - } else { - if (original.heightInLines >= modified.heightInLines) { - // modified view zone gets removed - original.heightInLines -= modified.heightInLines; - stepModifiedIndex++; - } else { - // original view zone gets removed - modified.heightInLines -= original.heightInLines; - stepOriginalIndex++; - } - } - } - - // [EMIT] Remaining original view zones - while (stepOriginalIndex < stepOriginal.length) { - addAndCombineIfPossible(result.original, stepOriginal[stepOriginalIndex]); - stepOriginalIndex++; - } - - // [EMIT] Remaining modified view zones - while (stepModifiedIndex < stepModified.length) { - addAndCombineIfPossible(result.modified, stepModified[stepModifiedIndex]); - stepModifiedIndex++; - } - - // ---------------------------- END EMIT MINIMAL VIEW ZONES - } - - return { - original: ViewZonesComputer._ensureDomNodes(result.original), - modified: ViewZonesComputer._ensureDomNodes(result.modified), - }; - } - - private static _ensureDomNodes(zones: IMyViewZone[]): IMyViewZone[] { - return zones.map((z) => { - if (!z.domNode) { - z.domNode = createFakeLinesDiv(); - } - return z; - }); - } - - protected abstract _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null; - - protected abstract _produceOriginalFromDiff(lineChange: ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null; - - protected abstract _produceModifiedFromDiff(lineChange: ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null; -} - -function createDecoration(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number, options: ModelDecorationOptions) { - return { - range: new Range(startLineNumber, startColumn, endLineNumber, endColumn), - options: options - }; -} - -const enum DiffEditorLineClasses { - Insert = 'line-insert', - Delete = 'line-delete' -} - -const DECORATIONS = { - - arrowRevertChange: ModelDecorationOptions.register({ - description: 'diff-editor-arrow-revert-change', - glyphMarginHoverMessage: new MarkdownString(undefined, { isTrusted: true, supportThemeIcons: true }).appendMarkdown(nls.localize('revertChangeHoverMessage', 'Click to revert change')), - glyphMarginClassName: 'arrow-revert-change ' + ThemeIcon.asClassName(Codicon.arrowRight), - zIndex: 10001, - }), - - charDelete: ModelDecorationOptions.register({ - description: 'diff-editor-char-delete', - className: 'char-delete' - }), - charDeleteWholeLine: ModelDecorationOptions.register({ - description: 'diff-editor-char-delete-whole-line', - className: 'char-delete', - isWholeLine: true - }), - - charInsert: ModelDecorationOptions.register({ - description: 'diff-editor-char-insert', - className: 'char-insert' - }), - charInsertWholeLine: ModelDecorationOptions.register({ - description: 'diff-editor-char-insert-whole-line', - className: 'char-insert', - isWholeLine: true - }), - - lineInsert: ModelDecorationOptions.register({ - description: 'diff-editor-line-insert', - className: DiffEditorLineClasses.Insert, - marginClassName: 'gutter-insert', - isWholeLine: true - }), - lineInsertWithSign: ModelDecorationOptions.register({ - description: 'diff-editor-line-insert-with-sign', - className: DiffEditorLineClasses.Insert, - linesDecorationsClassName: 'insert-sign ' + ThemeIcon.asClassName(diffInsertIcon), - marginClassName: 'gutter-insert', - isWholeLine: true - }), - - lineDelete: ModelDecorationOptions.register({ - description: 'diff-editor-line-delete', - className: DiffEditorLineClasses.Delete, - marginClassName: 'gutter-delete', - isWholeLine: true - }), - lineDeleteWithSign: ModelDecorationOptions.register({ - description: 'diff-editor-line-delete-with-sign', - className: DiffEditorLineClasses.Delete, - linesDecorationsClassName: 'delete-sign ' + ThemeIcon.asClassName(diffRemoveIcon), - marginClassName: 'gutter-delete', - isWholeLine: true - - }), - lineDeleteMargin: ModelDecorationOptions.register({ - description: 'diff-editor-line-delete-margin', - marginClassName: 'gutter-delete', - }) - -}; - -class DiffEditorWidgetSideBySide extends DiffEditorWidgetStyle implements IVerticalSashLayoutProvider { - - static readonly MINIMUM_EDITOR_WIDTH = 100; - - private _disableSash: boolean; - private readonly _sash: Sash; - private _defaultRatio: number; - private _sashRatio: number | null; - private _sashPosition: number | null; - private _startSashPosition: number | null; - - constructor(dataSource: IDataSource, enableSplitViewResizing: boolean, defaultSashRatio: number) { - super(dataSource); - - this._disableSash = (enableSplitViewResizing === false); - this._defaultRatio = defaultSashRatio; - this._sashRatio = null; - this._sashPosition = null; - this._startSashPosition = null; - this._sash = this._register(new Sash(this._dataSource.getContainerDomNode(), this, { orientation: Orientation.VERTICAL })); - - if (this._disableSash) { - this._sash.state = SashState.Disabled; - } - - this._sash.onDidStart(() => this._onSashDragStart()); - this._sash.onDidChange((e: ISashEvent) => this._onSashDrag(e)); - this._sash.onDidEnd(() => this._onSashDragEnd()); - this._sash.onDidReset(() => this._onSashReset()); - } - - public setEnableSplitViewResizing(enableSplitViewResizing: boolean, defaultRatio: number): void { - this._defaultRatio = defaultRatio; - const newDisableSash = (enableSplitViewResizing === false); - if (this._disableSash !== newDisableSash) { - this._disableSash = newDisableSash; - this._sash.state = this._disableSash ? SashState.Disabled : SashState.Enabled; - } - } - - public layout(sashRatio: number | null = this._sashRatio || this._defaultRatio): number { - const w = this._dataSource.getWidth(); - const contentWidth = w - (this._dataSource.getOptions().renderOverviewRuler ? DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH : 0); - - let sashPosition = Math.floor((sashRatio || this._defaultRatio) * contentWidth); - const midPoint = Math.floor(this._defaultRatio * contentWidth); - - sashPosition = this._disableSash ? midPoint : sashPosition || midPoint; - - if (contentWidth > DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH * 2) { - if (sashPosition < DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH) { - sashPosition = DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH; - } - - if (sashPosition > contentWidth - DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH) { - sashPosition = contentWidth - DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH; - } - } else { - sashPosition = midPoint; - } - - if (this._sashPosition !== sashPosition) { - this._sashPosition = sashPosition; - } - this._sash.layout(); - - return this._sashPosition; - } - - private _onSashDragStart(): void { - this._startSashPosition = this._sashPosition!; - } - - private _onSashDrag(e: ISashEvent): void { - const w = this._dataSource.getWidth(); - const contentWidth = w - (this._dataSource.getOptions().renderOverviewRuler ? DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH : 0); - const sashPosition = this.layout((this._startSashPosition! + (e.currentX - e.startX)) / contentWidth); - - this._sashRatio = sashPosition / contentWidth; - - this._dataSource.relayoutEditors(); - } - - private _onSashDragEnd(): void { - this._sash.layout(); - } - - private _onSashReset(): void { - this._sashRatio = this._defaultRatio; - this._dataSource.relayoutEditors(); - this._sash.layout(); - } - - public getVerticalSashTop(sash: Sash): number { - return 0; - } - - public getVerticalSashLeft(sash: Sash): number { - return this._sashPosition!; - } - - public getVerticalSashHeight(sash: Sash): number { - return this._dataSource.getHeight(); - } - - override setBoundarySashes(sashes: IBoundarySashes) { - this._sash.orthogonalEndSash = sashes.bottom; - } - - protected _getViewZones(lineChanges: ILineChange[], originalForeignVZ: IEditorWhitespace[], modifiedForeignVZ: IEditorWhitespace[]): IEditorsZones { - const originalEditor = this._dataSource.getOriginalEditor(); - const modifiedEditor = this._dataSource.getModifiedEditor(); - const c = new SideBySideViewZonesComputer(lineChanges, originalForeignVZ, modifiedForeignVZ, originalEditor, modifiedEditor); - return c.getViewZones(); - } - - protected _getOriginalEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean): IEditorDiffDecorations { - const originalEditor = this._dataSource.getOriginalEditor(); - const overviewZoneColor = String(this._removeColor); - - const result: IEditorDiffDecorations = { - decorations: [], - overviewZones: [] - }; - - const originalModel = originalEditor.getModel()!; - const originalViewModel = originalEditor._getViewModel()!; - - for (const lineChange of lineChanges) { - - if (isChangeOrDelete(lineChange)) { - result.decorations.push({ - range: new Range(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER), - options: (renderIndicators ? DECORATIONS.lineDeleteWithSign : DECORATIONS.lineDelete) - }); - if (!isChangeOrInsert(lineChange) || !lineChange.charChanges) { - result.decorations.push(createDecoration(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charDeleteWholeLine)); - } - - const viewRange = getViewRange(originalModel, originalViewModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber); - result.overviewZones.push(new OverviewRulerZone(viewRange.startLineNumber, viewRange.endLineNumber, /*use endLineNumber*/0, overviewZoneColor)); - - if (lineChange.charChanges) { - for (const charChange of lineChange.charChanges) { - if (isCharChangeOrDelete(charChange)) { - if (ignoreTrimWhitespace) { - for (let lineNumber = charChange.originalStartLineNumber; lineNumber <= charChange.originalEndLineNumber; lineNumber++) { - let startColumn: number; - let endColumn: number; - if (lineNumber === charChange.originalStartLineNumber) { - startColumn = charChange.originalStartColumn; - } else { - startColumn = originalModel.getLineFirstNonWhitespaceColumn(lineNumber); - } - if (lineNumber === charChange.originalEndLineNumber) { - endColumn = charChange.originalEndColumn; - } else { - endColumn = originalModel.getLineLastNonWhitespaceColumn(lineNumber); - } - result.decorations.push(createDecoration(lineNumber, startColumn, lineNumber, endColumn, DECORATIONS.charDelete)); - } - } else { - result.decorations.push(createDecoration(charChange.originalStartLineNumber, charChange.originalStartColumn, charChange.originalEndLineNumber, charChange.originalEndColumn, DECORATIONS.charDelete)); - } - } - } - } - } - } - - return result; - } - - protected _getModifiedEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, renderMarginRevertIcon: boolean): IEditorDiffDecorations { - const modifiedEditor = this._dataSource.getModifiedEditor(); - const overviewZoneColor = String(this._insertColor); - - const result: IEditorDiffDecorations = { - decorations: [], - overviewZones: [] - }; - - const modifiedModel = modifiedEditor.getModel()!; - const modifiedViewModel = modifiedEditor._getViewModel()!; - - for (const lineChange of lineChanges) { - - // Arrows for reverting changes. - if (renderMarginRevertIcon) { - if (lineChange.modifiedEndLineNumber > 0) { - result.decorations.push({ - range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedStartLineNumber, 1), - options: DECORATIONS.arrowRevertChange - }); - } else { - const viewZone = zones.modified.find(z => z.afterLineNumber === lineChange.modifiedStartLineNumber); - if (viewZone) { - viewZone.marginDomNode = createViewZoneMarginArrow(); - } - } - } - - if (isChangeOrInsert(lineChange)) { - - result.decorations.push({ - range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER), - options: (renderIndicators ? DECORATIONS.lineInsertWithSign : DECORATIONS.lineInsert) - }); - if (!isChangeOrDelete(lineChange) || !lineChange.charChanges) { - result.decorations.push(createDecoration(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charInsertWholeLine)); - } - - const viewRange = getViewRange(modifiedModel, modifiedViewModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber); - result.overviewZones.push(new OverviewRulerZone(viewRange.startLineNumber, viewRange.endLineNumber,/*use endLineNumber*/0, overviewZoneColor)); - - if (lineChange.charChanges) { - for (const charChange of lineChange.charChanges) { - if (isCharChangeOrInsert(charChange)) { - if (ignoreTrimWhitespace) { - for (let lineNumber = charChange.modifiedStartLineNumber; lineNumber <= charChange.modifiedEndLineNumber; lineNumber++) { - let startColumn: number; - let endColumn: number; - if (lineNumber === charChange.modifiedStartLineNumber) { - startColumn = charChange.modifiedStartColumn; - } else { - startColumn = modifiedModel.getLineFirstNonWhitespaceColumn(lineNumber); - } - if (lineNumber === charChange.modifiedEndLineNumber) { - endColumn = charChange.modifiedEndColumn; - } else { - endColumn = modifiedModel.getLineLastNonWhitespaceColumn(lineNumber); - } - result.decorations.push(createDecoration(lineNumber, startColumn, lineNumber, endColumn, DECORATIONS.charInsert)); - } - } else { - result.decorations.push(createDecoration(charChange.modifiedStartLineNumber, charChange.modifiedStartColumn, charChange.modifiedEndLineNumber, charChange.modifiedEndColumn, DECORATIONS.charInsert)); - } - } - } - } - - } - } - return result; - } -} - -class SideBySideViewZonesComputer extends ViewZonesComputer { - - constructor( - lineChanges: ILineChange[], - originalForeignVZ: IEditorWhitespace[], - modifiedForeignVZ: IEditorWhitespace[], - originalEditor: CodeEditorWidget, - modifiedEditor: CodeEditorWidget, - ) { - super(lineChanges, originalForeignVZ, modifiedForeignVZ, originalEditor, modifiedEditor); - } - - protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null { - return null; - } - - protected _produceOriginalFromDiff(lineChange: ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null { - if (lineChangeModifiedLength > lineChangeOriginalLength) { - return { - afterLineNumber: Math.max(lineChange.originalStartLineNumber, lineChange.originalEndLineNumber), - heightInLines: (lineChangeModifiedLength - lineChangeOriginalLength), - domNode: null - }; - } - return null; - } - - protected _produceModifiedFromDiff(lineChange: ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null { - if (lineChangeOriginalLength > lineChangeModifiedLength) { - return { - afterLineNumber: Math.max(lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber), - heightInLines: (lineChangeOriginalLength - lineChangeModifiedLength), - domNode: null - }; - } - return null; - } -} - -class DiffEditorWidgetInline extends DiffEditorWidgetStyle { - - private _decorationsLeft: number; - - constructor(dataSource: IDataSource, enableSplitViewResizing: boolean) { - super(dataSource); - - this._decorationsLeft = dataSource.getOriginalEditor().getLayoutInfo().decorationsLeft; - - this._register(dataSource.getOriginalEditor().onDidLayoutChange((layoutInfo: EditorLayoutInfo) => { - if (this._decorationsLeft !== layoutInfo.decorationsLeft) { - this._decorationsLeft = layoutInfo.decorationsLeft; - dataSource.relayoutEditors(); - } - })); - } - - public setEnableSplitViewResizing(enableSplitViewResizing: boolean): void { - // Nothing to do.. - } - - protected _getViewZones(lineChanges: ILineChange[], originalForeignVZ: IEditorWhitespace[], modifiedForeignVZ: IEditorWhitespace[], renderIndicators: boolean): IEditorsZones { - const originalEditor = this._dataSource.getOriginalEditor(); - const modifiedEditor = this._dataSource.getModifiedEditor(); - const computer = new InlineViewZonesComputer(lineChanges, originalForeignVZ, modifiedForeignVZ, originalEditor, modifiedEditor, renderIndicators); - return computer.getViewZones(); - } - - protected _getOriginalEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean): IEditorDiffDecorations { - const overviewZoneColor = String(this._removeColor); - - const result: IEditorDiffDecorations = { - decorations: [], - overviewZones: [] - }; - - const originalEditor = this._dataSource.getOriginalEditor(); - const originalModel = originalEditor.getModel()!; - const originalViewModel = originalEditor._getViewModel()!; - let zoneIndex = 0; - - for (const lineChange of lineChanges) { - - // Add overview zones in the overview ruler - if (isChangeOrDelete(lineChange)) { - result.decorations.push({ - range: new Range(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER), - options: DECORATIONS.lineDeleteMargin - }); - - while (zoneIndex < zones.modified.length) { - const zone = zones.modified[zoneIndex]; - if (zone.diff && zone.diff.originalStartLineNumber >= lineChange.originalStartLineNumber) { - break; - } - zoneIndex++; - } - - let zoneHeightInLines = 0; - if (zoneIndex < zones.modified.length) { - const zone = zones.modified[zoneIndex]; - if ( - zone.diff - && zone.diff.originalStartLineNumber === lineChange.originalStartLineNumber - && zone.diff.originalEndLineNumber === lineChange.originalEndLineNumber - && zone.diff.modifiedStartLineNumber === lineChange.modifiedStartLineNumber - && zone.diff.modifiedEndLineNumber === lineChange.modifiedEndLineNumber - ) { - zoneHeightInLines = zone.heightInLines; - } - } - - const viewRange = getViewRange(originalModel, originalViewModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber); - result.overviewZones.push(new OverviewRulerZone(viewRange.startLineNumber, viewRange.endLineNumber, zoneHeightInLines, overviewZoneColor)); - } - } - - return result; - } - - protected _getModifiedEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, renderMarginRevertIcon: boolean): IEditorDiffDecorations { - const modifiedEditor = this._dataSource.getModifiedEditor(); - const overviewZoneColor = String(this._insertColor); - - const result: IEditorDiffDecorations = { - decorations: [], - overviewZones: [] - }; - - const modifiedModel = modifiedEditor.getModel()!; - const modifiedViewModel = modifiedEditor._getViewModel()!; - - for (const lineChange of lineChanges) { - - // Add decorations & overview zones - if (isChangeOrInsert(lineChange)) { - result.decorations.push({ - range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER), - options: (renderIndicators ? DECORATIONS.lineInsertWithSign : DECORATIONS.lineInsert) - }); - - const viewRange = getViewRange(modifiedModel, modifiedViewModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber); - result.overviewZones.push(new OverviewRulerZone(viewRange.startLineNumber, viewRange.endLineNumber, /*use endLineNumber*/0, overviewZoneColor)); - - if (lineChange.charChanges) { - for (const charChange of lineChange.charChanges) { - if (isCharChangeOrInsert(charChange)) { - if (ignoreTrimWhitespace) { - for (let lineNumber = charChange.modifiedStartLineNumber; lineNumber <= charChange.modifiedEndLineNumber; lineNumber++) { - let startColumn: number; - let endColumn: number; - if (lineNumber === charChange.modifiedStartLineNumber) { - startColumn = charChange.modifiedStartColumn; - } else { - startColumn = modifiedModel.getLineFirstNonWhitespaceColumn(lineNumber); - } - if (lineNumber === charChange.modifiedEndLineNumber) { - endColumn = charChange.modifiedEndColumn; - } else { - endColumn = modifiedModel.getLineLastNonWhitespaceColumn(lineNumber); - } - result.decorations.push(createDecoration(lineNumber, startColumn, lineNumber, endColumn, DECORATIONS.charInsert)); - } - } else { - result.decorations.push(createDecoration(charChange.modifiedStartLineNumber, charChange.modifiedStartColumn, charChange.modifiedEndLineNumber, charChange.modifiedEndColumn, DECORATIONS.charInsert)); - } - } - } - } else { - result.decorations.push(createDecoration(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charInsertWholeLine)); - } - } - } - - return result; - } - - public layout(): number { - // An editor should not be smaller than 5px - return Math.max(5, this._decorationsLeft); - } - -} - -interface InlineModifiedViewZone extends IMyViewZone { - shouldNotShrink: boolean; - afterLineNumber: number; - heightInLines: number; - minWidthInPx: number; - domNode: HTMLElement; - marginDomNode: HTMLElement; - diff: IDiffLinesChange; -} - -class InlineViewZonesComputer extends ViewZonesComputer { - - private readonly _originalModel: ITextModel; - private readonly _renderIndicators: boolean; - private readonly _pendingLineChange: ILineChange[]; - private readonly _pendingViewZones: InlineModifiedViewZone[]; - private readonly _lineBreaksComputer: ILineBreaksComputer; - - constructor( - lineChanges: ILineChange[], - originalForeignVZ: IEditorWhitespace[], - modifiedForeignVZ: IEditorWhitespace[], - originalEditor: CodeEditorWidget, - modifiedEditor: CodeEditorWidget, - renderIndicators: boolean - ) { - super(lineChanges, originalForeignVZ, modifiedForeignVZ, originalEditor, modifiedEditor); - this._originalModel = originalEditor.getModel()!; - this._renderIndicators = renderIndicators; - this._pendingLineChange = []; - this._pendingViewZones = []; - this._lineBreaksComputer = this._modifiedEditor._getViewModel()!.createLineBreaksComputer(); - } - - public override getViewZones(): IEditorsZones { - const result = super.getViewZones(); - this._finalize(result); - return result; - } - - protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null { - const result = document.createElement('div'); - result.className = 'inline-added-margin-view-zone'; - return result; - } - - protected _produceOriginalFromDiff(lineChange: ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null { - const marginDomNode = document.createElement('div'); - marginDomNode.className = 'inline-added-margin-view-zone'; - - return { - afterLineNumber: Math.max(lineChange.originalStartLineNumber, lineChange.originalEndLineNumber), - heightInLines: lineChangeModifiedLength, - domNode: document.createElement('div'), - marginDomNode: marginDomNode - }; - } - - protected _produceModifiedFromDiff(lineChange: ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null { - const domNode = document.createElement('div'); - domNode.className = `view-lines line-delete ${MOUSE_CURSOR_TEXT_CSS_CLASS_NAME}`; - - const marginDomNode = document.createElement('div'); - marginDomNode.className = 'inline-deleted-margin-view-zone'; - - const viewZone: InlineModifiedViewZone = { - shouldNotShrink: true, - afterLineNumber: (lineChange.modifiedEndLineNumber === 0 ? lineChange.modifiedStartLineNumber : lineChange.modifiedStartLineNumber - 1), - heightInLines: lineChangeOriginalLength, - minWidthInPx: 0, - domNode: domNode, - marginDomNode: marginDomNode, - diff: { - originalStartLineNumber: lineChange.originalStartLineNumber, - originalEndLineNumber: lineChange.originalEndLineNumber, - modifiedStartLineNumber: lineChange.modifiedStartLineNumber, - modifiedEndLineNumber: lineChange.modifiedEndLineNumber, - originalModel: this._originalModel, - viewLineCounts: null, - } - }; - - for (let lineNumber = lineChange.originalStartLineNumber; lineNumber <= lineChange.originalEndLineNumber; lineNumber++) { - this._lineBreaksComputer.addRequest(this._originalModel.getLineContent(lineNumber), null, null); - } - - this._pendingLineChange.push(lineChange); - this._pendingViewZones.push(viewZone); - - return viewZone; - } - - private _finalize(result: IEditorsZones): void { - const modifiedEditorOptions = this._modifiedEditor.getOptions(); - const tabSize = this._modifiedEditor.getModel()!.getOptions().tabSize; - const fontInfo = modifiedEditorOptions.get(EditorOption.fontInfo); - const disableMonospaceOptimizations = modifiedEditorOptions.get(EditorOption.disableMonospaceOptimizations); - const typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth; - const scrollBeyondLastColumn = modifiedEditorOptions.get(EditorOption.scrollBeyondLastColumn); - const mightContainNonBasicASCII = this._originalModel.mightContainNonBasicASCII(); - const mightContainRTL = this._originalModel.mightContainRTL(); - const lineHeight = modifiedEditorOptions.get(EditorOption.lineHeight); - const layoutInfo = modifiedEditorOptions.get(EditorOption.layoutInfo); - const lineDecorationsWidth = layoutInfo.decorationsWidth; - const stopRenderingLineAfter = modifiedEditorOptions.get(EditorOption.stopRenderingLineAfter); - const renderWhitespace = modifiedEditorOptions.get(EditorOption.renderWhitespace); - const renderControlCharacters = modifiedEditorOptions.get(EditorOption.renderControlCharacters); - const fontLigatures = modifiedEditorOptions.get(EditorOption.fontLigatures); - - const lineBreaks = this._lineBreaksComputer.finalize(); - let lineBreakIndex = 0; - - for (let i = 0; i < this._pendingLineChange.length; i++) { - const lineChange = this._pendingLineChange[i]; - const viewZone = this._pendingViewZones[i]; - const domNode = viewZone.domNode; - applyFontInfo(domNode, fontInfo); - - const marginDomNode = viewZone.marginDomNode; - applyFontInfo(marginDomNode, fontInfo); - - const decorations: InlineDecoration[] = []; - if (lineChange.charChanges) { - for (const charChange of lineChange.charChanges) { - if (isCharChangeOrDelete(charChange)) { - decorations.push(new InlineDecoration( - new Range(charChange.originalStartLineNumber, charChange.originalStartColumn, charChange.originalEndLineNumber, charChange.originalEndColumn), - 'char-delete', - InlineDecorationType.Regular - )); - } - } - } - const hasCharChanges = (decorations.length > 0); - - const sb = new StringBuilder(10000); - let maxCharsPerLine = 0; - let renderedLineCount = 0; - let viewLineCounts: number[] | null = null; - for (let lineNumber = lineChange.originalStartLineNumber; lineNumber <= lineChange.originalEndLineNumber; lineNumber++) { - const lineIndex = lineNumber - lineChange.originalStartLineNumber; - const lineTokens = this._originalModel.tokenization.getLineTokens(lineNumber); - const lineContent = lineTokens.getLineContent(); - const lineBreakData = lineBreaks[lineBreakIndex++]; - const actualDecorations = LineDecoration.filter(decorations, lineNumber, 1, lineContent.length + 1); - - if (lineBreakData) { - let lastBreakOffset = 0; - for (const breakOffset of lineBreakData.breakOffsets) { - const viewLineTokens = lineTokens.sliceAndInflate(lastBreakOffset, breakOffset, 0); - const viewLineContent = lineContent.substring(lastBreakOffset, breakOffset); - maxCharsPerLine = Math.max(maxCharsPerLine, this._renderOriginalLine( - renderedLineCount++, - viewLineContent, - viewLineTokens, - LineDecoration.extractWrapped(actualDecorations, lastBreakOffset, breakOffset), - hasCharChanges, - mightContainNonBasicASCII, - mightContainRTL, - fontInfo, - disableMonospaceOptimizations, - lineHeight, - lineDecorationsWidth, - stopRenderingLineAfter, - renderWhitespace, - renderControlCharacters, - fontLigatures, - tabSize, - sb, - marginDomNode - )); - lastBreakOffset = breakOffset; - } - if (!viewLineCounts) { - viewLineCounts = []; - } - // make sure all lines before this one have an entry in `viewLineCounts` - while (viewLineCounts.length < lineIndex) { - viewLineCounts[viewLineCounts.length] = 1; - } - viewLineCounts[lineIndex] = lineBreakData.breakOffsets.length; - viewZone.heightInLines += (lineBreakData.breakOffsets.length - 1); - const marginDomNode2 = document.createElement('div'); - marginDomNode2.className = 'gutter-delete'; - result.original.push({ - afterLineNumber: lineNumber, - afterColumn: 0, - heightInLines: lineBreakData.breakOffsets.length - 1, - domNode: createFakeLinesDiv(), - marginDomNode: marginDomNode2 - }); - } else { - maxCharsPerLine = Math.max(maxCharsPerLine, this._renderOriginalLine( - renderedLineCount++, - lineContent, - lineTokens, - actualDecorations, - hasCharChanges, - mightContainNonBasicASCII, - mightContainRTL, - fontInfo, - disableMonospaceOptimizations, - lineHeight, - lineDecorationsWidth, - stopRenderingLineAfter, - renderWhitespace, - renderControlCharacters, - fontLigatures, - tabSize, - sb, - marginDomNode - )); - } - } - maxCharsPerLine += scrollBeyondLastColumn; - - const html = sb.build(); - const trustedhtml = diffEditorWidgetTtPolicy ? diffEditorWidgetTtPolicy.createHTML(html) : html; - domNode.innerHTML = trustedhtml as string; - viewZone.minWidthInPx = (maxCharsPerLine * typicalHalfwidthCharacterWidth); - - if (viewLineCounts) { - // make sure all lines have an entry in `viewLineCounts` - const cnt = lineChange.originalEndLineNumber - lineChange.originalStartLineNumber; - while (viewLineCounts.length <= cnt) { - viewLineCounts[viewLineCounts.length] = 1; - } - } - viewZone.diff.viewLineCounts = viewLineCounts; - } - - result.original.sort((a, b) => { - return a.afterLineNumber - b.afterLineNumber; - }); - } - - private _renderOriginalLine( - renderedLineCount: number, - lineContent: string, - lineTokens: IViewLineTokens, - decorations: LineDecoration[], - hasCharChanges: boolean, - mightContainNonBasicASCII: boolean, - mightContainRTL: boolean, - fontInfo: FontInfo, - disableMonospaceOptimizations: boolean, - lineHeight: number, - lineDecorationsWidth: number, - stopRenderingLineAfter: number, - renderWhitespace: 'selection' | 'none' | 'boundary' | 'trailing' | 'all', - renderControlCharacters: boolean, - fontLigatures: string, - tabSize: number, - sb: StringBuilder, - marginDomNode: HTMLElement - ): number { - - sb.appendString('
'); - - const isBasicASCII = ViewLineRenderingData.isBasicASCII(lineContent, mightContainNonBasicASCII); - const containsRTL = ViewLineRenderingData.containsRTL(lineContent, isBasicASCII, mightContainRTL); - const output = renderViewLine(new RenderLineInput( - (fontInfo.isMonospace && !disableMonospaceOptimizations), - fontInfo.canUseHalfwidthRightwardsArrow, - lineContent, - false, - isBasicASCII, - containsRTL, - 0, - lineTokens, - decorations, - tabSize, - 0, - fontInfo.spaceWidth, - fontInfo.middotWidth, - fontInfo.wsmiddotWidth, - stopRenderingLineAfter, - renderWhitespace, - renderControlCharacters, - fontLigatures !== EditorFontLigatures.OFF, - null // Send no selections, original line cannot be selected - ), sb); - - sb.appendString('
'); - - if (this._renderIndicators) { - const marginElement = document.createElement('div'); - marginElement.className = `delete-sign ${ThemeIcon.asClassName(diffRemoveIcon)}`; - marginElement.setAttribute('style', `position:absolute;top:${renderedLineCount * lineHeight}px;width:${lineDecorationsWidth}px;height:${lineHeight}px;right:0;`); - marginDomNode.appendChild(marginElement); - } - - return output.characterMapping.getHorizontalOffset(output.characterMapping.length); - } -} - -function validateDiffWordWrap(value: 'off' | 'on' | 'inherit' | undefined, defaultValue: 'off' | 'on' | 'inherit'): 'off' | 'on' | 'inherit' { - return validateStringSetOption<'off' | 'on' | 'inherit'>(value, defaultValue, ['off', 'on', 'inherit']); -} - -function isChangeOrInsert(lineChange: ILineChange): boolean { - return lineChange.modifiedEndLineNumber > 0; -} - -function isChangeOrDelete(lineChange: ILineChange): boolean { - return lineChange.originalEndLineNumber > 0; -} - -function isCharChangeOrInsert(charChange: ICharChange): boolean { - if (charChange.modifiedStartLineNumber === charChange.modifiedEndLineNumber) { - return charChange.modifiedEndColumn - charChange.modifiedStartColumn > 0; - } - return charChange.modifiedEndLineNumber - charChange.modifiedStartLineNumber > 0; -} - -function isCharChangeOrDelete(charChange: ICharChange): boolean { - if (charChange.originalStartLineNumber === charChange.originalEndLineNumber) { - return charChange.originalEndColumn - charChange.originalStartColumn > 0; - } - return charChange.originalEndLineNumber - charChange.originalStartLineNumber > 0; -} - -function createFakeLinesDiv(): HTMLElement { - const r = document.createElement('div'); - r.className = 'diagonal-fill'; - return r; -} - -function createViewZoneMarginArrow(): HTMLElement { - const arrow = document.createElement('div'); - arrow.className = 'arrow-revert-change ' + ThemeIcon.asClassName(Codicon.arrowRight); - return dom.$('div', {}, arrow); -} - -function getViewRange(model: ITextModel, viewModel: IViewModel, startLineNumber: number, endLineNumber: number): Range { - const lineCount = model.getLineCount(); - startLineNumber = Math.min(lineCount, Math.max(1, startLineNumber)); - endLineNumber = Math.min(lineCount, Math.max(1, endLineNumber)); - return viewModel.coordinatesConverter.convertModelRangeToViewRange(new Range( - startLineNumber, model.getLineMinColumn(startLineNumber), - endLineNumber, model.getLineMaxColumn(endLineNumber) - )); -} - -function validateDiffEditorOptions(options: Readonly, defaults: ValidDiffEditorBaseOptions): ValidDiffEditorBaseOptions { - return { - enableSplitViewResizing: validateBooleanOption(options.enableSplitViewResizing, defaults.enableSplitViewResizing), - splitViewDefaultRatio: clampedFloat(options.splitViewDefaultRatio, 0.5, 0.1, 0.9), - renderSideBySide: validateBooleanOption(options.renderSideBySide, defaults.renderSideBySide), - renderMarginRevertIcon: validateBooleanOption(options.renderMarginRevertIcon, defaults.renderMarginRevertIcon), - maxComputationTime: clampedInt(options.maxComputationTime, defaults.maxComputationTime, 0, Constants.MAX_SAFE_SMALL_INTEGER), - maxFileSize: clampedInt(options.maxFileSize, defaults.maxFileSize, 0, Constants.MAX_SAFE_SMALL_INTEGER), - ignoreTrimWhitespace: validateBooleanOption(options.ignoreTrimWhitespace, defaults.ignoreTrimWhitespace), - renderIndicators: validateBooleanOption(options.renderIndicators, defaults.renderIndicators), - originalEditable: validateBooleanOption(options.originalEditable, defaults.originalEditable), - diffCodeLens: validateBooleanOption(options.diffCodeLens, defaults.diffCodeLens), - renderOverviewRuler: validateBooleanOption(options.renderOverviewRuler, defaults.renderOverviewRuler), - diffWordWrap: validateDiffWordWrap(options.diffWordWrap, defaults.diffWordWrap), - diffAlgorithm: validateStringSetOption(options.diffAlgorithm, defaults.diffAlgorithm, ['legacy', 'advanced'], { 'smart': 'legacy', 'experimental': 'advanced' }), - accessibilityVerbose: validateBooleanOption(options.accessibilityVerbose, defaults.accessibilityVerbose), - hideUnchangedRegions: { - enabled: false, - contextLineCount: 0, - minimumLineCount: 0, - revealLineCount: 0, - }, - experimental: { - showEmptyDecorations: false, - showMoves: false, - }, - isInEmbeddedEditor: validateBooleanOption(options.isInEmbeddedEditor, defaults.isInEmbeddedEditor), - onlyShowAccessibleDiffViewer: false, - renderSideBySideInlineBreakpoint: 0, - useInlineViewWhenSpaceIsLimited: false, - }; -} - -function changedDiffEditorOptions(a: ValidDiffEditorBaseOptions, b: ValidDiffEditorBaseOptions) { - return { - enableSplitViewResizing: (a.enableSplitViewResizing !== b.enableSplitViewResizing), - renderSideBySide: (a.renderSideBySide !== b.renderSideBySide), - renderMarginRevertIcon: (a.renderMarginRevertIcon !== b.renderMarginRevertIcon), - maxComputationTime: (a.maxComputationTime !== b.maxComputationTime), - maxFileSize: (a.maxFileSize !== b.maxFileSize), - ignoreTrimWhitespace: (a.ignoreTrimWhitespace !== b.ignoreTrimWhitespace), - renderIndicators: (a.renderIndicators !== b.renderIndicators), - originalEditable: (a.originalEditable !== b.originalEditable), - diffCodeLens: (a.diffCodeLens !== b.diffCodeLens), - renderOverviewRuler: (a.renderOverviewRuler !== b.renderOverviewRuler), - diffWordWrap: (a.diffWordWrap !== b.diffWordWrap), - diffAlgorithm: (a.diffAlgorithm !== b.diffAlgorithm), - accessibilityVerbose: (a.accessibilityVerbose !== b.accessibilityVerbose), - }; -} - -registerThemingParticipant((theme, collector) => { - const diffDiagonalFillColor = theme.getColor(diffDiagonalFill); - collector.addRule(` - .monaco-editor .diagonal-fill { - background-image: linear-gradient( - -45deg, - ${diffDiagonalFillColor} 12.5%, - #0000 12.5%, #0000 50%, - ${diffDiagonalFillColor} 50%, ${diffDiagonalFillColor} 62.5%, - #0000 62.5%, #0000 100% - ); - background-size: 8px 8px; - } - `); -}); diff --git a/src/vs/editor/browser/widget/diffEditorWidget2/accessibleDiffViewer.ts b/src/vs/editor/browser/widget/diffEditorWidget2/accessibleDiffViewer.ts index 3f45fae3b99..3b2f9b3204a 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget2/accessibleDiffViewer.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget2/accessibleDiffViewer.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { addDisposableListener, addStandardDisposableListener, reset } from 'vs/base/browser/dom'; +import { createTrustedTypesPolicy } from 'vs/base/browser/trustedTypes'; import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement'; import { Action } from 'vs/base/common/actions'; @@ -16,7 +17,6 @@ import { ThemeIcon } from 'vs/base/common/themables'; import { applyFontInfo } from 'vs/editor/browser/config/domFontInfo'; import { DiffEditorEditors } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorEditors'; import { applyStyle } from 'vs/editor/browser/widget/diffEditorWidget2/utils'; -import { DiffReview } from 'vs/editor/browser/widget/diffReview'; import { EditorFontLigatures, EditorOption, IComputedEditorOptions } from 'vs/editor/common/config/editorOptions'; import { LineRange } from 'vs/editor/common/core/lineRange'; import { OffsetRange } from 'vs/editor/common/core/offsetRange'; @@ -39,6 +39,8 @@ const accessibleDiffViewerRemoveIcon = registerIcon('diff-review-remove', Codico const accessibleDiffViewerCloseIcon = registerIcon('diff-review-close', Codicon.close, localize('accessibleDiffViewerCloseIcon', 'Icon for \'Close\' in accessible diff viewer.')); export class AccessibleDiffViewer extends Disposable { + public static _ttPolicy = createTrustedTypesPolicy('diffReview', { createHTML: value => value }); + constructor( private readonly _parentNode: HTMLElement, private readonly _visible: IObservable, @@ -590,15 +592,15 @@ class View extends Disposable { let lineContent: string; if (item.modifiedLineNumber !== undefined) { let html: string | TrustedHTML = this._getLineHtml(modifiedModel, modifiedOptions, modifiedModelOpts.tabSize, item.modifiedLineNumber, this._languageService.languageIdCodec); - if (DiffReview._ttPolicy) { - html = DiffReview._ttPolicy.createHTML(html as string); + if (AccessibleDiffViewer._ttPolicy) { + html = AccessibleDiffViewer._ttPolicy.createHTML(html as string); } cell.insertAdjacentHTML('beforeend', html as string); lineContent = modifiedModel.getLineContent(item.modifiedLineNumber); } else { let html: string | TrustedHTML = this._getLineHtml(originalModel, originalOptions, originalModelOpts.tabSize, item.originalLineNumber, this._languageService.languageIdCodec); - if (DiffReview._ttPolicy) { - html = DiffReview._ttPolicy.createHTML(html as string); + if (AccessibleDiffViewer._ttPolicy) { + html = AccessibleDiffViewer._ttPolicy.createHTML(html as string); } cell.insertAdjacentHTML('beforeend', html as string); lineContent = originalModel.getLineContent(item.originalLineNumber); diff --git a/src/vs/editor/browser/widget/diffEditorWidget2/diffEditorEditors.ts b/src/vs/editor/browser/widget/diffEditorWidget2/diffEditorEditors.ts index 2294861e7af..1166c4522b8 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget2/diffEditorEditors.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget2/diffEditorEditors.ts @@ -8,7 +8,6 @@ import { IObservable, IReader, autorunHandleChanges, observableFromEvent } from import { IEditorConstructionOptions } from 'vs/editor/browser/config/editorConfiguration'; import { IDiffEditorConstructionOptions } from 'vs/editor/browser/editorBrowser'; import { CodeEditorWidget, ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget'; -import { IDiffCodeEditorWidgetOptions } from 'vs/editor/browser/widget/diffEditorWidget'; import { OverviewRulerPart } from 'vs/editor/browser/widget/diffEditorWidget2/overviewRulerPart'; import { EditorOptions, IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { IContentSizeChangedEvent } from 'vs/editor/common/editorCommon'; @@ -17,6 +16,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { DiffEditorOptions } from './diffEditorOptions'; import { ITextModel } from 'vs/editor/common/model'; +import { IDiffCodeEditorWidgetOptions } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2'; export class DiffEditorEditors extends Disposable { public readonly modified: CodeEditorWidget; diff --git a/src/vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2.ts b/src/vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2.ts index e899a379f99..264b8117601 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2.ts @@ -15,7 +15,6 @@ import { ICodeEditor, IDiffEditor, IDiffEditorConstructionOptions, IMouseTargetV import { EditorExtensionsRegistry, IDiffEditorContributionDescription } from 'vs/editor/browser/editorExtensions'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { CodeEditorWidget, ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget'; -import { IDiffCodeEditorWidgetOptions } from 'vs/editor/browser/widget/diffEditorWidget'; import { AccessibleDiffViewer } from 'vs/editor/browser/widget/diffEditorWidget2/accessibleDiffViewer'; import { DiffEditorDecorations } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorDecorations'; import { DiffEditorSash } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorSash'; @@ -46,7 +45,14 @@ import { DiffEditorEditors } from './diffEditorEditors'; import { DiffEditorOptions } from './diffEditorOptions'; import { DiffEditorViewModel, DiffMapping, DiffState } from './diffEditorViewModel'; +export interface IDiffCodeEditorWidgetOptions { + originalEditor?: ICodeEditorWidgetOptions; + modifiedEditor?: ICodeEditorWidgetOptions; +} + export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor { + public static ENTIRE_DIFF_OVERVIEW_WIDTH = OverviewRulerPart.ENTIRE_DIFF_OVERVIEW_WIDTH; + private readonly elements = h('div.monaco-diff-editor.side-by-side', { style: { position: 'relative', height: '100%' } }, [ h('div.noModificationsOverlay@overlay', { style: { position: 'absolute', height: '100%', visibility: 'hidden', } }, [$('span', {}, 'No Changes')]), h('div.editor.original@original', { style: { position: 'absolute', height: '100%' } }), @@ -279,6 +285,10 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor { })); } + public getViewWidth(): number { + return this._rootSizeObserver.width.get(); + } + public getContentHeight() { return this._editors.modified.getContentHeight(); } diff --git a/src/vs/editor/browser/widget/diffEditorWidget2/renderLines.ts b/src/vs/editor/browser/widget/diffEditorWidget2/renderLines.ts index b33db4762e0..f9d8b3f9a08 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget2/renderLines.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget2/renderLines.ts @@ -3,9 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { createTrustedTypesPolicy } from 'vs/base/browser/trustedTypes'; import { applyFontInfo } from 'vs/editor/browser/config/domFontInfo'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { diffEditorWidgetTtPolicy } from 'vs/editor/browser/widget/diffEditorWidget'; import { EditorFontLigatures, EditorOption, FindComputedEditorOptionValueById } from 'vs/editor/common/config/editorOptions'; import { FontInfo } from 'vs/editor/common/config/fontInfo'; import { StringBuilder } from 'vs/editor/common/core/stringBuilder'; @@ -15,7 +15,7 @@ import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations'; import { RenderLineInput, renderViewLine } from 'vs/editor/common/viewLayout/viewLineRenderer'; import { InlineDecoration, ViewLineRenderingData } from 'vs/editor/common/viewModel'; -const ttPolicy = diffEditorWidgetTtPolicy; +const ttPolicy = createTrustedTypesPolicy('diffEditorWidget', { createHTML: value => value }); export function renderLines(source: LineSource, options: RenderOptions, decorations: InlineDecoration[], domNode: HTMLElement): RenderLinesResult { applyFontInfo(domNode, options.fontInfo); diff --git a/src/vs/editor/browser/widget/diffNavigator.ts b/src/vs/editor/browser/widget/diffNavigator.ts deleted file mode 100644 index 1edce99edf6..00000000000 --- a/src/vs/editor/browser/widget/diffNavigator.ts +++ /dev/null @@ -1,278 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as assert from 'vs/base/common/assert'; -import { Emitter, Event } from 'vs/base/common/event'; -import { Disposable } from 'vs/base/common/lifecycle'; -import * as objects from 'vs/base/common/objects'; -import { IDiffEditor } from 'vs/editor/browser/editorBrowser'; -import { ICursorPositionChangedEvent } from 'vs/editor/common/cursorEvents'; -import { Range } from 'vs/editor/common/core/range'; -import { ILineChange } from 'vs/editor/common/diff/legacyLinesDiffComputer'; -import { ScrollType } from 'vs/editor/common/editorCommon'; -import { AudioCue, IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService'; -import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; -import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; - - -interface IDiffRange { - rhs: boolean; - range: Range; -} - -export interface Options { - followsCaret?: boolean; - ignoreCharChanges?: boolean; - alwaysRevealFirst?: boolean; - findResultLoop?: boolean; -} - -const defaultOptions: Options = { - followsCaret: true, - ignoreCharChanges: true, - alwaysRevealFirst: true, - findResultLoop: true -}; - -export interface IDiffNavigator { - canNavigate(): boolean; - next(): void; - previous(): void; - dispose(): void; -} - -/** - * Create a new diff navigator for the provided diff editor. - */ -export class DiffNavigator extends Disposable implements IDiffNavigator { - - private readonly _editor: IDiffEditor; - private readonly _options: Options; - private readonly _onDidUpdate = this._register(new Emitter()); - - readonly onDidUpdate: Event = this._onDidUpdate.event; - - private disposed: boolean; - public revealFirst: boolean; - private nextIdx: number; - private ranges: IDiffRange[]; - private ignoreSelectionChange: boolean; - - constructor( - editor: IDiffEditor, - options: Options = {}, - @IAudioCueService private readonly _audioCueService: IAudioCueService, - @ICodeEditorService private readonly _codeEditorService: ICodeEditorService, - @IAccessibilityService private readonly _accessibilityService: IAccessibilityService - ) { - super(); - this._editor = editor; - this._options = objects.mixin(options, defaultOptions, false); - - this.disposed = false; - - this.nextIdx = -1; - this.ranges = []; - this.ignoreSelectionChange = false; - this.revealFirst = Boolean(this._options.alwaysRevealFirst); - - this._register(this._editor.onDidUpdateDiff(() => this._onDiffUpdated())); - - if (this._options.followsCaret) { - this._register(this._editor.getModifiedEditor().onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => { - if (this.ignoreSelectionChange) { - return; - } - this._updateAccessibilityState(e.position.lineNumber); - this.nextIdx = -1; - })); - } - - // init things - this._init(); - } - - private _init(): void { - const changes = this._editor.getLineChanges(); - if (!changes) { - return; - } - } - - private _onDiffUpdated(): void { - this._init(); - - this._compute(this._editor.getLineChanges()); - if (this.revealFirst) { - // Only reveal first on first non-null changes - if (this._editor.getLineChanges() !== null) { - this.revealFirst = false; - this.nextIdx = -1; - this.next(ScrollType.Immediate); - } - } - } - - private _compute(lineChanges: ILineChange[] | null): void { - - // new ranges - this.ranges = []; - - if (lineChanges) { - // create ranges from changes - lineChanges.forEach((lineChange) => { - - if (!this._options.ignoreCharChanges && lineChange.charChanges) { - - lineChange.charChanges.forEach((charChange) => { - this.ranges.push({ - rhs: true, - range: new Range( - charChange.modifiedStartLineNumber, - charChange.modifiedStartColumn, - charChange.modifiedEndLineNumber, - charChange.modifiedEndColumn) - }); - }); - - } else { - if (lineChange.modifiedEndLineNumber === 0) { - // a deletion - this.ranges.push({ - rhs: true, - range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedStartLineNumber + 1, 1) - }); - } else { - // an insertion or modification - this.ranges.push({ - rhs: true, - range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber + 1, 1) - }); - } - } - }); - } - - // sort - this.ranges.sort((left, right) => Range.compareRangesUsingStarts(left.range, right.range)); - this._onDidUpdate.fire(this); - } - - private _initIdx(fwd: boolean): void { - let found = false; - const position = this._editor.getPosition(); - if (!position) { - this.nextIdx = 0; - return; - } - for (let i = 0, len = this.ranges.length; i < len && !found; i++) { - const range = this.ranges[i].range; - if (position.isBeforeOrEqual(range.getStartPosition())) { - this.nextIdx = i + (fwd ? 0 : -1); - found = true; - } - } - if (!found) { - // after the last change - this.nextIdx = fwd ? 0 : this.ranges.length - 1; - } - if (this.nextIdx < 0) { - this.nextIdx = this.ranges.length - 1; - } - } - - private _move(fwd: boolean, scrollType: ScrollType): void { - assert.ok(!this.disposed, 'Illegal State - diff navigator has been disposed'); - - if (!this.canNavigate()) { - return; - } - - if (this.nextIdx === -1) { - this._initIdx(fwd); - - } else if (fwd) { - this.nextIdx += 1; - if (this.nextIdx >= this.ranges.length) { - this.nextIdx = 0; - } - } else { - this.nextIdx -= 1; - if (this.nextIdx < 0) { - this.nextIdx = this.ranges.length - 1; - } - } - - const info = this.ranges[this.nextIdx]; - this.ignoreSelectionChange = true; - try { - const pos = info.range.getStartPosition(); - this._editor.setPosition(pos); - this._editor.revealRangeInCenter(info.range, scrollType); - this._updateAccessibilityState(pos.lineNumber, true); - } finally { - this.ignoreSelectionChange = false; - } - } - - _updateAccessibilityState(lineNumber: number, jumpToChange?: boolean): void { - const modifiedEditor = this._editor.getModel()?.modified; - if (!modifiedEditor) { - return; - } - const insertedOrModified = modifiedEditor.getLineDecorations(lineNumber).find(l => l.options.className === 'line-insert'); - if (insertedOrModified) { - this._audioCueService.playAudioCue(AudioCue.diffLineModified, { allowManyInParallel: true }); - } else if (jumpToChange) { - // The modified editor does not include deleted lines, but when - // we are moved to the area where lines were deleted, play this cue - this._audioCueService.playAudioCue(AudioCue.diffLineDeleted, { allowManyInParallel: true }); - } else { - return; - } - - const codeEditor = this._codeEditorService.getActiveCodeEditor(); - if (jumpToChange && codeEditor && insertedOrModified && this._accessibilityService.isScreenReaderOptimized()) { - codeEditor.setSelection({ startLineNumber: lineNumber, startColumn: 0, endLineNumber: lineNumber, endColumn: Number.MAX_VALUE }); - codeEditor.writeScreenReaderContent('diff-navigation'); - } - } - - canNavigate(): boolean { - return this.ranges && this.ranges.length > 0; - } - - next(scrollType: ScrollType = ScrollType.Smooth): void { - if (!this.canNavigateNext()) { - return; - } - this._move(true, scrollType); - } - - previous(scrollType: ScrollType = ScrollType.Smooth): void { - if (!this.canNavigatePrevious()) { - return; - } - this._move(false, scrollType); - } - - canNavigateNext(): boolean { - return this.canNavigateLoop() || this.nextIdx < this.ranges.length - 1; - } - - canNavigatePrevious(): boolean { - return this.canNavigateLoop() || this.nextIdx !== 0; - } - - canNavigateLoop(): boolean { - return Boolean(this._options.findResultLoop); - } - - override dispose(): void { - super.dispose(); - this.ranges = []; - this.disposed = true; - } -} diff --git a/src/vs/editor/browser/widget/diffReview.ts b/src/vs/editor/browser/widget/diffReview.ts deleted file mode 100644 index 268d41d2f3b..00000000000 --- a/src/vs/editor/browser/widget/diffReview.ts +++ /dev/null @@ -1,826 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as dom from 'vs/base/browser/dom'; -import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode'; -import { createTrustedTypesPolicy } from 'vs/base/browser/trustedTypes'; -import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; -import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement'; -import { Action } from 'vs/base/common/actions'; -import { Codicon } from 'vs/base/common/codicons'; -import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; -import { Disposable } from 'vs/base/common/lifecycle'; -import { ThemeIcon } from 'vs/base/common/themables'; -import { Constants } from 'vs/base/common/uint'; -import 'vs/css!./media/diffReview'; -import { applyFontInfo } from 'vs/editor/browser/config/domFontInfo'; -import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; -import { EditorFontLigatures, EditorOption, IComputedEditorOptions } from 'vs/editor/common/config/editorOptions'; -import { Position } from 'vs/editor/common/core/position'; -import { ILineChange } from 'vs/editor/common/diff/legacyLinesDiffComputer'; -import { ScrollType } from 'vs/editor/common/editorCommon'; -import { ILanguageIdCodec } from 'vs/editor/common/languages'; -import { ILanguageService } from 'vs/editor/common/languages/language'; -import { ITextModel, TextModelResolvedOptions } from 'vs/editor/common/model'; -import { LineTokens } from 'vs/editor/common/tokens/lineTokens'; -import { RenderLineInput, renderViewLine2 as renderViewLine } from 'vs/editor/common/viewLayout/viewLineRenderer'; -import { ViewLineRenderingData } from 'vs/editor/common/viewModel'; -import * as nls from 'vs/nls'; -import { AudioCue, IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService'; -import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; -import { registerIcon } from 'vs/platform/theme/common/iconRegistry'; - -const DIFF_LINES_PADDING = 3; - -const enum DiffEntryType { - Equal = 0, - Insert = 1, - Delete = 2 -} - -class DiffEntry { - readonly originalLineStart: number; - readonly originalLineEnd: number; - readonly modifiedLineStart: number; - readonly modifiedLineEnd: number; - - constructor(originalLineStart: number, originalLineEnd: number, modifiedLineStart: number, modifiedLineEnd: number) { - this.originalLineStart = originalLineStart; - this.originalLineEnd = originalLineEnd; - this.modifiedLineStart = modifiedLineStart; - this.modifiedLineEnd = modifiedLineEnd; - } - - public getType(): DiffEntryType { - if (this.originalLineStart === 0) { - return DiffEntryType.Insert; - } - if (this.modifiedLineStart === 0) { - return DiffEntryType.Delete; - } - return DiffEntryType.Equal; - } -} - -const enum DiffEditorLineClasses { - Insert = 'line-insert', - Delete = 'line-delete' -} - -class Diff { - readonly entries: DiffEntry[]; - - constructor(entries: DiffEntry[]) { - this.entries = entries; - } -} - -const diffReviewInsertIcon = registerIcon('diff-review-insert', Codicon.add, nls.localize('diffReviewInsertIcon', 'Icon for \'Insert\' in diff review.')); -const diffReviewRemoveIcon = registerIcon('diff-review-remove', Codicon.remove, nls.localize('diffReviewRemoveIcon', 'Icon for \'Remove\' in diff review.')); -const diffReviewCloseIcon = registerIcon('diff-review-close', Codicon.close, nls.localize('diffReviewCloseIcon', 'Icon for \'Close\' in diff review.')); - -export class DiffReview extends Disposable { - - public static _ttPolicy = createTrustedTypesPolicy('diffReview', { createHTML: value => value }); - - private readonly _diffEditor: DiffEditorWidget; - private _isVisible: boolean; - public readonly shadow: FastDomNode; - private readonly _actionBar: ActionBar; - public readonly actionBarContainer: FastDomNode; - public readonly domNode: FastDomNode; - private readonly _content: FastDomNode; - private readonly scrollbar: DomScrollableElement; - private _diffs: Diff[]; - private _currentDiff: Diff | null; - - constructor( - diffEditor: DiffEditorWidget, - @ILanguageService private readonly _languageService: ILanguageService, - @IAudioCueService private readonly _audioCueService: IAudioCueService, - @IConfigurationService private readonly _configurationService: IConfigurationService - ) { - super(); - this._diffEditor = diffEditor; - this._isVisible = false; - - this.shadow = createFastDomNode(document.createElement('div')); - this.shadow.setClassName('diff-review-shadow'); - - this.actionBarContainer = createFastDomNode(document.createElement('div')); - this.actionBarContainer.setClassName('diff-review-actions'); - this._actionBar = this._register(new ActionBar( - this.actionBarContainer.domNode - )); - - this._actionBar.push(new Action('diffreview.close', nls.localize('label.close', "Close"), 'close-diff-review ' + ThemeIcon.asClassName(diffReviewCloseIcon), true, async () => this.hide()), { label: false, icon: true }); - - this.domNode = createFastDomNode(document.createElement('div')); - this.domNode.setClassName('diff-review monaco-editor-background'); - - this._content = createFastDomNode(document.createElement('div')); - this._content.setClassName('diff-review-content'); - this._content.setAttribute('role', 'code'); - this.scrollbar = this._register(new DomScrollableElement(this._content.domNode, {})); - this.domNode.domNode.appendChild(this.scrollbar.getDomNode()); - - this._register(diffEditor.onDidUpdateDiff(() => { - if (!this._isVisible) { - return; - } - this._diffs = this._compute(); - this._render(); - })); - this._register(diffEditor.getModifiedEditor().onDidChangeCursorPosition(() => { - if (!this._isVisible) { - return; - } - this._render(); - })); - this._register(dom.addStandardDisposableListener(this.domNode.domNode, 'click', (e) => { - e.preventDefault(); - - const row = dom.findParentWithClass(e.target, 'diff-review-row'); - if (row) { - this._goToRow(row); - } - })); - this._register(dom.addStandardDisposableListener(this.domNode.domNode, 'keydown', (e) => { - if ( - e.equals(KeyCode.DownArrow) - || e.equals(KeyMod.CtrlCmd | KeyCode.DownArrow) - || e.equals(KeyMod.Alt | KeyCode.DownArrow) - ) { - e.preventDefault(); - this._goToRow(this._getNextRow(), 'next'); - } - - if ( - e.equals(KeyCode.UpArrow) - || e.equals(KeyMod.CtrlCmd | KeyCode.UpArrow) - || e.equals(KeyMod.Alt | KeyCode.UpArrow) - ) { - e.preventDefault(); - this._goToRow(this._getPrevRow(), 'previous'); - } - - if ( - e.equals(KeyCode.Escape) - || e.equals(KeyMod.CtrlCmd | KeyCode.Escape) - || e.equals(KeyMod.Alt | KeyCode.Escape) - || e.equals(KeyMod.Shift | KeyCode.Escape) - || e.equals(KeyCode.Space) - || e.equals(KeyCode.Enter) - ) { - e.preventDefault(); - this.accept(); - } - })); - this._register(this._configurationService.onDidChangeConfiguration(e => { - if (e.affectsConfiguration('accessibility.verbosity.diffEditor')) { - this._diffEditor.updateOptions({ accessibilityVerbose: this._configurationService.getValue('accessibility.verbosity.diffEditor') }); - } - })); - this._diffs = []; - this._currentDiff = null; - } - - public prev(): void { - let index = 0; - - if (!this._isVisible) { - this._diffs = this._compute(); - } - - if (this._isVisible) { - let currentIndex = -1; - for (let i = 0, len = this._diffs.length; i < len; i++) { - if (this._diffs[i] === this._currentDiff) { - currentIndex = i; - break; - } - } - index = (this._diffs.length + currentIndex - 1); - } else { - index = this._findDiffIndex(this._diffEditor.getPosition()!); - } - - if (this._diffs.length === 0) { - // Nothing to do - return; - } - - index = index % this._diffs.length; - const entries = this._diffs[index].entries; - this._diffEditor.setPosition(new Position(entries[0].modifiedLineStart, 1)); - this._diffEditor.setSelection({ startColumn: 1, startLineNumber: entries[0].modifiedLineStart, endColumn: Constants.MAX_SAFE_SMALL_INTEGER, endLineNumber: entries[entries.length - 1].modifiedLineEnd }); - this._isVisible = true; - this._diffEditor.doLayout(); - this._render(); - this._goToRow(this._getPrevRow(), 'previous'); - } - - public next(): void { - let index = 0; - - if (!this._isVisible) { - this._diffs = this._compute(); - } - - if (this._isVisible) { - let currentIndex = -1; - for (let i = 0, len = this._diffs.length; i < len; i++) { - if (this._diffs[i] === this._currentDiff) { - currentIndex = i; - break; - } - } - index = (currentIndex + 1); - } else { - index = this._findDiffIndex(this._diffEditor.getPosition()!); - } - - if (this._diffs.length === 0) { - // Nothing to do - return; - } - - index = index % this._diffs.length; - const entries = this._diffs[index].entries; - this._diffEditor.setPosition(new Position(entries[0].modifiedLineStart, 1)); - this._diffEditor.setSelection({ startColumn: 1, startLineNumber: entries[0].modifiedLineStart, endColumn: Constants.MAX_SAFE_SMALL_INTEGER, endLineNumber: entries[entries.length - 1].modifiedLineEnd }); - this._isVisible = true; - this._diffEditor.doLayout(); - this._render(); - this._goToRow(this._getNextRow(), 'next'); - } - - private accept(): void { - let jumpToLineNumber = -1; - const current = this._getCurrentFocusedRow(); - if (current) { - const lineNumber = parseInt(current.getAttribute('data-line')!, 10); - if (!isNaN(lineNumber)) { - jumpToLineNumber = lineNumber; - } - } - this.hide(); - - if (jumpToLineNumber !== -1) { - this._diffEditor.setPosition(new Position(jumpToLineNumber, 1)); - this._diffEditor.revealPosition(new Position(jumpToLineNumber, 1), ScrollType.Immediate); - } - } - - private hide(): void { - this._isVisible = false; - this._diffEditor.updateOptions({ readOnly: false }); - this._diffEditor.focus(); - this._diffEditor.doLayout(); - this._render(); - } - - private _getPrevRow(): HTMLElement { - const current = this._getCurrentFocusedRow(); - if (!current) { - return this._getFirstRow(); - } - if (current.previousElementSibling) { - return current.previousElementSibling; - } - return current; - } - - private _getNextRow(): HTMLElement { - const current = this._getCurrentFocusedRow(); - if (!current) { - return this._getFirstRow(); - } - if (current.nextElementSibling) { - return current.nextElementSibling; - } - return current; - } - - private _getFirstRow(): HTMLElement { - return this.domNode.domNode.querySelector('.diff-review-row'); - } - - private _getCurrentFocusedRow(): HTMLElement | null { - const result = document.activeElement; - if (result && /diff-review-row/.test(result.className)) { - return result; - } - return null; - } - - private _goToRow(row: HTMLElement, type?: 'next' | 'previous'): void { - const current = this._getCurrentFocusedRow(); - row.tabIndex = 0; - row.focus(); - if (current && current !== row) { - current.tabIndex = -1; - } - const element = !type ? current : type === 'next' ? current?.nextElementSibling : current?.previousElementSibling; - if (element?.classList.contains(DiffEditorLineClasses.Insert)) { - this._audioCueService.playAudioCue(AudioCue.diffLineInserted, { allowManyInParallel: true }); - } else if (element?.classList.contains(DiffEditorLineClasses.Delete)) { - this._audioCueService.playAudioCue(AudioCue.diffLineDeleted, { allowManyInParallel: true }); - } - this.scrollbar.scanDomNode(); - } - - public isVisible(): boolean { - return this._isVisible; - } - - private _width: number = 0; - - public layout(top: number, width: number, height: number): void { - this._width = width; - this.shadow.setTop(top - 6); - this.shadow.setWidth(width); - this.shadow.setHeight(this._isVisible ? 6 : 0); - this.domNode.setTop(top); - this.domNode.setWidth(width); - this.domNode.setHeight(height); - this._content.setHeight(height); - this._content.setWidth(width); - - if (this._isVisible) { - this.actionBarContainer.setAttribute('aria-hidden', 'false'); - this.actionBarContainer.setDisplay('block'); - } else { - this.actionBarContainer.setAttribute('aria-hidden', 'true'); - this.actionBarContainer.setDisplay('none'); - } - } - - private _compute(): Diff[] { - const lineChanges = this._diffEditor.getLineChanges(); - if (!lineChanges || lineChanges.length === 0) { - return []; - } - const originalModel = this._diffEditor.getOriginalEditor().getModel(); - const modifiedModel = this._diffEditor.getModifiedEditor().getModel(); - - if (!originalModel || !modifiedModel) { - return []; - } - - return DiffReview._mergeAdjacent(lineChanges, originalModel.getLineCount(), modifiedModel.getLineCount()); - } - - private static _mergeAdjacent(lineChanges: ILineChange[], originalLineCount: number, modifiedLineCount: number): Diff[] { - if (!lineChanges || lineChanges.length === 0) { - return []; - } - - const diffs: Diff[] = []; - let diffsLength = 0; - - for (let i = 0, len = lineChanges.length; i < len; i++) { - const lineChange = lineChanges[i]; - - const originalStart = lineChange.originalStartLineNumber; - const originalEnd = lineChange.originalEndLineNumber; - const modifiedStart = lineChange.modifiedStartLineNumber; - const modifiedEnd = lineChange.modifiedEndLineNumber; - - const r: DiffEntry[] = []; - let rLength = 0; - - // Emit before anchors - { - const originalEqualAbove = (originalEnd === 0 ? originalStart : originalStart - 1); - const modifiedEqualAbove = (modifiedEnd === 0 ? modifiedStart : modifiedStart - 1); - - // Make sure we don't step into the previous diff - let minOriginal = 1; - let minModified = 1; - if (i > 0) { - const prevLineChange = lineChanges[i - 1]; - - if (prevLineChange.originalEndLineNumber === 0) { - minOriginal = prevLineChange.originalStartLineNumber + 1; - } else { - minOriginal = prevLineChange.originalEndLineNumber + 1; - } - - if (prevLineChange.modifiedEndLineNumber === 0) { - minModified = prevLineChange.modifiedStartLineNumber + 1; - } else { - minModified = prevLineChange.modifiedEndLineNumber + 1; - } - } - - let fromOriginal = originalEqualAbove - DIFF_LINES_PADDING + 1; - let fromModified = modifiedEqualAbove - DIFF_LINES_PADDING + 1; - if (fromOriginal < minOriginal) { - const delta = minOriginal - fromOriginal; - fromOriginal = fromOriginal + delta; - fromModified = fromModified + delta; - } - if (fromModified < minModified) { - const delta = minModified - fromModified; - fromOriginal = fromOriginal + delta; - fromModified = fromModified + delta; - } - - r[rLength++] = new DiffEntry( - fromOriginal, originalEqualAbove, - fromModified, modifiedEqualAbove - ); - } - - // Emit deleted lines - { - if (originalEnd !== 0) { - r[rLength++] = new DiffEntry(originalStart, originalEnd, 0, 0); - } - } - - // Emit inserted lines - { - if (modifiedEnd !== 0) { - r[rLength++] = new DiffEntry(0, 0, modifiedStart, modifiedEnd); - } - } - - // Emit after anchors - { - const originalEqualBelow = (originalEnd === 0 ? originalStart + 1 : originalEnd + 1); - const modifiedEqualBelow = (modifiedEnd === 0 ? modifiedStart + 1 : modifiedEnd + 1); - - // Make sure we don't step into the next diff - let maxOriginal = originalLineCount; - let maxModified = modifiedLineCount; - if (i + 1 < len) { - const nextLineChange = lineChanges[i + 1]; - - if (nextLineChange.originalEndLineNumber === 0) { - maxOriginal = nextLineChange.originalStartLineNumber; - } else { - maxOriginal = nextLineChange.originalStartLineNumber - 1; - } - - if (nextLineChange.modifiedEndLineNumber === 0) { - maxModified = nextLineChange.modifiedStartLineNumber; - } else { - maxModified = nextLineChange.modifiedStartLineNumber - 1; - } - } - - let toOriginal = originalEqualBelow + DIFF_LINES_PADDING - 1; - let toModified = modifiedEqualBelow + DIFF_LINES_PADDING - 1; - - if (toOriginal > maxOriginal) { - const delta = maxOriginal - toOriginal; - toOriginal = toOriginal + delta; - toModified = toModified + delta; - } - if (toModified > maxModified) { - const delta = maxModified - toModified; - toOriginal = toOriginal + delta; - toModified = toModified + delta; - } - - r[rLength++] = new DiffEntry( - originalEqualBelow, toOriginal, - modifiedEqualBelow, toModified, - ); - } - - diffs[diffsLength++] = new Diff(r); - } - - // Merge adjacent diffs - let curr: DiffEntry[] = diffs[0].entries; - const r: Diff[] = []; - let rLength = 0; - for (let i = 1, len = diffs.length; i < len; i++) { - const thisDiff = diffs[i].entries; - - const currLast = curr[curr.length - 1]; - const thisFirst = thisDiff[0]; - - if ( - currLast.getType() === DiffEntryType.Equal - && thisFirst.getType() === DiffEntryType.Equal - && thisFirst.originalLineStart <= currLast.originalLineEnd - ) { - // We are dealing with equal lines that overlap - - curr[curr.length - 1] = new DiffEntry( - currLast.originalLineStart, thisFirst.originalLineEnd, - currLast.modifiedLineStart, thisFirst.modifiedLineEnd - ); - curr = curr.concat(thisDiff.slice(1)); - continue; - } - - r[rLength++] = new Diff(curr); - curr = thisDiff; - } - r[rLength++] = new Diff(curr); - return r; - } - - private _findDiffIndex(pos: Position): number { - const lineNumber = pos.lineNumber; - for (let i = 0, len = this._diffs.length; i < len; i++) { - const diff = this._diffs[i].entries; - const lastModifiedLine = diff[diff.length - 1].modifiedLineEnd; - if (lineNumber <= lastModifiedLine) { - return i; - } - } - return 0; - } - - private _render(): void { - - const originalOptions = this._diffEditor.getOriginalEditor().getOptions(); - const modifiedOptions = this._diffEditor.getModifiedEditor().getOptions(); - - const originalModel = this._diffEditor.getOriginalEditor().getModel(); - const modifiedModel = this._diffEditor.getModifiedEditor().getModel(); - - const originalModelOpts = originalModel!.getOptions(); - const modifiedModelOpts = modifiedModel!.getOptions(); - - if (!this._isVisible || !originalModel || !modifiedModel) { - dom.clearNode(this._content.domNode); - this._currentDiff = null; - this.scrollbar.scanDomNode(); - return; - } - - this._diffEditor.updateOptions({ readOnly: true }); - const diffIndex = this._findDiffIndex(this._diffEditor.getPosition()!); - - if (this._diffs[diffIndex] === this._currentDiff) { - return; - } - this._currentDiff = this._diffs[diffIndex]; - - const diffs = this._diffs[diffIndex].entries; - const container = document.createElement('div'); - container.className = 'diff-review-table'; - container.setAttribute('role', 'list'); - container.setAttribute('aria-label', 'Difference review. Use "Stage | Unstage | Revert Selected Ranges" commands'); - applyFontInfo(container, modifiedOptions.get(EditorOption.fontInfo)); - - let minOriginalLine = 0; - let maxOriginalLine = 0; - let minModifiedLine = 0; - let maxModifiedLine = 0; - for (let i = 0, len = diffs.length; i < len; i++) { - const diffEntry = diffs[i]; - const originalLineStart = diffEntry.originalLineStart; - const originalLineEnd = diffEntry.originalLineEnd; - const modifiedLineStart = diffEntry.modifiedLineStart; - const modifiedLineEnd = diffEntry.modifiedLineEnd; - - if (originalLineStart !== 0 && ((minOriginalLine === 0 || originalLineStart < minOriginalLine))) { - minOriginalLine = originalLineStart; - } - if (originalLineEnd !== 0 && ((maxOriginalLine === 0 || originalLineEnd > maxOriginalLine))) { - maxOriginalLine = originalLineEnd; - } - if (modifiedLineStart !== 0 && ((minModifiedLine === 0 || modifiedLineStart < minModifiedLine))) { - minModifiedLine = modifiedLineStart; - } - if (modifiedLineEnd !== 0 && ((maxModifiedLine === 0 || modifiedLineEnd > maxModifiedLine))) { - maxModifiedLine = modifiedLineEnd; - } - } - - const header = document.createElement('div'); - header.className = 'diff-review-row'; - - const cell = document.createElement('div'); - cell.className = 'diff-review-cell diff-review-summary'; - const originalChangedLinesCnt = maxOriginalLine - minOriginalLine + 1; - const modifiedChangedLinesCnt = maxModifiedLine - minModifiedLine + 1; - cell.appendChild(document.createTextNode(`${diffIndex + 1}/${this._diffs.length}: @@ -${minOriginalLine},${originalChangedLinesCnt} +${minModifiedLine},${modifiedChangedLinesCnt} @@`)); - header.setAttribute('data-line', String(minModifiedLine)); - - const getAriaLines = (lines: number) => { - if (lines === 0) { - return nls.localize('no_lines_changed', "no lines changed"); - } else if (lines === 1) { - return nls.localize('one_line_changed', "1 line changed"); - } else { - return nls.localize('more_lines_changed', "{0} lines changed", lines); - } - }; - - const originalChangedLinesCntAria = getAriaLines(originalChangedLinesCnt); - const modifiedChangedLinesCntAria = getAriaLines(modifiedChangedLinesCnt); - header.setAttribute('aria-label', nls.localize({ - key: 'header', - comment: [ - 'This is the ARIA label for a git diff header.', - 'A git diff header looks like this: @@ -154,12 +159,39 @@.', - 'That encodes that at original line 154 (which is now line 159), 12 lines were removed/changed with 39 lines.', - 'Variables 0 and 1 refer to the diff index out of total number of diffs.', - 'Variables 2 and 4 will be numbers (a line number).', - 'Variables 3 and 5 will be "no lines changed", "1 line changed" or "X lines changed", localized separately.' - ] - }, "Difference {0} of {1}: original line {2}, {3}, modified line {4}, {5}", (diffIndex + 1), this._diffs.length, minOriginalLine, originalChangedLinesCntAria, minModifiedLine, modifiedChangedLinesCntAria)); - header.appendChild(cell); - - // @@ -504,7 +517,7 @@ - header.setAttribute('role', 'listitem'); - container.appendChild(header); - - const lineHeight = modifiedOptions.get(EditorOption.lineHeight); - let modLine = minModifiedLine; - for (let i = 0, len = diffs.length; i < len; i++) { - const diffEntry = diffs[i]; - DiffReview._renderSection(container, diffEntry, modLine, lineHeight, this._width, originalOptions, originalModel, originalModelOpts, modifiedOptions, modifiedModel, modifiedModelOpts, this._languageService.languageIdCodec); - if (diffEntry.modifiedLineStart !== 0) { - modLine = diffEntry.modifiedLineEnd; - } - } - - dom.clearNode(this._content.domNode); - this._content.domNode.appendChild(container); - this.scrollbar.scanDomNode(); - } - - private static _renderSection( - dest: HTMLElement, diffEntry: DiffEntry, modLine: number, lineHeight: number, width: number, - originalOptions: IComputedEditorOptions, originalModel: ITextModel, originalModelOpts: TextModelResolvedOptions, - modifiedOptions: IComputedEditorOptions, modifiedModel: ITextModel, modifiedModelOpts: TextModelResolvedOptions, - languageIdCodec: ILanguageIdCodec - ): void { - - const type = diffEntry.getType(); - - let rowClassName: string = 'diff-review-row'; - let lineNumbersExtraClassName: string = ''; - const spacerClassName: string = 'diff-review-spacer'; - let spacerIcon: ThemeIcon | null = null; - switch (type) { - case DiffEntryType.Insert: - rowClassName = 'diff-review-row line-insert'; - lineNumbersExtraClassName = ' char-insert'; - spacerIcon = diffReviewInsertIcon; - break; - case DiffEntryType.Delete: - rowClassName = 'diff-review-row line-delete'; - lineNumbersExtraClassName = ' char-delete'; - spacerIcon = diffReviewRemoveIcon; - break; - } - - const originalLineStart = diffEntry.originalLineStart; - const originalLineEnd = diffEntry.originalLineEnd; - const modifiedLineStart = diffEntry.modifiedLineStart; - const modifiedLineEnd = diffEntry.modifiedLineEnd; - - const cnt = Math.max( - modifiedLineEnd - modifiedLineStart, - originalLineEnd - originalLineStart - ); - - const originalLayoutInfo = originalOptions.get(EditorOption.layoutInfo); - const originalLineNumbersWidth = originalLayoutInfo.glyphMarginWidth + originalLayoutInfo.lineNumbersWidth; - - const modifiedLayoutInfo = modifiedOptions.get(EditorOption.layoutInfo); - const modifiedLineNumbersWidth = 10 + modifiedLayoutInfo.glyphMarginWidth + modifiedLayoutInfo.lineNumbersWidth; - - for (let i = 0; i <= cnt; i++) { - const originalLine = (originalLineStart === 0 ? 0 : originalLineStart + i); - const modifiedLine = (modifiedLineStart === 0 ? 0 : modifiedLineStart + i); - - const row = document.createElement('div'); - row.style.minWidth = width + 'px'; - row.className = rowClassName; - row.setAttribute('role', 'listitem'); - if (modifiedLine !== 0) { - modLine = modifiedLine; - } - row.setAttribute('data-line', String(modLine)); - - const cell = document.createElement('div'); - cell.className = 'diff-review-cell'; - cell.style.height = `${lineHeight}px`; - row.appendChild(cell); - - const originalLineNumber = document.createElement('span'); - originalLineNumber.style.width = (originalLineNumbersWidth + 'px'); - originalLineNumber.style.minWidth = (originalLineNumbersWidth + 'px'); - originalLineNumber.className = 'diff-review-line-number' + lineNumbersExtraClassName; - if (originalLine !== 0) { - originalLineNumber.appendChild(document.createTextNode(String(originalLine))); - } else { - originalLineNumber.innerText = '\u00a0'; - } - cell.appendChild(originalLineNumber); - - const modifiedLineNumber = document.createElement('span'); - modifiedLineNumber.style.width = (modifiedLineNumbersWidth + 'px'); - modifiedLineNumber.style.minWidth = (modifiedLineNumbersWidth + 'px'); - modifiedLineNumber.style.paddingRight = '10px'; - modifiedLineNumber.className = 'diff-review-line-number' + lineNumbersExtraClassName; - if (modifiedLine !== 0) { - modifiedLineNumber.appendChild(document.createTextNode(String(modifiedLine))); - } else { - modifiedLineNumber.innerText = '\u00a0'; - } - cell.appendChild(modifiedLineNumber); - - const spacer = document.createElement('span'); - spacer.className = spacerClassName; - - if (spacerIcon) { - const spacerCodicon = document.createElement('span'); - spacerCodicon.className = ThemeIcon.asClassName(spacerIcon); - spacerCodicon.innerText = '\u00a0\u00a0'; - spacer.appendChild(spacerCodicon); - } else { - spacer.innerText = '\u00a0\u00a0'; - } - cell.appendChild(spacer); - - let lineContent: string; - if (modifiedLine !== 0) { - let html: string | TrustedHTML = this._renderLine(modifiedModel, modifiedOptions, modifiedModelOpts.tabSize, modifiedLine, languageIdCodec); - if (DiffReview._ttPolicy) { - html = DiffReview._ttPolicy.createHTML(html as string); - } - cell.insertAdjacentHTML('beforeend', html as string); - lineContent = modifiedModel.getLineContent(modifiedLine); - } else { - let html: string | TrustedHTML = this._renderLine(originalModel, originalOptions, originalModelOpts.tabSize, originalLine, languageIdCodec); - if (DiffReview._ttPolicy) { - html = DiffReview._ttPolicy.createHTML(html as string); - } - cell.insertAdjacentHTML('beforeend', html as string); - lineContent = originalModel.getLineContent(originalLine); - } - - if (lineContent.length === 0) { - lineContent = nls.localize('blankLine', "blank"); - } - - let ariaLabel: string = ''; - switch (type) { - case DiffEntryType.Equal: - if (originalLine === modifiedLine) { - ariaLabel = nls.localize({ key: 'unchangedLine', comment: ['The placeholders are contents of the line and should not be translated.'] }, "{0} unchanged line {1}", lineContent, originalLine); - } else { - ariaLabel = nls.localize('equalLine', "{0} original line {1} modified line {2}", lineContent, originalLine, modifiedLine); - } - break; - case DiffEntryType.Insert: - ariaLabel = nls.localize('insertLine', "+ {0} modified line {1}", lineContent, modifiedLine); - break; - case DiffEntryType.Delete: - ariaLabel = nls.localize('deleteLine', "- {0} original line {1}", lineContent, originalLine); - break; - } - row.setAttribute('aria-label', ariaLabel); - - dest.appendChild(row); - } - } - - private static _renderLine(model: ITextModel, options: IComputedEditorOptions, tabSize: number, lineNumber: number, languageIdCodec: ILanguageIdCodec): string { - const lineContent = model.getLineContent(lineNumber); - const fontInfo = options.get(EditorOption.fontInfo); - const lineTokens = LineTokens.createEmpty(lineContent, languageIdCodec); - const isBasicASCII = ViewLineRenderingData.isBasicASCII(lineContent, model.mightContainNonBasicASCII()); - const containsRTL = ViewLineRenderingData.containsRTL(lineContent, isBasicASCII, model.mightContainRTL()); - const r = renderViewLine(new RenderLineInput( - (fontInfo.isMonospace && !options.get(EditorOption.disableMonospaceOptimizations)), - fontInfo.canUseHalfwidthRightwardsArrow, - lineContent, - false, - isBasicASCII, - containsRTL, - 0, - lineTokens, - [], - tabSize, - 0, - fontInfo.spaceWidth, - fontInfo.middotWidth, - fontInfo.wsmiddotWidth, - options.get(EditorOption.stopRenderingLineAfter), - options.get(EditorOption.renderWhitespace), - options.get(EditorOption.renderControlCharacters), - options.get(EditorOption.fontLigatures) !== EditorFontLigatures.OFF, - null - )); - - return r.html; - } -} - -// theming diff --git a/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts b/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts index d9785bfc8c1..78d8dffd609 100644 --- a/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts +++ b/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts @@ -7,21 +7,18 @@ import * as objects from 'vs/base/common/objects'; import { ICodeEditor, IDiffEditorConstructionOptions } from 'vs/editor/browser/editorBrowser'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { CodeEditorWidget, ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget'; -import { DiffEditorWidget, IDiffCodeEditorWidgetOptions } from 'vs/editor/browser/widget/diffEditorWidget'; +import { DiffEditorWidget2, IDiffCodeEditorWidgetOptions } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2'; import { ConfigurationChangedEvent, IDiffEditorOptions, IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry'; +import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; +import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; +import { IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { INotificationService } from 'vs/platform/notification/common/notification'; -import { IThemeService } from 'vs/platform/theme/common/themeService'; -import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; -import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; -import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { IEditorProgressService } from 'vs/platform/progress/common/progress'; -import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry'; -import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; -import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2'; -import { IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService'; +import { IThemeService } from 'vs/platform/theme/common/themeService'; export class EmbeddedCodeEditorWidget extends CodeEditorWidget { @@ -69,54 +66,6 @@ export class EmbeddedCodeEditorWidget extends CodeEditorWidget { } } -/** - * @deprecated Use EmbeddedDiffEditorWidget2 instead. - */ -export class EmbeddedDiffEditorWidget extends DiffEditorWidget { - - private readonly _parentEditor: ICodeEditor; - private readonly _overwriteOptions: IDiffEditorOptions; - - constructor( - domElement: HTMLElement, - options: Readonly, - codeEditorWidgetOptions: IDiffCodeEditorWidgetOptions, - parentEditor: ICodeEditor, - @IContextKeyService contextKeyService: IContextKeyService, - @IInstantiationService instantiationService: IInstantiationService, - @ICodeEditorService codeEditorService: ICodeEditorService, - @IThemeService themeService: IThemeService, - @INotificationService notificationService: INotificationService, - @IContextMenuService contextMenuService: IContextMenuService, - @IClipboardService clipboardService: IClipboardService, - @IEditorProgressService editorProgressService: IEditorProgressService, - ) { - super(domElement, parentEditor.getRawOptions(), codeEditorWidgetOptions, clipboardService, contextKeyService, instantiationService, codeEditorService, themeService, notificationService, contextMenuService, editorProgressService); - - this._parentEditor = parentEditor; - this._overwriteOptions = options; - - // Overwrite parent's options - super.updateOptions(this._overwriteOptions); - - this._register(parentEditor.onDidChangeConfiguration(e => this._onParentConfigurationChanged(e))); - } - - getParentEditor(): ICodeEditor { - return this._parentEditor; - } - - private _onParentConfigurationChanged(e: ConfigurationChangedEvent): void { - super.updateOptions(this._parentEditor.getRawOptions()); - super.updateOptions(this._overwriteOptions); - } - - override updateOptions(newOptions: IEditorOptions): void { - objects.mixin(this._overwriteOptions, newOptions, true); - super.updateOptions(this._overwriteOptions); - } -} - /** * TODO: Rename to EmbeddedDiffEditorWidget once EmbeddedDiffEditorWidget is removed. */ diff --git a/src/vs/editor/common/config/editorConfigurationSchema.ts b/src/vs/editor/common/config/editorConfigurationSchema.ts index 684ec85c33b..5f18e0ce03f 100644 --- a/src/vs/editor/common/config/editorConfigurationSchema.ts +++ b/src/vs/editor/common/config/editorConfigurationSchema.ts @@ -217,36 +217,30 @@ const editorConfiguration: IConfigurationNode = { 'diffEditor.hideUnchangedRegions.enabled': { type: 'boolean', default: diffEditorDefaultOptions.hideUnchangedRegions.enabled, - markdownDescription: nls.localize('hideUnchangedRegions.enabled', "Controls whether the diff editor shows unchanged regions. Only works when {0} is set.", '`#diffEditor.experimental.useVersion2#`'), + markdownDescription: nls.localize('hideUnchangedRegions.enabled', "Controls whether the diff editor shows unchanged regions."), }, 'diffEditor.hideUnchangedRegions.revealLineCount': { type: 'integer', default: diffEditorDefaultOptions.hideUnchangedRegions.revealLineCount, - markdownDescription: nls.localize('hideUnchangedRegions.revealLineCount', "Controls how many lines are used for unchanged regions. Only works when {0} is set.", '`#diffEditor.experimental.useVersion2#`'), + markdownDescription: nls.localize('hideUnchangedRegions.revealLineCount', "Controls how many lines are used for unchanged regions."), minimum: 1, }, 'diffEditor.hideUnchangedRegions.minimumLineCount': { type: 'integer', default: diffEditorDefaultOptions.hideUnchangedRegions.minimumLineCount, - markdownDescription: nls.localize('hideUnchangedRegions.minimumLineCount', "Controls how many lines are used as a minimum for unchanged regions. Only works when {0} is set.", '`#diffEditor.experimental.useVersion2#`'), + markdownDescription: nls.localize('hideUnchangedRegions.minimumLineCount', "Controls how many lines are used as a minimum for unchanged regions."), minimum: 1, }, 'diffEditor.hideUnchangedRegions.contextLineCount': { type: 'integer', default: diffEditorDefaultOptions.hideUnchangedRegions.contextLineCount, - markdownDescription: nls.localize('hideUnchangedRegions.contextLineCount', "Controls how many lines are used as context when comparing unchanged regions. Only works when {0} is set.", '`#diffEditor.experimental.useVersion2#`'), + markdownDescription: nls.localize('hideUnchangedRegions.contextLineCount', "Controls how many lines are used as context when comparing unchanged regions."), minimum: 1, }, 'diffEditor.experimental.showMoves': { type: 'boolean', default: diffEditorDefaultOptions.experimental.showMoves, - markdownDescription: nls.localize('showMoves', "Controls whether the diff editor should show detected code moves. Only works when {0} is set.", '`#diffEditor.experimental.useVersion2#`') - }, - 'diffEditor.experimental.useVersion2': { - type: 'boolean', - default: true, - description: nls.localize('useVersion2', "Controls whether the diff editor uses the new or the old implementation."), - tags: ['experimental'], + markdownDescription: nls.localize('showMoves', "Controls whether the diff editor should show detected code moves.") }, 'diffEditor.experimental.showEmptyDecorations': { type: 'boolean', diff --git a/src/vs/editor/editor.all.ts b/src/vs/editor/editor.all.ts index 71eedebd3b9..8cb672bb8dc 100644 --- a/src/vs/editor/editor.all.ts +++ b/src/vs/editor/editor.all.ts @@ -5,8 +5,7 @@ import 'vs/editor/browser/coreCommands'; import 'vs/editor/browser/widget/codeEditorWidget'; -import 'vs/editor/browser/widget/diffEditorWidget'; -import 'vs/editor/browser/widget/diffNavigator'; +import 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2'; import 'vs/editor/contrib/anchorSelect/browser/anchorSelect'; import 'vs/editor/contrib/bracketMatching/browser/bracketMatching'; import 'vs/editor/contrib/caretOperations/browser/caretOperations'; diff --git a/src/vs/editor/standalone/browser/standaloneCodeEditor.ts b/src/vs/editor/standalone/browser/standaloneCodeEditor.ts index c2eb25b69e9..7138127f621 100644 --- a/src/vs/editor/standalone/browser/standaloneCodeEditor.ts +++ b/src/vs/editor/standalone/browser/standaloneCodeEditor.ts @@ -8,7 +8,6 @@ import { Disposable, IDisposable, toDisposable, DisposableStore } from 'vs/base/ import { ICodeEditor, IDiffEditor, IDiffEditorConstructionOptions } from 'vs/editor/browser/editorBrowser'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; -import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; import { IDiffEditorOptions, IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { InternalEditorAction } from 'vs/editor/common/editorAction'; import { IModelChangedEvent } from 'vs/editor/common/editorCommon'; @@ -481,82 +480,6 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon } } -export class StandaloneDiffEditor extends DiffEditorWidget implements IStandaloneDiffEditor { - - private readonly _configurationService: IConfigurationService; - private readonly _standaloneThemeService: IStandaloneThemeService; - - constructor( - domElement: HTMLElement, - _options: Readonly | undefined, - @IInstantiationService instantiationService: IInstantiationService, - @IContextKeyService contextKeyService: IContextKeyService, - @ICodeEditorService codeEditorService: ICodeEditorService, - @IStandaloneThemeService themeService: IStandaloneThemeService, - @INotificationService notificationService: INotificationService, - @IConfigurationService configurationService: IConfigurationService, - @IContextMenuService contextMenuService: IContextMenuService, - @IEditorProgressService editorProgressService: IEditorProgressService, - @IClipboardService clipboardService: IClipboardService - ) { - const options = { ..._options }; - updateConfigurationService(configurationService, options, true); - const themeDomRegistration = (themeService).registerEditorContainer(domElement); - if (typeof options.theme === 'string') { - themeService.setTheme(options.theme); - } - if (typeof options.autoDetectHighContrast !== 'undefined') { - themeService.setAutoDetectHighContrast(Boolean(options.autoDetectHighContrast)); - } - - super(domElement, options, {}, clipboardService, contextKeyService, instantiationService, codeEditorService, themeService, notificationService, contextMenuService, editorProgressService); - - this._configurationService = configurationService; - this._standaloneThemeService = themeService; - - this._register(themeDomRegistration); - } - - public override dispose(): void { - super.dispose(); - } - - public override updateOptions(newOptions: Readonly): void { - updateConfigurationService(this._configurationService, newOptions, true); - if (typeof newOptions.theme === 'string') { - this._standaloneThemeService.setTheme(newOptions.theme); - } - if (typeof newOptions.autoDetectHighContrast !== 'undefined') { - this._standaloneThemeService.setAutoDetectHighContrast(Boolean(newOptions.autoDetectHighContrast)); - } - super.updateOptions(newOptions); - } - - protected override _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: Readonly): CodeEditorWidget { - return instantiationService.createInstance(StandaloneCodeEditor, container, options); - } - - public override getOriginalEditor(): IStandaloneCodeEditor { - return super.getOriginalEditor(); - } - - public override getModifiedEditor(): IStandaloneCodeEditor { - return super.getModifiedEditor(); - } - - public addCommand(keybinding: number, handler: ICommandHandler, context?: string): string | null { - return this.getModifiedEditor().addCommand(keybinding, handler, context); - } - - public createContextKey(key: string, defaultValue: T): IContextKey { - return this.getModifiedEditor().createContextKey(key, defaultValue); - } - - public addAction(descriptor: IActionDescriptor): IDisposable { - return this.getModifiedEditor().addAction(descriptor); - } -} - export class StandaloneDiffEditor2 extends DiffEditorWidget2 implements IStandaloneDiffEditor { private readonly _configurationService: IConfigurationService; diff --git a/src/vs/editor/standalone/browser/standaloneEditor.ts b/src/vs/editor/standalone/browser/standaloneEditor.ts index 8f8caf549a3..92cf32cf2d5 100644 --- a/src/vs/editor/standalone/browser/standaloneEditor.ts +++ b/src/vs/editor/standalone/browser/standaloneEditor.ts @@ -12,7 +12,6 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorCommand, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { IWebWorkerOptions, MonacoWebWorker, createWebWorker as actualCreateWebWorker } from 'vs/editor/browser/services/webWorker'; -import { DiffNavigator, IDiffNavigator } from 'vs/editor/browser/widget/diffNavigator'; import { ApplyUpdateResult, ConfigurationChangedEvent, EditorOptions } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { BareFontInfo, FontInfo } from 'vs/editor/common/config/fontInfo'; @@ -28,7 +27,7 @@ import { FindMatch, ITextModel, TextModelResolvedOptions } from 'vs/editor/commo import { IModelService } from 'vs/editor/common/services/model'; import * as standaloneEnums from 'vs/editor/common/standalone/standaloneEnums'; import { Colorizer, IColorizerElementOptions, IColorizerOptions } from 'vs/editor/standalone/browser/colorizer'; -import { IActionDescriptor, IStandaloneCodeEditor, IStandaloneDiffEditor, IStandaloneDiffEditorConstructionOptions, IStandaloneEditorConstructionOptions, StandaloneDiffEditor, StandaloneDiffEditor2, StandaloneEditor, createTextModel } from 'vs/editor/standalone/browser/standaloneCodeEditor'; +import { IActionDescriptor, IStandaloneCodeEditor, IStandaloneDiffEditor, IStandaloneDiffEditorConstructionOptions, IStandaloneEditorConstructionOptions, StandaloneDiffEditor2, StandaloneEditor, createTextModel } from 'vs/editor/standalone/browser/standaloneCodeEditor'; import { IEditorOverrideServices, StandaloneKeybindingService, StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices'; import { StandaloneThemeService } from 'vs/editor/standalone/browser/standaloneThemeService'; import { IStandaloneThemeData, IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneTheme'; @@ -96,21 +95,7 @@ export function getDiffEditors(): readonly IDiffEditor[] { */ export function createDiffEditor(domElement: HTMLElement, options?: IStandaloneDiffEditorConstructionOptions, override?: IEditorOverrideServices): IStandaloneDiffEditor { const instantiationService = StandaloneServices.initialize(override || {}); - if ((options?.experimental as any)?.useVersion2) { - return instantiationService.createInstance(StandaloneDiffEditor2, domElement, options); - } - return instantiationService.createInstance(StandaloneDiffEditor, domElement, options); -} - -export interface IDiffNavigatorOptions { - readonly followsCaret?: boolean; - readonly ignoreCharChanges?: boolean; - readonly alwaysRevealFirst?: boolean; -} - -export function createDiffNavigator(diffEditor: IStandaloneDiffEditor, opts?: IDiffNavigatorOptions): IDiffNavigator { - const instantiationService = StandaloneServices.initialize({}); - return instantiationService.createInstance(DiffNavigator, diffEditor, opts); + return instantiationService.createInstance(StandaloneDiffEditor2, domElement, options); } /** @@ -516,7 +501,6 @@ export function createMonacoEditorAPI(): typeof monaco.editor { onDidCreateEditor: onDidCreateEditor, onDidCreateDiffEditor: onDidCreateDiffEditor, createDiffEditor: createDiffEditor, - createDiffNavigator: createDiffNavigator, addCommand: addCommand, addEditorAction: addEditorAction, diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 168b46965be..2148581e50f 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -937,13 +937,6 @@ declare namespace monaco { declare namespace monaco.editor { - export interface IDiffNavigator { - canNavigate(): boolean; - next(): void; - previous(): void; - dispose(): void; - } - /** * Create a new editor under `domElement`. * `domElement` should be empty (not contain other dom nodes). @@ -981,14 +974,6 @@ declare namespace monaco.editor { */ export function createDiffEditor(domElement: HTMLElement, options?: IStandaloneDiffEditorConstructionOptions, override?: IEditorOverrideServices): IStandaloneDiffEditor; - export interface IDiffNavigatorOptions { - readonly followsCaret?: boolean; - readonly ignoreCharChanges?: boolean; - readonly alwaysRevealFirst?: boolean; - } - - export function createDiffNavigator(diffEditor: IStandaloneDiffEditor, opts?: IDiffNavigatorOptions): IDiffNavigator; - /** * Description of a command contribution */ diff --git a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts index adb0fcddd35..58377fcf767 100644 --- a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts @@ -13,7 +13,6 @@ import { TEXT_DIFF_EDITOR_ID, IEditorFactoryRegistry, EditorExtensions, ITextDif import { EditorInput } from 'vs/workbench/common/editor/editorInput'; import { applyTextEditorOptions } from 'vs/workbench/common/editor/editorOptions'; import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; -import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; import { TextDiffEditorModel } from 'vs/workbench/common/editor/textDiffEditorModel'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IStorageService } from 'vs/platform/storage/common/storage'; @@ -22,7 +21,6 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { IThemeService } from 'vs/platform/theme/common/themeService'; import { TextFileOperationError, TextFileOperationResult } from 'vs/workbench/services/textfile/common/textfiles'; import { ScrollType, IDiffEditorViewState, IDiffEditorModel } from 'vs/editor/common/editorCommon'; -import { DisposableStore } from 'vs/base/common/lifecycle'; import { Registry } from 'vs/platform/registry/common/platform'; import { URI } from 'vs/base/common/uri'; import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; @@ -43,12 +41,9 @@ import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/di */ export class TextDiffEditor extends AbstractTextEditor implements ITextDiffEditorPane { static readonly ID = TEXT_DIFF_EDITOR_ID; - private static widgetCounter = 0; // Just for debugging private diffEditorControl: IDiffEditor | undefined = undefined; - private readonly diffNavigatorDisposables = this._register(new DisposableStore()); - private inputLifecycleStopWatch: StopWatch | undefined = undefined; override get scopedContextKeyService(): IContextKeyService | undefined { @@ -85,18 +80,7 @@ export class TextDiffEditor extends AbstractTextEditor imp } protected override createEditorControl(parent: HTMLElement, configuration: ICodeEditorOptions): void { - TextDiffEditor.widgetCounter++; - let useVersion2 = this.textResourceConfigurationService.getValue(undefined, 'diffEditor.experimental.useVersion2'); - if (useVersion2 === 'first') { - // This allows to have both the old and new diff editor next to each other - just for debugging - useVersion2 = TextDiffEditor.widgetCounter === 1; - } - - if (useVersion2) { - this.diffEditorControl = this._register(this.instantiationService.createInstance(DiffEditorWidget2, parent, configuration, {})); - } else { - this.diffEditorControl = this._register(this.instantiationService.createInstance(DiffEditorWidget, parent, configuration, {})); - } + this.diffEditorControl = this._register(this.instantiationService.createInstance(DiffEditorWidget2, parent, configuration, {})); } protected updateEditorControlOptions(options: ICodeEditorOptions): void { @@ -111,7 +95,6 @@ export class TextDiffEditor extends AbstractTextEditor imp // Cleanup previous things associated with the input this.inputLifecycleStopWatch = undefined; - this.diffNavigatorDisposables.clear(); // Set input and resolve await super.setInput(input, options, context, token); @@ -324,9 +307,6 @@ export class TextDiffEditor extends AbstractTextEditor imp this.logInputLifecycleTelemetry(inputLifecycleElapsed, this.getControl()?.getModel()?.modified?.getLanguageId()); } - // Dispose previous diff navigator - this.diffNavigatorDisposables.clear(); - // Clear Model this.diffEditorControl?.setModel(null); } diff --git a/src/vs/workbench/contrib/codeEditor/browser/diffEditorHelper.ts b/src/vs/workbench/contrib/codeEditor/browser/diffEditorHelper.ts index f9f2bd13d28..d8c0d322bf3 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/diffEditorHelper.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/diffEditorHelper.ts @@ -10,7 +10,7 @@ import { registerDiffEditorContribution } from 'vs/editor/browser/editorExtensio import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { AccessibleDiffViewerNext, AccessibleDiffViewerPrev } from 'vs/editor/browser/widget/diffEditor.contribution'; import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2'; -import { EmbeddedDiffEditorWidget, EmbeddedDiffEditorWidget2 } from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; +import { EmbeddedDiffEditorWidget2 } from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; import { IDiffEditorContribution } from 'vs/editor/common/editorCommon'; import { localize } from 'vs/nls'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -39,7 +39,7 @@ class DiffEditorHelperContribution extends Disposable implements IDiffEditorCont this._register(createScreenReaderHelp()); - const isEmbeddedDiffEditor = (this._diffEditor instanceof EmbeddedDiffEditorWidget) || (this._diffEditor instanceof EmbeddedDiffEditorWidget2); + const isEmbeddedDiffEditor = this._diffEditor instanceof EmbeddedDiffEditorWidget2; if (!isEmbeddedDiffEditor) { const computationResult = observableFromEvent(e => this._diffEditor.onDidUpdateDiff(e), () => this._diffEditor.getDiffComputationResult()); diff --git a/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts b/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts index 7ab77c57846..369eef0d3cf 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts @@ -10,7 +10,6 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { DiffElementViewModelBase, getFormattedMetadataJSON, getFormattedOutputJSON, OutputComparison, outputEqual, OUTPUT_EDITOR_HEIGHT_MAGIC, PropertyFoldingState, SideBySideDiffElementViewModel, SingleSideDiffElementViewModel } from 'vs/workbench/contrib/notebook/browser/diff/diffElementViewModel'; import { CellDiffSideBySideRenderTemplate, CellDiffSingleSideRenderTemplate, DiffSide, DIFF_CELL_MARGIN, INotebookTextDiffEditor, NOTEBOOK_DIFF_CELL_INPUT, NOTEBOOK_DIFF_CELL_PROPERTY, NOTEBOOK_DIFF_CELL_PROPERTY_EXPANDED } from 'vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser'; import { CodeEditorWidget, ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget'; -import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; import { IModelService } from 'vs/editor/common/services/model'; import { ILanguageService } from 'vs/editor/common/languages/language'; import { CellEditType, CellUri, NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon'; @@ -42,6 +41,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { fixedDiffEditorOptions, fixedEditorOptions, fixedEditorPadding } from 'vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions'; import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityConfiguration'; import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; +import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2'; export function getOptimizedNestedCodeEditorWidgetOptions(): ICodeEditorWidgetOptions { return { @@ -242,7 +242,7 @@ abstract class AbstractElementRenderer extends Disposable { protected _metadataInfoContainer!: HTMLElement; protected _metadataEditorContainer?: HTMLElement; protected _metadataEditorDisposeStore!: DisposableStore; - protected _metadataEditor?: CodeEditorWidget | DiffEditorWidget; + protected _metadataEditor?: CodeEditorWidget | DiffEditorWidget2; protected _outputHeaderContainer!: HTMLElement; protected _outputHeader!: PropertyHeader; @@ -256,8 +256,8 @@ abstract class AbstractElementRenderer extends Disposable { protected _outputLeftView?: OutputContainer; protected _outputRightView?: OutputContainer; protected _outputEditorDisposeStore!: DisposableStore; - protected _outputEditor?: CodeEditorWidget | DiffEditorWidget; - protected _outputMetadataEditor?: DiffEditorWidget; + protected _outputEditor?: CodeEditorWidget | DiffEditorWidget2; + protected _outputMetadataEditor?: DiffEditorWidget2; protected _diffEditorContainer!: HTMLElement; protected _diagonalFill?: HTMLElement; @@ -493,7 +493,7 @@ abstract class AbstractElementRenderer extends Disposable { this._metadataEditorDisposeStore.clear(); if (this.cell instanceof SideBySideDiffElementViewModel) { - this._metadataEditor = this.instantiationService.createInstance(DiffEditorWidget, this._metadataEditorContainer!, { + this._metadataEditor = this.instantiationService.createInstance(DiffEditorWidget2, this._metadataEditorContainer!, { ...fixedDiffEditorOptions, overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(), readOnly: false, @@ -606,7 +606,7 @@ abstract class AbstractElementRenderer extends Disposable { const lineHeight = this.notebookEditor.getLayoutInfo().fontInfo.lineHeight || 17; const lineCount = Math.max(originalModel.getLineCount(), modifiedModel.getLineCount()); - this._outputEditor = this.instantiationService.createInstance(DiffEditorWidget, this._outputEditorContainer!, { + this._outputEditor = this.instantiationService.createInstance(DiffEditorWidget2, this._outputEditorContainer!, { ...fixedDiffEditorOptions, overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(), readOnly: true, @@ -1214,7 +1214,7 @@ export class InsertElement extends SingleSideDiffElement { } export class ModifiedElement extends AbstractElementRenderer { - private _editor?: DiffEditorWidget; + private _editor?: DiffEditorWidget2; private _editorViewStateChanged: boolean; private _editorContainer!: HTMLElement; private _inputToolbarContainer!: HTMLElement; @@ -1416,7 +1416,7 @@ export class ModifiedElement extends AbstractElementRenderer { this._outputMetadataContainer.style.top = `${this.cell.layoutInfo.rawOutputHeight}px`; // single output, metadata change, let's render a diff editor for metadata - this._outputMetadataEditor = this.instantiationService.createInstance(DiffEditorWidget, this._outputMetadataContainer!, { + this._outputMetadataEditor = this.instantiationService.createInstance(DiffEditorWidget2, this._outputMetadataContainer!, { ...fixedDiffEditorOptions, overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(), readOnly: true, diff --git a/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.ts b/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.ts index 0dd0c906d17..bd56f8c7ff4 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.ts @@ -8,7 +8,7 @@ import { hash } from 'vs/base/common/hash'; import { toFormattedString } from 'vs/base/common/jsonFormatter'; import { Disposable } from 'vs/base/common/lifecycle'; import { URI } from 'vs/base/common/uri'; -import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; +import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2'; import { FontInfo } from 'vs/editor/common/config/fontInfo'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { fixedEditorPadding } from 'vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions'; @@ -341,10 +341,10 @@ export abstract class DiffElementViewModelBase extends Disposable { getComputedCellContainerWidth(layoutInfo: NotebookLayoutInfo, diffEditor: boolean, fullWidth: boolean) { if (fullWidth) { - return layoutInfo.width - 2 * DIFF_CELL_MARGIN + (diffEditor ? DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH : 0) - 2; + return layoutInfo.width - 2 * DIFF_CELL_MARGIN + (diffEditor ? DiffEditorWidget2.ENTIRE_DIFF_OVERVIEW_WIDTH : 0) - 2; } - return (layoutInfo.width - 2 * DIFF_CELL_MARGIN + (diffEditor ? DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH : 0)) / 2 - 18 - 2; + return (layoutInfo.width - 2 * DIFF_CELL_MARGIN + (diffEditor ? DiffEditorWidget2.ENTIRE_DIFF_OVERVIEW_WIDTH : 0)) / 2 - 18 - 2; } getOutputEditorViewState(): editorCommon.ICodeEditorViewState | editorCommon.IDiffEditorViewState | null { diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.ts index 7148cccf5a3..62601268ebd 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.ts @@ -10,12 +10,12 @@ import { BareFontInfo } from 'vs/editor/common/config/fontInfo'; import { DisposableStore } from 'vs/base/common/lifecycle'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; -import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent'; import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { NotebookOptions } from 'vs/workbench/contrib/notebook/browser/notebookOptions'; import { NotebookLayoutInfo } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents'; import { WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar'; +import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2'; export enum DiffSide { Original = 0, @@ -85,7 +85,7 @@ export interface CellDiffSideBySideRenderTemplate extends CellDiffCommonRenderTe readonly body: HTMLElement; readonly diffEditorContainer: HTMLElement; readonly elementDisposables: DisposableStore; - readonly sourceEditor: DiffEditorWidget; + readonly sourceEditor: DiffEditorWidget2; readonly editorContainer: HTMLElement; readonly inputToolbarContainer: HTMLElement; readonly toolbar: WorkbenchToolBar; diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.ts index 7cff07828c4..af0bb4a20f4 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.ts @@ -18,7 +18,7 @@ import { DiffElementViewModelBase, SideBySideDiffElementViewModel, SingleSideDif import { CellDiffSideBySideRenderTemplate, CellDiffSingleSideRenderTemplate, DIFF_CELL_MARGIN, INotebookTextDiffEditor } from 'vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser'; import { DeletedElement, getOptimizedNestedCodeEditorWidgetOptions, InsertElement, ModifiedElement } from 'vs/workbench/contrib/notebook/browser/diff/diffComponents'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; -import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; +import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2'; import { IMenuService, MenuItemAction } from 'vs/platform/actions/common/actions'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { INotificationService } from 'vs/platform/notification/common/notification'; @@ -234,7 +234,7 @@ export class CellDiffSideBySideRenderer implements IListRenderer