diffEditorWidget.ts 82.2 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import 'vs/css!./media/diffEditor';
7
import * as nls from 'vs/nls';
A
Alex Dima 已提交
8
import * as dom from 'vs/base/browser/dom';
A
Alex Dima 已提交
9
import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode';
J
Joao Moreno 已提交
10
import { ISashEvent, IVerticalSashLayoutProvider, Sash, SashState } from 'vs/base/browser/ui/sash/sash';
A
Alex Dima 已提交
11
import { RunOnceScheduler, IntervalTimer } from 'vs/base/common/async';
A
Alex Dima 已提交
12 13 14 15 16 17 18
import { Color } from 'vs/base/common/color';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import * as objects from 'vs/base/common/objects';
import { URI } from 'vs/base/common/uri';
import { Configuration } from 'vs/editor/browser/config/configuration';
import { StableEditorScrollState } from 'vs/editor/browser/core/editorState';
A
Alex Dima 已提交
19
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
A
Alex Dima 已提交
20
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
A
Alex Dima 已提交
21
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
A
Alex Dima 已提交
22
import { DiffReview } from 'vs/editor/browser/widget/diffReview';
23
import { IDiffEditorOptions, IEditorOptions, EditorLayoutInfo, IComputedEditorOptions, EditorOption, EditorOptions, EditorFontLigatures } from 'vs/editor/common/config/editorOptions';
A
Alex Dima 已提交
24 25 26 27 28 29 30 31
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 { IStringBuilder, createStringBuilder } from 'vs/editor/common/core/stringBuilder';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IModelDecorationsChangeAccessor, IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { IDiffComputationResult, IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
32
import { OverviewRulerZone } from 'vs/editor/common/view/overviewZoneManager';
A
Alex Dima 已提交
33 34
import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations';
import { RenderLineInput, renderViewLine } from 'vs/editor/common/viewLayout/viewLineRenderer';
A
Alexandru Dima 已提交
35
import { EditorWhitespace } from 'vs/editor/common/viewLayout/linesLayout';
A
Alex Dima 已提交
36 37 38 39
import { InlineDecoration, InlineDecorationType, ViewLineRenderingData } from 'vs/editor/common/viewModel/viewModel';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
40
import { INotificationService } from 'vs/platform/notification/common/notification';
A
Alex Dima 已提交
41 42
import { defaultInsertColor, defaultRemoveColor, diffBorder, diffInserted, diffInsertedOutline, diffRemoved, diffRemovedOutline, scrollbarShadow } from 'vs/platform/theme/common/colorRegistry';
import { ITheme, IThemeService, getThemeTypeSelector, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
43 44 45
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IDiffLinesChange, InlineDiffMargin } from 'vs/editor/browser/widget/inlineDiffMargin';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
46
import { Constants } from 'vs/base/common/uint';
47
import { EditorExtensionsRegistry, IDiffEditorContributionDescription } from 'vs/editor/browser/editorExtensions';
A
Alex Dima 已提交
48
import { onUnexpectedError } from 'vs/base/common/errors';
49
import { IEditorProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
E
Erich Gamma 已提交
50 51

interface IEditorDiffDecorations {
52
	decorations: IModelDeltaDecoration[];
A
Alex Dima 已提交
53
	overviewZones: OverviewRulerZone[];
E
Erich Gamma 已提交
54 55 56
}

interface IEditorDiffDecorationsWithZones extends IEditorDiffDecorations {
57
	zones: IMyViewZone[];
E
Erich Gamma 已提交
58 59 60
}

interface IEditorsDiffDecorationsWithZones {
J
Johannes Rieken 已提交
61 62
	original: IEditorDiffDecorationsWithZones;
	modified: IEditorDiffDecorationsWithZones;
E
Erich Gamma 已提交
63 64 65
}

interface IEditorsZones {
66 67
	original: IMyViewZone[];
	modified: IMyViewZone[];
E
Erich Gamma 已提交
68 69 70
}

interface IDiffEditorWidgetStyle {
A
Alexandru Dima 已提交
71
	getEditorsDiffDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalWhitespaces: EditorWhitespace[], modifiedWhitespaces: EditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorsDiffDecorationsWithZones;
J
Johannes Rieken 已提交
72
	setEnableSplitViewResizing(enableSplitViewResizing: boolean): void;
73
	applyColors(theme: ITheme): boolean;
E
Erich Gamma 已提交
74 75 76 77 78
	layout(): number;
	dispose(): void;
}

class VisualEditorState {
A
Alex Dima 已提交
79
	private _zones: string[];
80
	private inlineDiffMargins: InlineDiffMargin[];
J
Johannes Rieken 已提交
81 82
	private _zonesMap: { [zoneId: string]: boolean; };
	private _decorations: string[];
E
Erich Gamma 已提交
83

84 85
	constructor(
		private _contextMenuService: IContextMenuService,
86
		private _clipboardService: IClipboardService | null
87
	) {
E
Erich Gamma 已提交
88
		this._zones = [];
89
		this.inlineDiffMargins = [];
E
Erich Gamma 已提交
90 91 92 93
		this._zonesMap = {};
		this._decorations = [];
	}

A
Alexandru Dima 已提交
94
	public getForeignViewZones(allViewZones: EditorWhitespace[]): EditorWhitespace[] {
E
Erich Gamma 已提交
95 96 97
		return allViewZones.filter((z) => !this._zonesMap[String(z.id)]);
	}

A
Alex Dima 已提交
98
	public clean(editor: CodeEditorWidget): void {
E
Erich Gamma 已提交
99 100
		// (1) View zones
		if (this._zones.length > 0) {
J
Johannes Rieken 已提交
101
			editor.changeViewZones((viewChangeAccessor: editorBrowser.IViewZoneChangeAccessor) => {
A
Alex Dima 已提交
102
				for (let i = 0, length = this._zones.length; i < length; i++) {
E
Erich Gamma 已提交
103 104 105 106 107 108 109 110
					viewChangeAccessor.removeZone(this._zones[i]);
				}
			});
		}
		this._zones = [];
		this._zonesMap = {};

		// (2) Model decorations
A
Alex Dima 已提交
111
		this._decorations = editor.deltaDecorations(this._decorations, []);
E
Erich Gamma 已提交
112 113
	}

A
Alex Dima 已提交
114
	public apply(editor: CodeEditorWidget, overviewRuler: editorBrowser.IOverviewRuler, newDecorations: IEditorDiffDecorationsWithZones, restoreScrollState: boolean): void {
A
Alex Dima 已提交
115 116 117

		const scrollState = restoreScrollState ? StableEditorScrollState.capture(editor) : null;

E
Erich Gamma 已提交
118
		// view zones
J
Johannes Rieken 已提交
119
		editor.changeViewZones((viewChangeAccessor: editorBrowser.IViewZoneChangeAccessor) => {
A
Alex Dima 已提交
120
			for (let i = 0, length = this._zones.length; i < length; i++) {
E
Erich Gamma 已提交
121 122
				viewChangeAccessor.removeZone(this._zones[i]);
			}
123 124 125
			for (let i = 0, length = this.inlineDiffMargins.length; i < length; i++) {
				this.inlineDiffMargins[i].dispose();
			}
E
Erich Gamma 已提交
126 127
			this._zones = [];
			this._zonesMap = {};
128
			this.inlineDiffMargins = [];
A
Alex Dima 已提交
129
			for (let i = 0, length = newDecorations.zones.length; i < length; i++) {
130 131 132
				const viewZone = <editorBrowser.IViewZone>newDecorations.zones[i];
				viewZone.suppressMouseDown = false;
				let zoneId = viewChangeAccessor.addZone(viewZone);
E
Erich Gamma 已提交
133 134
				this._zones.push(zoneId);
				this._zonesMap[String(zoneId)] = true;
135

136
				if (newDecorations.zones[i].diff && viewZone.marginDomNode && this._clipboardService) {
P
Peng Lyu 已提交
137
					this.inlineDiffMargins.push(new InlineDiffMargin(zoneId, viewZone.marginDomNode, editor, newDecorations.zones[i].diff!, this._contextMenuService, this._clipboardService));
138
				}
E
Erich Gamma 已提交
139 140 141
			}
		});

A
Alex Dima 已提交
142 143 144 145
		if (scrollState) {
			scrollState.restore(editor);
		}

E
Erich Gamma 已提交
146 147 148 149
		// decorations
		this._decorations = editor.deltaDecorations(this._decorations, newDecorations.decorations);

		// overview ruler
150 151 152
		if (overviewRuler) {
			overviewRuler.setZones(newDecorations.overviewZones);
		}
E
Erich Gamma 已提交
153 154 155
	}
}

A
Alex Dima 已提交
156
let DIFF_EDITOR_ID = 0;
E
Erich Gamma 已提交
157

A
Alex Dima 已提交
158
export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffEditor {
A
Alex Dima 已提交
159

160
	private static readonly ONE_OVERVIEW_WIDTH = 15;
M
Matt Bierner 已提交
161
	public static readonly ENTIRE_DIFF_OVERVIEW_WIDTH = 30;
162
	private static readonly UPDATE_DIFF_DECORATIONS_DELAY = 200; // ms
E
Erich Gamma 已提交
163

A
Alex Dima 已提交
164 165
	private readonly _onDidDispose: Emitter<void> = this._register(new Emitter<void>());
	public readonly onDidDispose: Event<void> = this._onDidDispose.event;
E
Erich Gamma 已提交
166

A
Alex Dima 已提交
167 168 169 170
	private readonly _onDidUpdateDiff: Emitter<void> = this._register(new Emitter<void>());
	public readonly onDidUpdateDiff: Event<void> = this._onDidUpdateDiff.event;

	private readonly id: number;
171
	private _state: editorBrowser.DiffEditorState;
172
	private _updatingDiffProgress: IProgressRunner | null;
E
Erich Gamma 已提交
173

174
	private readonly _domElement: HTMLElement;
A
Alex Dima 已提交
175 176 177
	protected readonly _containerDomElement: HTMLElement;
	private readonly _overviewDomElement: HTMLElement;
	private readonly _overviewViewportDomElement: FastDomNode<HTMLElement>;
E
Erich Gamma 已提交
178

J
Johannes Rieken 已提交
179 180
	private _width: number;
	private _height: number;
A
Alex Dima 已提交
181
	private _reviewHeight: number;
A
Alex Dima 已提交
182
	private readonly _measureDomElementToken: IntervalTimer | null;
E
Erich Gamma 已提交
183

A
Alex Dima 已提交
184
	private readonly originalEditor: CodeEditorWidget;
A
Alex Dima 已提交
185
	private readonly _originalDomNode: HTMLElement;
186
	private readonly _originalEditorState: VisualEditorState;
A
Alex Dima 已提交
187
	private _originalOverviewRuler: editorBrowser.IOverviewRuler | null;
E
Erich Gamma 已提交
188

A
Alex Dima 已提交
189
	private readonly modifiedEditor: CodeEditorWidget;
A
Alex Dima 已提交
190
	private readonly _modifiedDomNode: HTMLElement;
191
	private readonly _modifiedEditorState: VisualEditorState;
A
Alex Dima 已提交
192
	private _modifiedOverviewRuler: editorBrowser.IOverviewRuler | null;
E
Erich Gamma 已提交
193

J
Johannes Rieken 已提交
194 195 196
	private _currentlyChangingViewZones: boolean;
	private _beginUpdateDecorationsTimeout: number;
	private _diffComputationToken: number;
A
Alex Dima 已提交
197
	private _diffComputationResult: IDiffComputationResult | null;
E
Erich Gamma 已提交
198

J
Johannes Rieken 已提交
199 200
	private _isVisible: boolean;
	private _isHandlingScrollEvent: boolean;
E
Erich Gamma 已提交
201 202

	private _ignoreTrimWhitespace: boolean;
203
	private _originalIsEditable: boolean;
E
Erich Gamma 已提交
204

J
Johannes Rieken 已提交
205
	private _renderSideBySide: boolean;
206
	private _maxComputationTime: number;
207
	private _renderIndicators: boolean;
J
Johannes Rieken 已提交
208
	private _enableSplitViewResizing: boolean;
A
Alex Dima 已提交
209
	private _strategy!: IDiffEditorWidgetStyle;
E
Erich Gamma 已提交
210

211
	private readonly _updateDecorationsRunner: RunOnceScheduler;
E
Erich Gamma 已提交
212

213
	private readonly _editorWorkerService: IEditorWorkerService;
214
	protected _contextKeyService: IContextKeyService;
215 216 217
	private readonly _codeEditorService: ICodeEditorService;
	private readonly _themeService: IThemeService;
	private readonly _notificationService: INotificationService;
218

219
	private readonly _reviewPane: DiffReview;
A
Alex Dima 已提交
220

221
	constructor(
J
Johannes Rieken 已提交
222
		domElement: HTMLElement,
223
		options: IDiffEditorOptions,
224
		clipboardService: IClipboardService | null,
225
		@IEditorWorkerService editorWorkerService: IEditorWorkerService,
226
		@IContextKeyService contextKeyService: IContextKeyService,
227
		@IInstantiationService instantiationService: IInstantiationService,
228
		@ICodeEditorService codeEditorService: ICodeEditorService,
229
		@IThemeService themeService: IThemeService,
230 231
		@INotificationService notificationService: INotificationService,
		@IContextMenuService contextMenuService: IContextMenuService,
232
		@IEditorProgressService private readonly _editorProgressService: IEditorProgressService
233
	) {
E
Erich Gamma 已提交
234
		super();
A
Alex Dima 已提交
235

236
		this._editorWorkerService = editorWorkerService;
237
		this._codeEditorService = codeEditorService;
238
		this._contextKeyService = this._register(contextKeyService.createScoped(domElement));
J
Joao Moreno 已提交
239
		this._contextKeyService.createKey('isInDiffEditor', true);
240
		this._themeService = themeService;
241
		this._notificationService = notificationService;
E
Erich Gamma 已提交
242 243

		this.id = (++DIFF_EDITOR_ID);
244
		this._state = editorBrowser.DiffEditorState.Idle;
245
		this._updatingDiffProgress = null;
E
Erich Gamma 已提交
246 247 248 249 250 251 252 253 254 255

		this._domElement = domElement;
		options = options || {};

		// renderSideBySide
		this._renderSideBySide = true;
		if (typeof options.renderSideBySide !== 'undefined') {
			this._renderSideBySide = options.renderSideBySide;
		}

256 257 258 259
		// maxComputationTime
		this._maxComputationTime = 5000;
		if (typeof options.maxComputationTime !== 'undefined') {
			this._maxComputationTime = options.maxComputationTime;
260 261
		}

E
Erich Gamma 已提交
262 263 264 265 266 267
		// ignoreTrimWhitespace
		this._ignoreTrimWhitespace = true;
		if (typeof options.ignoreTrimWhitespace !== 'undefined') {
			this._ignoreTrimWhitespace = options.ignoreTrimWhitespace;
		}

268 269 270 271 272 273
		// renderIndicators
		this._renderIndicators = true;
		if (typeof options.renderIndicators !== 'undefined') {
			this._renderIndicators = options.renderIndicators;
		}

274 275 276 277 278
		this._originalIsEditable = false;
		if (typeof options.originalEditable !== 'undefined') {
			this._originalIsEditable = Boolean(options.originalEditable);
		}

A
Alex Dima 已提交
279
		this._updateDecorationsRunner = this._register(new RunOnceScheduler(() => this._updateDecorations(), 0));
E
Erich Gamma 已提交
280 281

		this._containerDomElement = document.createElement('div');
282
		this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getTheme(), this._renderSideBySide);
E
Erich Gamma 已提交
283 284 285 286
		this._containerDomElement.style.position = 'relative';
		this._containerDomElement.style.height = '100%';
		this._domElement.appendChild(this._containerDomElement);

A
Alex Dima 已提交
287 288 289
		this._overviewViewportDomElement = createFastDomNode(document.createElement('div'));
		this._overviewViewportDomElement.setClassName('diffViewport');
		this._overviewViewportDomElement.setPosition('absolute');
E
Erich Gamma 已提交
290 291 292 293 294

		this._overviewDomElement = document.createElement('div');
		this._overviewDomElement.className = 'diffOverview';
		this._overviewDomElement.style.position = 'absolute';

A
Alex Dima 已提交
295
		this._overviewDomElement.appendChild(this._overviewViewportDomElement.domNode);
E
Erich Gamma 已提交
296

297
		this._register(dom.addStandardDisposableListener(this._overviewDomElement, 'mousedown', (e) => {
E
Erich Gamma 已提交
298 299 300 301
			this.modifiedEditor.delegateVerticalScrollbarMouseDown(e);
		}));
		this._containerDomElement.appendChild(this._overviewDomElement);

A
Alex Dima 已提交
302 303 304 305 306 307 308 309 310 311 312 313 314
		// 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);
E
Erich Gamma 已提交
315 316 317 318 319

		this._beginUpdateDecorationsTimeout = -1;
		this._currentlyChangingViewZones = false;
		this._diffComputationToken = 0;

320 321
		this._originalEditorState = new VisualEditorState(contextMenuService, clipboardService);
		this._modifiedEditorState = new VisualEditorState(contextMenuService, clipboardService);
E
Erich Gamma 已提交
322 323 324 325 326 327

		this._isVisible = true;
		this._isHandlingScrollEvent = false;

		this._width = 0;
		this._height = 0;
A
Alex Dima 已提交
328
		this._reviewHeight = 0;
E
Erich Gamma 已提交
329

A
Alex Dima 已提交
330
		this._diffComputationResult = null;
E
Erich Gamma 已提交
331

332 333
		const leftContextKeyService = this._contextKeyService.createScoped();
		leftContextKeyService.createKey('isInDiffLeftEditor', true);
J
Joao Moreno 已提交
334

335 336 337
		const leftServices = new ServiceCollection();
		leftServices.set(IContextKeyService, leftContextKeyService);
		const leftScopedInstantiationService = instantiationService.createChild(leftServices);
J
Joao Moreno 已提交
338

339 340 341 342 343 344 345
		const rightContextKeyService = this._contextKeyService.createScoped();
		rightContextKeyService.createKey('isInDiffRightEditor', true);

		const rightServices = new ServiceCollection();
		rightServices.set(IContextKeyService, rightContextKeyService);
		const rightScopedInstantiationService = instantiationService.createChild(rightServices);

A
Alex Dima 已提交
346 347 348 349 350
		this.originalEditor = this._createLeftHandSideEditor(options, leftScopedInstantiationService);
		this.modifiedEditor = this._createRightHandSideEditor(options, rightScopedInstantiationService);

		this._originalOverviewRuler = null;
		this._modifiedOverviewRuler = null;
E
Erich Gamma 已提交
351

352 353 354
		this._reviewPane = new DiffReview(this);
		this._containerDomElement.appendChild(this._reviewPane.domNode.domNode);
		this._containerDomElement.appendChild(this._reviewPane.shadow.domNode);
355
		this._containerDomElement.appendChild(this._reviewPane.actionBarContainer.domNode);
356

E
Erich Gamma 已提交
357
		if (options.automaticLayout) {
A
Alex Dima 已提交
358 359 360 361
			this._measureDomElementToken = new IntervalTimer();
			this._measureDomElementToken.cancelAndSet(() => this._measureDomElement(false), 100);
		} else {
			this._measureDomElementToken = null;
E
Erich Gamma 已提交
362 363 364 365 366 367 368 369 370
		}

		// enableSplitViewResizing
		this._enableSplitViewResizing = true;
		if (typeof options.enableSplitViewResizing !== 'undefined') {
			this._enableSplitViewResizing = options.enableSplitViewResizing;
		}

		if (this._renderSideBySide) {
H
Howard Hung 已提交
371
			this._setStrategy(new DiffEditorWidgetSideBySide(this._createDataSource(), this._enableSplitViewResizing));
E
Erich Gamma 已提交
372
		} else {
H
Howard Hung 已提交
373
			this._setStrategy(new DiffEditorWidgetInline(this._createDataSource(), this._enableSplitViewResizing));
E
Erich Gamma 已提交
374
		}
375

376
		this._register(themeService.onThemeChange(t => {
377 378 379
			if (this._strategy && this._strategy.applyColors(t)) {
				this._updateDecorationsRunner.schedule();
			}
380 381
			this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getTheme(), this._renderSideBySide);
		}));
382

383 384
		const contributions: IDiffEditorContributionDescription[] = EditorExtensionsRegistry.getDiffEditorContributions();
		for (const desc of contributions) {
A
Alex Dima 已提交
385
			try {
386
				this._register(instantiationService.createInstance(desc.ctor, this));
A
Alex Dima 已提交
387 388 389 390 391
			} catch (err) {
				onUnexpectedError(err);
			}
		}

392
		this._codeEditorService.addDiffEditor(this);
E
Erich Gamma 已提交
393 394
	}

395 396 397 398 399 400 401 402
	public get ignoreTrimWhitespace(): boolean {
		return this._ignoreTrimWhitespace;
	}

	public get renderSideBySide(): boolean {
		return this._renderSideBySide;
	}

403 404 405 406
	public get maxComputationTime(): number {
		return this._maxComputationTime;
	}

407 408 409 410
	public get renderIndicators(): boolean {
		return this._renderIndicators;
	}

411
	private _setState(newState: editorBrowser.DiffEditorState): void {
412
		if (this._state === newState) {
413 414 415
			return;
		}
		this._state = newState;
416 417 418 419 420 421 422 423 424

		if (this._updatingDiffProgress) {
			this._updatingDiffProgress.done();
			this._updatingDiffProgress = null;
		}

		if (this._state === editorBrowser.DiffEditorState.ComputingDiff) {
			this._updatingDiffProgress = this._editorProgressService.show(true, 1000);
		}
425 426
	}

A
Alex Dima 已提交
427 428 429 430 431 432 433 434 435 436 437 438
	public hasWidgetFocus(): boolean {
		return dom.isAncestor(document.activeElement, this._domElement);
	}

	public diffReviewNext(): void {
		this._reviewPane.next();
	}

	public diffReviewPrev(): void {
		this._reviewPane.prev();
	}

439
	private static _getClassName(theme: ITheme, renderSideBySide: boolean): string {
A
Alex Dima 已提交
440
		let result = 'monaco-diff-editor monaco-editor-background ';
E
Erich Gamma 已提交
441 442 443
		if (renderSideBySide) {
			result += 'side-by-side ';
		}
444
		result += getThemeTypeSelector(theme.type);
E
Erich Gamma 已提交
445 446 447 448 449 450 451 452
		return result;
	}

	private _recreateOverviewRulers(): void {
		if (this._originalOverviewRuler) {
			this._overviewDomElement.removeChild(this._originalOverviewRuler.getDomNode());
			this._originalOverviewRuler.dispose();
		}
A
Alex Dima 已提交
453 454 455 456
		if (this.originalEditor.hasModel()) {
			this._originalOverviewRuler = this.originalEditor.createOverviewRuler('original diffOverviewRuler')!;
			this._overviewDomElement.appendChild(this._originalOverviewRuler.getDomNode());
		}
E
Erich Gamma 已提交
457 458 459 460 461

		if (this._modifiedOverviewRuler) {
			this._overviewDomElement.removeChild(this._modifiedOverviewRuler.getDomNode());
			this._modifiedOverviewRuler.dispose();
		}
A
Alex Dima 已提交
462 463 464 465
		if (this.modifiedEditor.hasModel()) {
			this._modifiedOverviewRuler = this.modifiedEditor.createOverviewRuler('modified diffOverviewRuler')!;
			this._overviewDomElement.appendChild(this._modifiedOverviewRuler.getDomNode());
		}
E
Erich Gamma 已提交
466 467 468 469

		this._layoutOverviewRulers();
	}

470
	private _createLeftHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget {
A
Alex Dima 已提交
471
		const editor = this._createInnerEditor(instantiationService, this._originalDomNode, this._adjustOptionsForLeftHandSide(options, this._originalIsEditable));
A
Alex Dima 已提交
472

A
Alex Dima 已提交
473
		this._register(editor.onDidScrollChange((e) => {
A
Alex Dima 已提交
474 475 476
			if (this._isHandlingScrollEvent) {
				return;
			}
477
			if (!e.scrollTopChanged && !e.scrollLeftChanged && !e.scrollHeightChanged) {
A
Alex Dima 已提交
478 479 480 481 482 483 484 485
				return;
			}
			this._isHandlingScrollEvent = true;
			this.modifiedEditor.setScrollPosition({
				scrollLeft: e.scrollLeft,
				scrollTop: e.scrollTop
			});
			this._isHandlingScrollEvent = false;
486 487

			this._layoutOverviewViewport();
A
Alex Dima 已提交
488 489
		}));

A
Alex Dima 已提交
490
		this._register(editor.onDidChangeViewZones(() => {
A
Alex Dima 已提交
491 492 493
			this._onViewZonesChanged();
		}));

A
Alex Dima 已提交
494
		this._register(editor.onDidChangeModelContent(() => {
A
Alex Dima 已提交
495 496 497 498
			if (this._isVisible) {
				this._beginUpdateDecorationsSoon();
			}
		}));
A
Alex Dima 已提交
499 500

		return editor;
E
Erich Gamma 已提交
501 502
	}

503
	private _createRightHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget {
A
Alex Dima 已提交
504
		const editor = this._createInnerEditor(instantiationService, this._modifiedDomNode, this._adjustOptionsForRightHandSide(options));
A
Alex Dima 已提交
505

A
Alex Dima 已提交
506
		this._register(editor.onDidScrollChange((e) => {
A
Alex Dima 已提交
507 508 509
			if (this._isHandlingScrollEvent) {
				return;
			}
510
			if (!e.scrollTopChanged && !e.scrollLeftChanged && !e.scrollHeightChanged) {
A
Alex Dima 已提交
511 512 513 514 515 516 517 518 519 520 521 522
				return;
			}
			this._isHandlingScrollEvent = true;
			this.originalEditor.setScrollPosition({
				scrollLeft: e.scrollLeft,
				scrollTop: e.scrollTop
			});
			this._isHandlingScrollEvent = false;

			this._layoutOverviewViewport();
		}));

A
Alex Dima 已提交
523
		this._register(editor.onDidChangeViewZones(() => {
A
Alex Dima 已提交
524 525 526
			this._onViewZonesChanged();
		}));

A
Alex Dima 已提交
527
		this._register(editor.onDidChangeConfiguration((e) => {
528
			if (e.hasChanged(EditorOption.fontInfo) && editor.getModel()) {
A
Alex Dima 已提交
529 530 531 532
				this._onViewZonesChanged();
			}
		}));

A
Alex Dima 已提交
533
		this._register(editor.onDidChangeModelContent(() => {
A
Alex Dima 已提交
534 535 536 537
			if (this._isVisible) {
				this._beginUpdateDecorationsSoon();
			}
		}));
A
Alex Dima 已提交
538

539 540 541 542 543 544
		this._register(editor.onDidChangeModelOptions((e) => {
			if (e.tabSize) {
				this._updateDecorationsRunner.schedule();
			}
		}));

A
Alex Dima 已提交
545
		return editor;
E
Erich Gamma 已提交
546 547
	}

548
	protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditorWidget {
549
		return instantiationService.createInstance(CodeEditorWidget, container, options, {});
A
Alex Dima 已提交
550 551
	}

E
Erich Gamma 已提交
552
	public dispose(): void {
553 554
		this._codeEditorService.removeDiffEditor(this);

555 556 557 558 559
		if (this._beginUpdateDecorationsTimeout !== -1) {
			window.clearTimeout(this._beginUpdateDecorationsTimeout);
			this._beginUpdateDecorationsTimeout = -1;
		}

A
Alex Dima 已提交
560 561 562
		if (this._measureDomElementToken) {
			this._measureDomElementToken.dispose();
		}
E
Erich Gamma 已提交
563 564 565

		this._cleanViewZonesAndDecorations();

566 567 568 569 570 571 572 573
		if (this._originalOverviewRuler) {
			this._overviewDomElement.removeChild(this._originalOverviewRuler.getDomNode());
			this._originalOverviewRuler.dispose();
		}
		if (this._modifiedOverviewRuler) {
			this._overviewDomElement.removeChild(this._modifiedOverviewRuler.getDomNode());
			this._modifiedOverviewRuler.dispose();
		}
574 575
		this._overviewDomElement.removeChild(this._overviewViewportDomElement.domNode);
		this._containerDomElement.removeChild(this._overviewDomElement);
E
Erich Gamma 已提交
576

577
		this._containerDomElement.removeChild(this._originalDomNode);
A
Alex Dima 已提交
578
		this.originalEditor.dispose();
579 580

		this._containerDomElement.removeChild(this._modifiedDomNode);
A
Alex Dima 已提交
581
		this.modifiedEditor.dispose();
E
Erich Gamma 已提交
582 583 584

		this._strategy.dispose();

585 586 587
		this._containerDomElement.removeChild(this._reviewPane.domNode.domNode);
		this._containerDomElement.removeChild(this._reviewPane.shadow.domNode);
		this._containerDomElement.removeChild(this._reviewPane.actionBarContainer.domNode);
588 589
		this._reviewPane.dispose();

590 591
		this._domElement.removeChild(this._containerDomElement);

A
Alex Dima 已提交
592
		this._onDidDispose.fire();
A
Alex Dima 已提交
593

E
Erich Gamma 已提交
594 595 596 597 598 599 600 601 602 603
		super.dispose();
	}

	//------------ begin IDiffEditor methods

	public getId(): string {
		return this.getEditorType() + ':' + this.id;
	}

	public getEditorType(): string {
A
Alex Dima 已提交
604
		return editorCommon.EditorType.IDiffEditor;
E
Erich Gamma 已提交
605 606
	}

A
Alex Dima 已提交
607
	public getLineChanges(): editorCommon.ILineChange[] | null {
A
Alex Dima 已提交
608 609 610 611
		if (!this._diffComputationResult) {
			return null;
		}
		return this._diffComputationResult.changes;
E
Erich Gamma 已提交
612 613
	}

614 615 616 617
	public getDiffComputationResult(): IDiffComputationResult | null {
		return this._diffComputationResult;
	}

A
Alex Dima 已提交
618
	public getOriginalEditor(): editorBrowser.ICodeEditor {
E
Erich Gamma 已提交
619 620 621
		return this.originalEditor;
	}

A
Alex Dima 已提交
622
	public getModifiedEditor(): editorBrowser.ICodeEditor {
E
Erich Gamma 已提交
623 624 625
		return this.modifiedEditor;
	}

626
	public updateOptions(newOptions: IDiffEditorOptions): void {
E
Erich Gamma 已提交
627 628

		// Handle side by side
A
Alex Dima 已提交
629
		let renderSideBySideChanged = false;
E
Erich Gamma 已提交
630 631 632 633 634 635 636
		if (typeof newOptions.renderSideBySide !== 'undefined') {
			if (this._renderSideBySide !== newOptions.renderSideBySide) {
				this._renderSideBySide = newOptions.renderSideBySide;
				renderSideBySideChanged = true;
			}
		}

637 638
		if (typeof newOptions.maxComputationTime !== 'undefined') {
			this._maxComputationTime = newOptions.maxComputationTime;
639 640 641
			if (this._isVisible) {
				this._beginUpdateDecorationsSoon();
			}
642 643
		}

644 645
		let beginUpdateDecorations = false;

E
Erich Gamma 已提交
646 647 648 649
		if (typeof newOptions.ignoreTrimWhitespace !== 'undefined') {
			if (this._ignoreTrimWhitespace !== newOptions.ignoreTrimWhitespace) {
				this._ignoreTrimWhitespace = newOptions.ignoreTrimWhitespace;
				// Begin comparing
650 651 652 653 654 655 656 657
				beginUpdateDecorations = true;
			}
		}

		if (typeof newOptions.renderIndicators !== 'undefined') {
			if (this._renderIndicators !== newOptions.renderIndicators) {
				this._renderIndicators = newOptions.renderIndicators;
				beginUpdateDecorations = true;
E
Erich Gamma 已提交
658 659 660
			}
		}

661 662 663 664
		if (beginUpdateDecorations) {
			this._beginUpdateDecorations();
		}

665 666 667 668
		if (typeof newOptions.originalEditable !== 'undefined') {
			this._originalIsEditable = Boolean(newOptions.originalEditable);
		}

E
Erich Gamma 已提交
669
		this.modifiedEditor.updateOptions(this._adjustOptionsForRightHandSide(newOptions));
670
		this.originalEditor.updateOptions(this._adjustOptionsForLeftHandSide(newOptions, this._originalIsEditable));
E
Erich Gamma 已提交
671 672 673 674 675 676 677 678 679 680

		// enableSplitViewResizing
		if (typeof newOptions.enableSplitViewResizing !== 'undefined') {
			this._enableSplitViewResizing = newOptions.enableSplitViewResizing;
		}
		this._strategy.setEnableSplitViewResizing(this._enableSplitViewResizing);

		// renderSideBySide
		if (renderSideBySideChanged) {
			if (this._renderSideBySide) {
H
Howard Hung 已提交
681
				this._setStrategy(new DiffEditorWidgetSideBySide(this._createDataSource(), this._enableSplitViewResizing));
E
Erich Gamma 已提交
682
			} else {
H
Howard Hung 已提交
683
				this._setStrategy(new DiffEditorWidgetInline(this._createDataSource(), this._enableSplitViewResizing));
E
Erich Gamma 已提交
684
			}
685 686
			// Update class name
			this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getTheme(), this._renderSideBySide);
E
Erich Gamma 已提交
687 688 689
		}
	}

A
Alex Dima 已提交
690
	public getModel(): editorCommon.IDiffEditorModel {
E
Erich Gamma 已提交
691
		return {
A
Alex Dima 已提交
692 693
			original: this.originalEditor.getModel()!,
			modified: this.modifiedEditor.getModel()!
E
Erich Gamma 已提交
694 695 696
		};
	}

J
Johannes Rieken 已提交
697
	public setModel(model: editorCommon.IDiffEditorModel): void {
E
Erich Gamma 已提交
698 699 700 701 702 703 704 705 706 707 708 709 710
		// 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();

		// Update code editor models
		this.originalEditor.setModel(model ? model.original : null);
		this.modifiedEditor.setModel(model ? model.modified : null);
		this._updateDecorationsRunner.cancel();

711 712
		// this.originalEditor.onDidChangeModelOptions

E
Erich Gamma 已提交
713 714 715 716 717 718
		if (model) {
			this.originalEditor.setScrollTop(0);
			this.modifiedEditor.setScrollTop(0);
		}

		// Disable any diff computations that will come in
A
Alex Dima 已提交
719
		this._diffComputationResult = null;
E
Erich Gamma 已提交
720
		this._diffComputationToken++;
721
		this._setState(editorBrowser.DiffEditorState.Idle);
E
Erich Gamma 已提交
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736

		if (model) {
			this._recreateOverviewRulers();

			// Begin comparing
			this._beginUpdateDecorations();
		}

		this._layoutOverviewViewport();
	}

	public getDomNode(): HTMLElement {
		return this._domElement;
	}

A
Alex Dima 已提交
737
	public getVisibleColumnFromPosition(position: IPosition): number {
E
Erich Gamma 已提交
738 739 740
		return this.modifiedEditor.getVisibleColumnFromPosition(position);
	}

741 742 743 744
	public getStatusbarColumn(position: IPosition): number {
		return this.modifiedEditor.getStatusbarColumn(position);
	}

A
Alex Dima 已提交
745
	public getPosition(): Position | null {
E
Erich Gamma 已提交
746 747 748
		return this.modifiedEditor.getPosition();
	}

749 750
	public setPosition(position: IPosition): void {
		this.modifiedEditor.setPosition(position);
E
Erich Gamma 已提交
751 752
	}

753 754
	public revealLine(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLine(lineNumber, scrollType);
E
Erich Gamma 已提交
755 756
	}

757 758
	public revealLineInCenter(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLineInCenter(lineNumber, scrollType);
E
Erich Gamma 已提交
759 760
	}

761 762
	public revealLineInCenterIfOutsideViewport(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLineInCenterIfOutsideViewport(lineNumber, scrollType);
E
Erich Gamma 已提交
763 764
	}

765 766
	public revealPosition(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealPosition(position, scrollType);
E
Erich Gamma 已提交
767 768
	}

769 770
	public revealPositionInCenter(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealPositionInCenter(position, scrollType);
E
Erich Gamma 已提交
771 772
	}

773 774
	public revealPositionInCenterIfOutsideViewport(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealPositionInCenterIfOutsideViewport(position, scrollType);
E
Erich Gamma 已提交
775 776
	}

A
Alex Dima 已提交
777
	public getSelection(): Selection | null {
E
Erich Gamma 已提交
778 779 780
		return this.modifiedEditor.getSelection();
	}

A
Alex Dima 已提交
781
	public getSelections(): Selection[] | null {
E
Erich Gamma 已提交
782 783 784
		return this.modifiedEditor.getSelections();
	}

785 786 787 788 789 790
	public setSelection(range: IRange): void;
	public setSelection(editorRange: Range): void;
	public setSelection(selection: ISelection): void;
	public setSelection(editorSelection: Selection): void;
	public setSelection(something: any): void {
		this.modifiedEditor.setSelection(something);
E
Erich Gamma 已提交
791 792
	}

793
	public setSelections(ranges: readonly ISelection[]): void {
E
Erich Gamma 已提交
794 795 796
		this.modifiedEditor.setSelections(ranges);
	}

797 798
	public revealLines(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLines(startLineNumber, endLineNumber, scrollType);
E
Erich Gamma 已提交
799 800
	}

801 802
	public revealLinesInCenter(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLinesInCenter(startLineNumber, endLineNumber, scrollType);
E
Erich Gamma 已提交
803 804
	}

805 806
	public revealLinesInCenterIfOutsideViewport(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLinesInCenterIfOutsideViewport(startLineNumber, endLineNumber, scrollType);
E
Erich Gamma 已提交
807 808
	}

809 810
	public revealRange(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth, revealVerticalInCenter: boolean = false, revealHorizontal: boolean = true): void {
		this.modifiedEditor.revealRange(range, scrollType, revealVerticalInCenter, revealHorizontal);
E
Erich Gamma 已提交
811 812
	}

813 814
	public revealRangeInCenter(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealRangeInCenter(range, scrollType);
E
Erich Gamma 已提交
815 816
	}

817 818
	public revealRangeInCenterIfOutsideViewport(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealRangeInCenterIfOutsideViewport(range, scrollType);
E
Erich Gamma 已提交
819 820
	}

821 822
	public revealRangeAtTop(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealRangeAtTop(range, scrollType);
823 824
	}

A
Alex Dima 已提交
825
	public getSupportedActions(): editorCommon.IEditorAction[] {
826 827 828
		return this.modifiedEditor.getSupportedActions();
	}

A
Alex Dima 已提交
829
	public saveViewState(): editorCommon.IDiffEditorViewState {
A
Alex Dima 已提交
830 831
		let originalViewState = this.originalEditor.saveViewState();
		let modifiedViewState = this.modifiedEditor.saveViewState();
E
Erich Gamma 已提交
832 833 834 835 836 837
		return {
			original: originalViewState,
			modified: modifiedViewState
		};
	}

A
Alex Dima 已提交
838
	public restoreViewState(s: editorCommon.IDiffEditorViewState): void {
A
Alex Dima 已提交
839
		if (s.original && s.modified) {
A
Alex Dima 已提交
840
			let diffEditorState = <editorCommon.IDiffEditorViewState>s;
E
Erich Gamma 已提交
841 842 843 844 845
			this.originalEditor.restoreViewState(diffEditorState.original);
			this.modifiedEditor.restoreViewState(diffEditorState.modified);
		}
	}

J
Johannes Rieken 已提交
846
	public layout(dimension?: editorCommon.IDimension): void {
E
Erich Gamma 已提交
847 848 849 850 851 852 853
		this._measureDomElement(false, dimension);
	}

	public focus(): void {
		this.modifiedEditor.focus();
	}

A
Alex Dima 已提交
854 855
	public hasTextFocus(): boolean {
		return this.originalEditor.hasTextFocus() || this.modifiedEditor.hasTextFocus();
E
Erich Gamma 已提交
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
	}

	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();
	}

J
Johannes Rieken 已提交
874
	public trigger(source: string, handlerId: string, payload: any): void {
E
Erich Gamma 已提交
875 876 877
		this.modifiedEditor.trigger(source, handlerId, payload);
	}

878
	public changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any {
E
Erich Gamma 已提交
879 880 881 882 883 884 885 886 887
		return this.modifiedEditor.changeDecorations(callback);
	}

	//------------ end IDiffEditor methods



	//------------ begin layouting methods

J
Johannes Rieken 已提交
888
	private _measureDomElement(forceDoLayoutCall: boolean, dimensions?: editorCommon.IDimension): void {
889 890 891 892
		dimensions = dimensions || {
			width: this._containerDomElement.clientWidth,
			height: this._containerDomElement.clientHeight
		};
E
Erich Gamma 已提交
893 894

		if (dimensions.width <= 0) {
895 896
			this._width = 0;
			this._height = 0;
A
Alex Dima 已提交
897
			this._reviewHeight = 0;
E
Erich Gamma 已提交
898 899 900 901 902 903 904 905 906 907
			return;
		}

		if (!forceDoLayoutCall && dimensions.width === this._width && dimensions.height === this._height) {
			// Nothing has changed
			return;
		}

		this._width = dimensions.width;
		this._height = dimensions.height;
908
		this._reviewHeight = this._reviewPane.isVisible() ? this._height : 0;
E
Erich Gamma 已提交
909 910 911 912 913

		this._doLayout();
	}

	private _layoutOverviewRulers(): void {
A
Alex Dima 已提交
914 915 916
		if (!this._originalOverviewRuler || !this._modifiedOverviewRuler) {
			return;
		}
A
Alex Dima 已提交
917 918
		let freeSpace = DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH - 2 * DiffEditorWidget.ONE_OVERVIEW_WIDTH;
		let layoutInfo = this.modifiedEditor.getLayoutInfo();
E
Erich Gamma 已提交
919
		if (layoutInfo) {
A
Alex Dima 已提交
920
			this._originalOverviewRuler.setLayout({
E
Erich Gamma 已提交
921 922 923
				top: 0,
				width: DiffEditorWidget.ONE_OVERVIEW_WIDTH,
				right: freeSpace + DiffEditorWidget.ONE_OVERVIEW_WIDTH,
A
Alex Dima 已提交
924
				height: (this._height - this._reviewHeight)
A
Alex Dima 已提交
925 926
			});
			this._modifiedOverviewRuler.setLayout({
E
Erich Gamma 已提交
927 928 929
				top: 0,
				right: 0,
				width: DiffEditorWidget.ONE_OVERVIEW_WIDTH,
A
Alex Dima 已提交
930
				height: (this._height - this._reviewHeight)
A
Alex Dima 已提交
931
			});
E
Erich Gamma 已提交
932 933 934 935 936 937 938 939 940 941 942 943
		}
	}

	//------------ end layouting methods

	private _onViewZonesChanged(): void {
		if (this._currentlyChangingViewZones) {
			return;
		}
		this._updateDecorationsRunner.schedule();
	}

A
Alex Dima 已提交
944 945 946 947 948 949 950 951 952
	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);
	}

953 954
	private _lastOriginalWarning: URI | null = null;
	private _lastModifiedWarning: URI | null = null;
955

A
Alex Dima 已提交
956
	private static _equals(a: URI | null, b: URI | null): boolean {
957 958 959 960 961 962 963 964 965
		if (!a && !b) {
			return true;
		}
		if (!a || !b) {
			return false;
		}
		return (a.toString() === b.toString());
	}

E
Erich Gamma 已提交
966 967
	private _beginUpdateDecorations(): void {
		this._beginUpdateDecorationsTimeout = -1;
968 969 970
		const currentOriginalModel = this.originalEditor.getModel();
		const currentModifiedModel = this.modifiedEditor.getModel();
		if (!currentOriginalModel || !currentModifiedModel) {
E
Erich Gamma 已提交
971 972 973 974 975 976 977
			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++;
A
Alex Dima 已提交
978
		let currentToken = this._diffComputationToken;
979
		this._setState(editorBrowser.DiffEditorState.ComputingDiff);
E
Erich Gamma 已提交
980

981 982 983 984 985 986 987
		if (!this._editorWorkerService.canComputeDiff(currentOriginalModel.uri, currentModifiedModel.uri)) {
			if (
				!DiffEditorWidget._equals(currentOriginalModel.uri, this._lastOriginalWarning)
				|| !DiffEditorWidget._equals(currentModifiedModel.uri, this._lastModifiedWarning)
			) {
				this._lastOriginalWarning = currentOriginalModel.uri;
				this._lastModifiedWarning = currentModifiedModel.uri;
988
				this._notificationService.warn(nls.localize("diff.tooLarge", "Cannot compare files because one file is too large."));
989 990 991 992
			}
			return;
		}

993
		this._editorWorkerService.computeDiff(currentOriginalModel.uri, currentModifiedModel.uri, this._ignoreTrimWhitespace, this._maxComputationTime).then((result) => {
994 995 996
			if (currentToken === this._diffComputationToken
				&& currentOriginalModel === this.originalEditor.getModel()
				&& currentModifiedModel === this.modifiedEditor.getModel()
J
Johannes Rieken 已提交
997
			) {
998
				this._setState(editorBrowser.DiffEditorState.DiffComputed);
A
Alex Dima 已提交
999
				this._diffComputationResult = result;
1000
				this._updateDecorationsRunner.schedule();
A
Alex Dima 已提交
1001
				this._onDidUpdateDiff.fire();
1002 1003 1004 1005 1006
			}
		}, (error) => {
			if (currentToken === this._diffComputationToken
				&& currentOriginalModel === this.originalEditor.getModel()
				&& currentModifiedModel === this.modifiedEditor.getModel()
J
Johannes Rieken 已提交
1007
			) {
1008
				this._setState(editorBrowser.DiffEditorState.DiffComputed);
A
Alex Dima 已提交
1009
				this._diffComputationResult = null;
E
Erich Gamma 已提交
1010 1011
				this._updateDecorationsRunner.schedule();
			}
1012
		});
E
Erich Gamma 已提交
1013 1014 1015 1016 1017 1018 1019 1020
	}

	private _cleanViewZonesAndDecorations(): void {
		this._originalEditorState.clean(this.originalEditor);
		this._modifiedEditorState.clean(this.modifiedEditor);
	}

	private _updateDecorations(): void {
A
Alex Dima 已提交
1021
		if (!this.originalEditor.getModel() || !this.modifiedEditor.getModel() || !this._originalOverviewRuler || !this._modifiedOverviewRuler) {
1022 1023
			return;
		}
A
Alex Dima 已提交
1024
		const lineChanges = (this._diffComputationResult ? this._diffComputationResult.changes : []);
E
Erich Gamma 已提交
1025

A
Alex Dima 已提交
1026 1027
		let foreignOriginal = this._originalEditorState.getForeignViewZones(this.originalEditor.getWhitespaces());
		let foreignModified = this._modifiedEditorState.getForeignViewZones(this.modifiedEditor.getWhitespaces());
E
Erich Gamma 已提交
1028

1029
		let diffDecorations = this._strategy.getEditorsDiffDecorations(lineChanges, this._ignoreTrimWhitespace, this._renderIndicators, foreignOriginal, foreignModified, this.originalEditor, this.modifiedEditor);
E
Erich Gamma 已提交
1030 1031 1032

		try {
			this._currentlyChangingViewZones = true;
A
Alex Dima 已提交
1033 1034
			this._originalEditorState.apply(this.originalEditor, this._originalOverviewRuler, diffDecorations.original, false);
			this._modifiedEditorState.apply(this.modifiedEditor, this._modifiedOverviewRuler, diffDecorations.modified, true);
E
Erich Gamma 已提交
1035 1036 1037 1038 1039
		} finally {
			this._currentlyChangingViewZones = false;
		}
	}

1040 1041
	private _adjustOptionsForSubEditor(options: IDiffEditorOptions): IDiffEditorOptions {
		let clonedOptions: IDiffEditorOptions = objects.deepClone(options || {});
A
Alex Dima 已提交
1042
		clonedOptions.inDiffEditor = true;
1043
		clonedOptions.wordWrap = 'off';
1044
		clonedOptions.wordWrapMinified = false;
E
Erich Gamma 已提交
1045 1046 1047
		clonedOptions.automaticLayout = false;
		clonedOptions.scrollbar = clonedOptions.scrollbar || {};
		clonedOptions.scrollbar.vertical = 'visible';
A
Alex Dima 已提交
1048
		clonedOptions.folding = false;
1049
		clonedOptions.codeLens = false;
J
Joao Moreno 已提交
1050
		clonedOptions.fixedOverflowWidgets = true;
1051
		// clonedOptions.lineDecorationsWidth = '2ch';
1052 1053 1054
		if (!clonedOptions.minimap) {
			clonedOptions.minimap = {};
		}
1055
		clonedOptions.minimap.enabled = false;
E
Erich Gamma 已提交
1056 1057 1058
		return clonedOptions;
	}

1059
	private _adjustOptionsForLeftHandSide(options: IDiffEditorOptions, isEditable: boolean): IEditorOptions {
1060 1061
		let result = this._adjustOptionsForSubEditor(options);
		result.readOnly = !isEditable;
1062
		result.extraEditorClassName = 'original-in-monaco-diff-editor';
1063 1064 1065
		return result;
	}

1066
	private _adjustOptionsForRightHandSide(options: IDiffEditorOptions): IEditorOptions {
1067
		let result = this._adjustOptionsForSubEditor(options);
A
Alex Dima 已提交
1068
		result.revealHorizontalRightPadding = EditorOptions.revealHorizontalRightPadding.defaultValue + DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH;
A
Alex Dima 已提交
1069
		result.scrollbar!.verticalHasArrows = false;
1070
		result.extraEditorClassName = 'modified-in-monaco-diff-editor';
1071
		return result;
E
Erich Gamma 已提交
1072 1073
	}

1074 1075 1076 1077
	public doLayout(): void {
		this._measureDomElement(true);
	}

E
Erich Gamma 已提交
1078
	private _doLayout(): void {
A
Alex Dima 已提交
1079
		let splitPoint = this._strategy.layout();
E
Erich Gamma 已提交
1080 1081 1082 1083 1084 1085 1086 1087

		this._originalDomNode.style.width = splitPoint + 'px';
		this._originalDomNode.style.left = '0px';

		this._modifiedDomNode.style.width = (this._width - splitPoint) + 'px';
		this._modifiedDomNode.style.left = splitPoint + 'px';

		this._overviewDomElement.style.top = '0px';
A
Alex Dima 已提交
1088
		this._overviewDomElement.style.height = (this._height - this._reviewHeight) + 'px';
E
Erich Gamma 已提交
1089 1090
		this._overviewDomElement.style.width = DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH + 'px';
		this._overviewDomElement.style.left = (this._width - DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH) + 'px';
A
Alex Dima 已提交
1091 1092
		this._overviewViewportDomElement.setWidth(DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH);
		this._overviewViewportDomElement.setHeight(30);
E
Erich Gamma 已提交
1093

A
Alex Dima 已提交
1094 1095
		this.originalEditor.layout({ width: splitPoint, height: (this._height - this._reviewHeight) });
		this.modifiedEditor.layout({ width: this._width - splitPoint - DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH, height: (this._height - this._reviewHeight) });
E
Erich Gamma 已提交
1096 1097 1098 1099 1100

		if (this._originalOverviewRuler || this._modifiedOverviewRuler) {
			this._layoutOverviewRulers();
		}

A
Alex Dima 已提交
1101 1102
		this._reviewPane.layout(this._height - this._reviewHeight, this._width, this._reviewHeight);

E
Erich Gamma 已提交
1103 1104 1105 1106
		this._layoutOverviewViewport();
	}

	private _layoutOverviewViewport(): void {
A
Alex Dima 已提交
1107
		let layout = this._computeOverviewViewport();
E
Erich Gamma 已提交
1108
		if (!layout) {
A
Alex Dima 已提交
1109 1110
			this._overviewViewportDomElement.setTop(0);
			this._overviewViewportDomElement.setHeight(0);
E
Erich Gamma 已提交
1111
		} else {
A
Alex Dima 已提交
1112 1113
			this._overviewViewportDomElement.setTop(layout.top);
			this._overviewViewportDomElement.setHeight(layout.height);
E
Erich Gamma 已提交
1114 1115 1116
		}
	}

A
Alex Dima 已提交
1117
	private _computeOverviewViewport(): { height: number; top: number; } | null {
A
Alex Dima 已提交
1118
		let layoutInfo = this.modifiedEditor.getLayoutInfo();
E
Erich Gamma 已提交
1119 1120 1121 1122
		if (!layoutInfo) {
			return null;
		}

A
Alex Dima 已提交
1123 1124
		let scrollTop = this.modifiedEditor.getScrollTop();
		let scrollHeight = this.modifiedEditor.getScrollHeight();
E
Erich Gamma 已提交
1125

A
Alex Dima 已提交
1126 1127 1128
		let computedAvailableSize = Math.max(0, layoutInfo.contentHeight);
		let computedRepresentableSize = Math.max(0, computedAvailableSize - 2 * 0);
		let computedRatio = scrollHeight > 0 ? (computedRepresentableSize / scrollHeight) : 0;
E
Erich Gamma 已提交
1129

1130
		let computedSliderSize = Math.max(0, Math.floor(layoutInfo.contentHeight * computedRatio));
A
Alex Dima 已提交
1131
		let computedSliderPosition = Math.floor(scrollTop * computedRatio);
E
Erich Gamma 已提交
1132 1133 1134 1135 1136 1137 1138

		return {
			height: computedSliderSize,
			top: computedSliderPosition
		};
	}

J
Johannes Rieken 已提交
1139
	private _createDataSource(): IDataSource {
E
Erich Gamma 已提交
1140 1141 1142 1143 1144 1145
		return {
			getWidth: () => {
				return this._width;
			},

			getHeight: () => {
A
Alex Dima 已提交
1146
				return (this._height - this._reviewHeight);
E
Erich Gamma 已提交
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
			},

			getContainerDomNode: () => {
				return this._containerDomElement;
			},

			relayoutEditors: () => {
				this._doLayout();
			},

			getOriginalEditor: () => {
				return this.originalEditor;
			},

			getModifiedEditor: () => {
				return this.modifiedEditor;
			}
		};
	}

J
Johannes Rieken 已提交
1167
	private _setStrategy(newStrategy: IDiffEditorWidgetStyle): void {
E
Erich Gamma 已提交
1168 1169 1170 1171 1172
		if (this._strategy) {
			this._strategy.dispose();
		}

		this._strategy = newStrategy;
1173
		newStrategy.applyColors(this._themeService.getTheme());
E
Erich Gamma 已提交
1174

A
Alex Dima 已提交
1175
		if (this._diffComputationResult) {
E
Erich Gamma 已提交
1176 1177 1178 1179 1180 1181 1182
			this._updateDecorations();
		}

		// Just do a layout, the strategy might need it
		this._measureDomElement(true);
	}

A
Alex Dima 已提交
1183
	private _getLineChangeAtOrBeforeLineNumber(lineNumber: number, startLineNumberExtractor: (lineChange: editorCommon.ILineChange) => number): editorCommon.ILineChange | null {
A
Alex Dima 已提交
1184 1185
		const lineChanges = (this._diffComputationResult ? this._diffComputationResult.changes : []);
		if (lineChanges.length === 0 || lineNumber < startLineNumberExtractor(lineChanges[0])) {
E
Erich Gamma 已提交
1186 1187 1188 1189
			// There are no changes or `lineNumber` is before the first change
			return null;
		}

A
Alex Dima 已提交
1190
		let min = 0, max = lineChanges.length - 1;
E
Erich Gamma 已提交
1191
		while (min < max) {
A
Alex Dima 已提交
1192
			let mid = Math.floor((min + max) / 2);
A
Alex Dima 已提交
1193
			let midStart = startLineNumberExtractor(lineChanges[mid]);
1194
			let midEnd = (mid + 1 <= max ? startLineNumberExtractor(lineChanges[mid + 1]) : Constants.MAX_SAFE_SMALL_INTEGER);
E
Erich Gamma 已提交
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205

			if (lineNumber < midStart) {
				max = mid - 1;
			} else if (lineNumber >= midEnd) {
				min = mid + 1;
			} else {
				// HIT!
				min = mid;
				max = mid;
			}
		}
A
Alex Dima 已提交
1206
		return lineChanges[min];
E
Erich Gamma 已提交
1207 1208 1209
	}

	private _getEquivalentLineForOriginalLineNumber(lineNumber: number): number {
A
Alex Dima 已提交
1210
		let lineChange = this._getLineChangeAtOrBeforeLineNumber(lineNumber, (lineChange) => lineChange.originalStartLineNumber);
E
Erich Gamma 已提交
1211 1212 1213 1214 1215

		if (!lineChange) {
			return lineNumber;
		}

A
Alex Dima 已提交
1216 1217 1218 1219
		let originalEquivalentLineNumber = lineChange.originalStartLineNumber + (lineChange.originalEndLineNumber > 0 ? -1 : 0);
		let modifiedEquivalentLineNumber = lineChange.modifiedStartLineNumber + (lineChange.modifiedEndLineNumber > 0 ? -1 : 0);
		let lineChangeOriginalLength = (lineChange.originalEndLineNumber > 0 ? (lineChange.originalEndLineNumber - lineChange.originalStartLineNumber + 1) : 0);
		let lineChangeModifiedLength = (lineChange.modifiedEndLineNumber > 0 ? (lineChange.modifiedEndLineNumber - lineChange.modifiedStartLineNumber + 1) : 0);
E
Erich Gamma 已提交
1220 1221


A
Alex Dima 已提交
1222
		let delta = lineNumber - originalEquivalentLineNumber;
E
Erich Gamma 已提交
1223 1224 1225 1226 1227

		if (delta <= lineChangeOriginalLength) {
			return modifiedEquivalentLineNumber + Math.min(delta, lineChangeModifiedLength);
		}

J
Johannes Rieken 已提交
1228
		return modifiedEquivalentLineNumber + lineChangeModifiedLength - lineChangeOriginalLength + delta;
E
Erich Gamma 已提交
1229 1230 1231
	}

	private _getEquivalentLineForModifiedLineNumber(lineNumber: number): number {
A
Alex Dima 已提交
1232
		let lineChange = this._getLineChangeAtOrBeforeLineNumber(lineNumber, (lineChange) => lineChange.modifiedStartLineNumber);
E
Erich Gamma 已提交
1233 1234 1235 1236 1237

		if (!lineChange) {
			return lineNumber;
		}

A
Alex Dima 已提交
1238 1239 1240 1241
		let originalEquivalentLineNumber = lineChange.originalStartLineNumber + (lineChange.originalEndLineNumber > 0 ? -1 : 0);
		let modifiedEquivalentLineNumber = lineChange.modifiedStartLineNumber + (lineChange.modifiedEndLineNumber > 0 ? -1 : 0);
		let lineChangeOriginalLength = (lineChange.originalEndLineNumber > 0 ? (lineChange.originalEndLineNumber - lineChange.originalStartLineNumber + 1) : 0);
		let lineChangeModifiedLength = (lineChange.modifiedEndLineNumber > 0 ? (lineChange.modifiedEndLineNumber - lineChange.modifiedStartLineNumber + 1) : 0);
E
Erich Gamma 已提交
1242 1243


A
Alex Dima 已提交
1244
		let delta = lineNumber - modifiedEquivalentLineNumber;
E
Erich Gamma 已提交
1245 1246 1247 1248 1249

		if (delta <= lineChangeModifiedLength) {
			return originalEquivalentLineNumber + Math.min(delta, lineChangeOriginalLength);
		}

J
Johannes Rieken 已提交
1250
		return originalEquivalentLineNumber + lineChangeOriginalLength - lineChangeModifiedLength + delta;
E
Erich Gamma 已提交
1251 1252
	}

A
Alex Dima 已提交
1253
	public getDiffLineInformationForOriginal(lineNumber: number): editorBrowser.IDiffLineInformation | null {
A
Alex Dima 已提交
1254
		if (!this._diffComputationResult) {
E
Erich Gamma 已提交
1255 1256 1257 1258 1259 1260 1261 1262
			// Cannot answer that which I don't know
			return null;
		}
		return {
			equivalentLineNumber: this._getEquivalentLineForOriginalLineNumber(lineNumber)
		};
	}

A
Alex Dima 已提交
1263
	public getDiffLineInformationForModified(lineNumber: number): editorBrowser.IDiffLineInformation | null {
A
Alex Dima 已提交
1264
		if (!this._diffComputationResult) {
E
Erich Gamma 已提交
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
			// Cannot answer that which I don't know
			return null;
		}
		return {
			equivalentLineNumber: this._getEquivalentLineForModifiedLineNumber(lineNumber)
		};
	}
}

interface IDataSource {
	getWidth(): number;
	getHeight(): number;
	getContainerDomNode(): HTMLElement;
	relayoutEditors(): void;

A
Alex Dima 已提交
1280 1281
	getOriginalEditor(): editorBrowser.ICodeEditor;
	getModifiedEditor(): editorBrowser.ICodeEditor;
E
Erich Gamma 已提交
1282 1283
}

A
Alex Dima 已提交
1284
abstract class DiffEditorWidgetStyle extends Disposable implements IDiffEditorWidgetStyle {
E
Erich Gamma 已提交
1285

J
Johannes Rieken 已提交
1286
	_dataSource: IDataSource;
A
Alex Dima 已提交
1287 1288
	_insertColor: Color | null;
	_removeColor: Color | null;
E
Erich Gamma 已提交
1289

J
Johannes Rieken 已提交
1290
	constructor(dataSource: IDataSource) {
A
Alex Dima 已提交
1291
		super();
E
Erich Gamma 已提交
1292
		this._dataSource = dataSource;
A
Alex Dima 已提交
1293 1294
		this._insertColor = null;
		this._removeColor = null;
E
Erich Gamma 已提交
1295 1296
	}

1297 1298 1299 1300 1301 1302 1303 1304 1305
	public applyColors(theme: ITheme): boolean {
		let newInsertColor = (theme.getColor(diffInserted) || defaultInsertColor).transparent(2);
		let newRemoveColor = (theme.getColor(diffRemoved) || defaultRemoveColor).transparent(2);
		let hasChanges = !newInsertColor.equals(this._insertColor) || !newRemoveColor.equals(this._removeColor);
		this._insertColor = newInsertColor;
		this._removeColor = newRemoveColor;
		return hasChanges;
	}

A
Alexandru Dima 已提交
1306
	public getEditorsDiffDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalWhitespaces: EditorWhitespace[], modifiedWhitespaces: EditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorsDiffDecorationsWithZones {
E
Erich Gamma 已提交
1307 1308 1309 1310 1311 1312 1313
		// Get view zones
		modifiedWhitespaces = modifiedWhitespaces.sort((a, b) => {
			return a.afterLineNumber - b.afterLineNumber;
		});
		originalWhitespaces = originalWhitespaces.sort((a, b) => {
			return a.afterLineNumber - b.afterLineNumber;
		});
1314
		let zones = this._getViewZones(lineChanges, originalWhitespaces, modifiedWhitespaces, originalEditor, modifiedEditor, renderIndicators);
E
Erich Gamma 已提交
1315 1316

		// Get decorations & overview ruler zones
1317 1318
		let originalDecorations = this._getOriginalEditorDecorations(lineChanges, ignoreTrimWhitespace, renderIndicators, originalEditor, modifiedEditor);
		let modifiedDecorations = this._getModifiedEditorDecorations(lineChanges, ignoreTrimWhitespace, renderIndicators, originalEditor, modifiedEditor);
E
Erich Gamma 已提交
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333

		return {
			original: {
				decorations: originalDecorations.decorations,
				overviewZones: originalDecorations.overviewZones,
				zones: zones.original
			},
			modified: {
				decorations: modifiedDecorations.decorations,
				overviewZones: modifiedDecorations.overviewZones,
				zones: zones.modified
			}
		};
	}

A
Alexandru Dima 已提交
1334
	protected abstract _getViewZones(lineChanges: editorCommon.ILineChange[], originalForeignVZ: EditorWhitespace[], modifiedForeignVZ: EditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor, renderIndicators: boolean): IEditorsZones;
1335 1336
	protected abstract _getOriginalEditorDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorDiffDecorations;
	protected abstract _getModifiedEditorDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorDiffDecorations;
A
Alex Dima 已提交
1337 1338 1339

	public abstract setEnableSplitViewResizing(enableSplitViewResizing: boolean): void;
	public abstract layout(): number;
E
Erich Gamma 已提交
1340 1341
}

A
Alex Dima 已提交
1342
interface IMyViewZone {
E
Erich Gamma 已提交
1343
	shouldNotShrink?: boolean;
A
Alex Dima 已提交
1344 1345 1346 1347 1348
	afterLineNumber: number;
	heightInLines: number;
	minWidthInPx?: number;
	domNode: HTMLElement | null;
	marginDomNode?: HTMLElement | null;
1349
	diff?: IDiffLinesChange;
E
Erich Gamma 已提交
1350 1351 1352 1353 1354
}

class ForeignViewZonesIterator {

	private _index: number;
A
Alexandru Dima 已提交
1355 1356
	private readonly _source: EditorWhitespace[];
	public current: EditorWhitespace | null;
E
Erich Gamma 已提交
1357

A
Alexandru Dima 已提交
1358
	constructor(source: EditorWhitespace[]) {
E
Erich Gamma 已提交
1359 1360
		this._source = source;
		this._index = -1;
A
Alex Dima 已提交
1361
		this.current = null;
E
Erich Gamma 已提交
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374
		this.advance();
	}

	public advance(): void {
		this._index++;
		if (this._index < this._source.length) {
			this.current = this._source[this._index];
		} else {
			this.current = null;
		}
	}
}

1375
abstract class ViewZonesComputer {
E
Erich Gamma 已提交
1376

1377
	private readonly lineChanges: editorCommon.ILineChange[];
A
Alexandru Dima 已提交
1378 1379
	private readonly originalForeignVZ: EditorWhitespace[];
	private readonly modifiedForeignVZ: EditorWhitespace[];
E
Erich Gamma 已提交
1380

A
Alexandru Dima 已提交
1381
	constructor(lineChanges: editorCommon.ILineChange[], originalForeignVZ: EditorWhitespace[], modifiedForeignVZ: EditorWhitespace[]) {
E
Erich Gamma 已提交
1382 1383 1384 1385 1386 1387
		this.lineChanges = lineChanges;
		this.originalForeignVZ = originalForeignVZ;
		this.modifiedForeignVZ = modifiedForeignVZ;
	}

	public getViewZones(): IEditorsZones {
A
Alex Dima 已提交
1388
		let result: { original: IMyViewZone[]; modified: IMyViewZone[]; } = {
E
Erich Gamma 已提交
1389 1390 1391 1392
			original: [],
			modified: []
		};

A
Alex Dima 已提交
1393 1394 1395 1396 1397 1398 1399 1400
		let lineChangeModifiedLength: number = 0;
		let lineChangeOriginalLength: number = 0;
		let originalEquivalentLineNumber: number = 0;
		let modifiedEquivalentLineNumber: number = 0;
		let originalEndEquivalentLineNumber: number = 0;
		let modifiedEndEquivalentLineNumber: number = 0;

		let sortMyViewZones = (a: IMyViewZone, b: IMyViewZone) => {
E
Erich Gamma 已提交
1401 1402 1403
			return a.afterLineNumber - b.afterLineNumber;
		};

A
Alex Dima 已提交
1404
		let addAndCombineIfPossible = (destination: IMyViewZone[], item: IMyViewZone) => {
E
Erich Gamma 已提交
1405
			if (item.domNode === null && destination.length > 0) {
A
Alex Dima 已提交
1406
				let lastItem = destination[destination.length - 1];
E
Erich Gamma 已提交
1407 1408 1409 1410 1411 1412 1413 1414
				if (lastItem.afterLineNumber === item.afterLineNumber && lastItem.domNode === null) {
					lastItem.heightInLines += item.heightInLines;
					return;
				}
			}
			destination.push(item);
		};

A
Alex Dima 已提交
1415 1416
		let modifiedForeignVZ = new ForeignViewZonesIterator(this.modifiedForeignVZ);
		let originalForeignVZ = new ForeignViewZonesIterator(this.originalForeignVZ);
E
Erich Gamma 已提交
1417 1418

		// 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
A
Alex Dima 已提交
1419 1420
		for (let i = 0, length = this.lineChanges.length; i <= length; i++) {
			let lineChange = (i < length ? this.lineChanges[i] : null);
E
Erich Gamma 已提交
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437

			if (lineChange !== null) {
				originalEquivalentLineNumber = lineChange.originalStartLineNumber + (lineChange.originalEndLineNumber > 0 ? -1 : 0);
				modifiedEquivalentLineNumber = lineChange.modifiedStartLineNumber + (lineChange.modifiedEndLineNumber > 0 ? -1 : 0);
				lineChangeOriginalLength = (lineChange.originalEndLineNumber > 0 ? (lineChange.originalEndLineNumber - lineChange.originalStartLineNumber + 1) : 0);
				lineChangeModifiedLength = (lineChange.modifiedEndLineNumber > 0 ? (lineChange.modifiedEndLineNumber - lineChange.modifiedStartLineNumber + 1) : 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
A
Alex Dima 已提交
1438 1439
			let stepOriginal: IMyViewZone[] = [];
			let stepModified: IMyViewZone[] = [];
E
Erich Gamma 已提交
1440 1441 1442 1443 1444

			// ---------------------------- PRODUCE VIEW ZONES

			// [PRODUCE] View zone(s) in original-side due to foreign view zone(s) in modified-side
			while (modifiedForeignVZ.current && modifiedForeignVZ.current.afterLineNumber <= modifiedEndEquivalentLineNumber) {
A
Alex Dima 已提交
1445
				let viewZoneLineNumber: number;
E
Erich Gamma 已提交
1446 1447 1448 1449 1450
				if (modifiedForeignVZ.current.afterLineNumber <= modifiedEquivalentLineNumber) {
					viewZoneLineNumber = originalEquivalentLineNumber - modifiedEquivalentLineNumber + modifiedForeignVZ.current.afterLineNumber;
				} else {
					viewZoneLineNumber = originalEndEquivalentLineNumber;
				}
A
Alex Dima 已提交
1451

1452
				let marginDomNode: HTMLDivElement | null = null;
A
Alex Dima 已提交
1453 1454 1455 1456
				if (lineChange && lineChange.modifiedStartLineNumber <= modifiedForeignVZ.current.afterLineNumber && modifiedForeignVZ.current.afterLineNumber <= lineChange.modifiedEndLineNumber) {
					marginDomNode = this._createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion();
				}

E
Erich Gamma 已提交
1457 1458 1459
				stepOriginal.push({
					afterLineNumber: viewZoneLineNumber,
					heightInLines: modifiedForeignVZ.current.heightInLines,
A
Alex Dima 已提交
1460 1461
					domNode: null,
					marginDomNode: marginDomNode
E
Erich Gamma 已提交
1462 1463 1464 1465 1466 1467
				});
				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) {
A
Alex Dima 已提交
1468
				let viewZoneLineNumber: number;
E
Erich Gamma 已提交
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
				if (originalForeignVZ.current.afterLineNumber <= originalEquivalentLineNumber) {
					viewZoneLineNumber = modifiedEquivalentLineNumber - originalEquivalentLineNumber + originalForeignVZ.current.afterLineNumber;
				} else {
					viewZoneLineNumber = modifiedEndEquivalentLineNumber;
				}
				stepModified.push({
					afterLineNumber: viewZoneLineNumber,
					heightInLines: originalForeignVZ.current.heightInLines,
					domNode: null
				});
				originalForeignVZ.advance();
			}

			if (lineChange !== null && isChangeOrInsert(lineChange)) {
A
Alex Dima 已提交
1483
				let r = this._produceOriginalFromDiff(lineChange, lineChangeOriginalLength, lineChangeModifiedLength);
E
Erich Gamma 已提交
1484 1485 1486 1487 1488 1489
				if (r) {
					stepOriginal.push(r);
				}
			}

			if (lineChange !== null && isChangeOrDelete(lineChange)) {
A
Alex Dima 已提交
1490
				let r = this._produceModifiedFromDiff(lineChange, lineChangeOriginalLength, lineChangeModifiedLength);
E
Erich Gamma 已提交
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
				if (r) {
					stepModified.push(r);
				}
			}

			// ---------------------------- END PRODUCE VIEW ZONES


			// ---------------------------- EMIT MINIMAL VIEW ZONES

			// [CANCEL & EMIT] Try to cancel view zones out
A
Alex Dima 已提交
1502 1503
			let stepOriginalIndex = 0;
			let stepModifiedIndex = 0;
E
Erich Gamma 已提交
1504 1505 1506 1507 1508

			stepOriginal = stepOriginal.sort(sortMyViewZones);
			stepModified = stepModified.sort(sortMyViewZones);

			while (stepOriginalIndex < stepOriginal.length && stepModifiedIndex < stepModified.length) {
A
Alex Dima 已提交
1509 1510
				let original = stepOriginal[stepOriginalIndex];
				let modified = stepModified[stepModifiedIndex];
E
Erich Gamma 已提交
1511

A
Alex Dima 已提交
1512 1513
				let originalDelta = original.afterLineNumber - originalEquivalentLineNumber;
				let modifiedDelta = modified.afterLineNumber - modifiedEquivalentLineNumber;
E
Erich Gamma 已提交
1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554

				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
		}

A
Alex Dima 已提交
1555 1556 1557 1558 1559 1560
		return {
			original: ViewZonesComputer._ensureDomNodes(result.original),
			modified: ViewZonesComputer._ensureDomNodes(result.modified),
		};
	}

1561
	private static _ensureDomNodes(zones: IMyViewZone[]): IMyViewZone[] {
A
Alex Dima 已提交
1562
		return zones.map((z) => {
E
Erich Gamma 已提交
1563 1564 1565
			if (!z.domNode) {
				z.domNode = createFakeLinesDiv();
			}
1566
			return z;
A
Alex Dima 已提交
1567
		});
E
Erich Gamma 已提交
1568 1569
	}

A
Alex Dima 已提交
1570
	protected abstract _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null;
A
Alex Dima 已提交
1571

A
Alex Dima 已提交
1572
	protected abstract _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null;
E
Erich Gamma 已提交
1573

A
Alex Dima 已提交
1574
	protected abstract _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null;
E
Erich Gamma 已提交
1575 1576
}

1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
function createDecoration(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number, options: ModelDecorationOptions) {
	return {
		range: new Range(startLineNumber, startColumn, endLineNumber, endColumn),
		options: options
	};
}

const DECORATIONS = {

	charDelete: ModelDecorationOptions.register({
		className: 'char-delete'
	}),
	charDeleteWholeLine: ModelDecorationOptions.register({
		className: 'char-delete',
		isWholeLine: true
	}),

	charInsert: ModelDecorationOptions.register({
		className: 'char-insert'
	}),
	charInsertWholeLine: ModelDecorationOptions.register({
		className: 'char-insert',
		isWholeLine: true
	}),

	lineInsert: ModelDecorationOptions.register({
		className: 'line-insert',
		marginClassName: 'line-insert',
		isWholeLine: true
	}),
	lineInsertWithSign: ModelDecorationOptions.register({
		className: 'line-insert',
		linesDecorationsClassName: 'insert-sign',
		marginClassName: 'line-insert',
		isWholeLine: true
	}),

	lineDelete: ModelDecorationOptions.register({
		className: 'line-delete',
		marginClassName: 'line-delete',
		isWholeLine: true
	}),
	lineDeleteWithSign: ModelDecorationOptions.register({
		className: 'line-delete',
		linesDecorationsClassName: 'delete-sign',
		marginClassName: 'line-delete',
		isWholeLine: true

	}),
	lineDeleteMargin: ModelDecorationOptions.register({
		marginClassName: 'line-delete',
	})

};

H
Howard Hung 已提交
1632
class DiffEditorWidgetSideBySide extends DiffEditorWidgetStyle implements IDiffEditorWidgetStyle, IVerticalSashLayoutProvider {
E
Erich Gamma 已提交
1633

1634
	static readonly MINIMUM_EDITOR_WIDTH = 100;
E
Erich Gamma 已提交
1635 1636

	private _disableSash: boolean;
1637
	private readonly _sash: Sash;
A
Alex Dima 已提交
1638 1639
	private _sashRatio: number | null;
	private _sashPosition: number | null;
A
Alex Dima 已提交
1640
	private _startSashPosition: number | null;
E
Erich Gamma 已提交
1641

J
Johannes Rieken 已提交
1642
	constructor(dataSource: IDataSource, enableSplitViewResizing: boolean) {
E
Erich Gamma 已提交
1643 1644 1645 1646 1647
		super(dataSource);

		this._disableSash = (enableSplitViewResizing === false);
		this._sashRatio = null;
		this._sashPosition = null;
A
Alex Dima 已提交
1648
		this._startSashPosition = null;
A
Alex Dima 已提交
1649
		this._sash = this._register(new Sash(this._dataSource.getContainerDomNode(), this));
E
Erich Gamma 已提交
1650 1651

		if (this._disableSash) {
J
Joao Moreno 已提交
1652
			this._sash.state = SashState.Disabled;
E
Erich Gamma 已提交
1653 1654
		}

I
isidor 已提交
1655 1656 1657 1658
		this._sash.onDidStart(() => this.onSashDragStart());
		this._sash.onDidChange((e: ISashEvent) => this.onSashDrag(e));
		this._sash.onDidEnd(() => this.onSashDragEnd());
		this._sash.onDidReset(() => this.onSashReset());
E
Erich Gamma 已提交
1659 1660
	}

J
Johannes Rieken 已提交
1661
	public setEnableSplitViewResizing(enableSplitViewResizing: boolean): void {
A
Alex Dima 已提交
1662
		let newDisableSash = (enableSplitViewResizing === false);
E
Erich Gamma 已提交
1663 1664
		if (this._disableSash !== newDisableSash) {
			this._disableSash = newDisableSash;
J
Joao Moreno 已提交
1665
			this._sash.state = this._disableSash ? SashState.Disabled : SashState.Enabled;
E
Erich Gamma 已提交
1666 1667 1668
		}
	}

A
Alex Dima 已提交
1669
	public layout(sashRatio: number | null = this._sashRatio): number {
A
Alex Dima 已提交
1670 1671
		let w = this._dataSource.getWidth();
		let contentWidth = w - DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH;
E
Erich Gamma 已提交
1672

A
Alex Dima 已提交
1673 1674
		let sashPosition = Math.floor((sashRatio || 0.5) * contentWidth);
		let midPoint = Math.floor(0.5 * contentWidth);
E
Erich Gamma 已提交
1675

A
Alex Dima 已提交
1676
		sashPosition = this._disableSash ? midPoint : sashPosition || midPoint;
E
Erich Gamma 已提交
1677

H
Howard Hung 已提交
1678 1679 1680
		if (contentWidth > DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH * 2) {
			if (sashPosition < DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH) {
				sashPosition = DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH;
E
Erich Gamma 已提交
1681 1682
			}

H
Howard Hung 已提交
1683 1684
			if (sashPosition > contentWidth - DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH) {
				sashPosition = contentWidth - DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH;
E
Erich Gamma 已提交
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697
			}
		} else {
			sashPosition = midPoint;
		}

		if (this._sashPosition !== sashPosition) {
			this._sashPosition = sashPosition;
			this._sash.layout();
		}

		return this._sashPosition;
	}

M
Maxime Quandalle 已提交
1698
	private onSashDragStart(): void {
A
Alex Dima 已提交
1699
		this._startSashPosition = this._sashPosition!;
E
Erich Gamma 已提交
1700 1701
	}

J
Johannes Rieken 已提交
1702
	private onSashDrag(e: ISashEvent): void {
A
Alex Dima 已提交
1703 1704
		let w = this._dataSource.getWidth();
		let contentWidth = w - DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH;
A
Alex Dima 已提交
1705
		let sashPosition = this.layout((this._startSashPosition! + (e.currentX - e.startX)) / contentWidth);
E
Erich Gamma 已提交
1706 1707 1708 1709 1710 1711

		this._sashRatio = sashPosition / contentWidth;

		this._dataSource.relayoutEditors();
	}

M
Maxime Quandalle 已提交
1712 1713 1714 1715 1716 1717 1718
	private onSashDragEnd(): void {
		this._sash.layout();
	}

	private onSashReset(): void {
		this._sashRatio = 0.5;
		this._dataSource.relayoutEditors();
E
Erich Gamma 已提交
1719 1720 1721
		this._sash.layout();
	}

A
Alex Dima 已提交
1722
	public getVerticalSashTop(sash: Sash): number {
E
Erich Gamma 已提交
1723 1724 1725
		return 0;
	}

A
Alex Dima 已提交
1726
	public getVerticalSashLeft(sash: Sash): number {
A
Alex Dima 已提交
1727
		return this._sashPosition!;
E
Erich Gamma 已提交
1728 1729
	}

A
Alex Dima 已提交
1730
	public getVerticalSashHeight(sash: Sash): number {
E
Erich Gamma 已提交
1731 1732 1733
		return this._dataSource.getHeight();
	}

A
Alexandru Dima 已提交
1734
	protected _getViewZones(lineChanges: editorCommon.ILineChange[], originalForeignVZ: EditorWhitespace[], modifiedForeignVZ: EditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorsZones {
A
Alex Dima 已提交
1735
		let c = new SideBySideViewZonesComputer(lineChanges, originalForeignVZ, modifiedForeignVZ);
E
Erich Gamma 已提交
1736 1737 1738
		return c.getViewZones();
	}

1739
	protected _getOriginalEditorDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorDiffDecorations {
A
Alex Dima 已提交
1740
		const overviewZoneColor = String(this._removeColor);
E
Erich Gamma 已提交
1741

A
Alex Dima 已提交
1742
		let result: IEditorDiffDecorations = {
J
Johannes Rieken 已提交
1743 1744
			decorations: [],
			overviewZones: []
P
Peng Lyu 已提交
1745
		};
A
Alex Dima 已提交
1746

A
Alex Dima 已提交
1747
		let originalModel = originalEditor.getModel()!;
A
Alex Dima 已提交
1748 1749 1750

		for (let i = 0, length = lineChanges.length; i < length; i++) {
			let lineChange = lineChanges[i];
E
Erich Gamma 已提交
1751 1752

			if (isChangeOrDelete(lineChange)) {
1753
				result.decorations.push({
1754
					range: new Range(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
1755
					options: (renderIndicators ? DECORATIONS.lineDeleteWithSign : DECORATIONS.lineDelete)
1756
				});
E
Erich Gamma 已提交
1757
				if (!isChangeOrInsert(lineChange) || !lineChange.charChanges) {
1758
					result.decorations.push(createDecoration(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charDeleteWholeLine));
E
Erich Gamma 已提交
1759 1760
				}

A
Alex Dima 已提交
1761
				result.overviewZones.push(new OverviewRulerZone(
A
Alex Dima 已提交
1762 1763
					lineChange.originalStartLineNumber,
					lineChange.originalEndLineNumber,
A
Alex Dima 已提交
1764
					overviewZoneColor
A
Alex Dima 已提交
1765
				));
E
Erich Gamma 已提交
1766 1767

				if (lineChange.charChanges) {
A
Alex Dima 已提交
1768 1769
					for (let j = 0, lengthJ = lineChange.charChanges.length; j < lengthJ; j++) {
						let charChange = lineChange.charChanges[j];
E
Erich Gamma 已提交
1770 1771
						if (isChangeOrDelete(charChange)) {
							if (ignoreTrimWhitespace) {
A
Alex Dima 已提交
1772 1773 1774
								for (let lineNumber = charChange.originalStartLineNumber; lineNumber <= charChange.originalEndLineNumber; lineNumber++) {
									let startColumn: number;
									let endColumn: number;
E
Erich Gamma 已提交
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784
									if (lineNumber === charChange.originalStartLineNumber) {
										startColumn = charChange.originalStartColumn;
									} else {
										startColumn = originalModel.getLineFirstNonWhitespaceColumn(lineNumber);
									}
									if (lineNumber === charChange.originalEndLineNumber) {
										endColumn = charChange.originalEndColumn;
									} else {
										endColumn = originalModel.getLineLastNonWhitespaceColumn(lineNumber);
									}
1785
									result.decorations.push(createDecoration(lineNumber, startColumn, lineNumber, endColumn, DECORATIONS.charDelete));
E
Erich Gamma 已提交
1786 1787
								}
							} else {
1788
								result.decorations.push(createDecoration(charChange.originalStartLineNumber, charChange.originalStartColumn, charChange.originalEndLineNumber, charChange.originalEndColumn, DECORATIONS.charDelete));
E
Erich Gamma 已提交
1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
							}
						}
					}
				}
			}
		}

		return result;
	}

1799
	protected _getModifiedEditorDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorDiffDecorations {
A
Alex Dima 已提交
1800
		const overviewZoneColor = String(this._insertColor);
E
Erich Gamma 已提交
1801

A
Alex Dima 已提交
1802
		let result: IEditorDiffDecorations = {
J
Johannes Rieken 已提交
1803 1804
			decorations: [],
			overviewZones: []
A
Alex Dima 已提交
1805 1806
		};

A
Alex Dima 已提交
1807
		let modifiedModel = modifiedEditor.getModel()!;
A
Alex Dima 已提交
1808 1809 1810

		for (let i = 0, length = lineChanges.length; i < length; i++) {
			let lineChange = lineChanges[i];
E
Erich Gamma 已提交
1811 1812 1813

			if (isChangeOrInsert(lineChange)) {

1814
				result.decorations.push({
1815
					range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
1816
					options: (renderIndicators ? DECORATIONS.lineInsertWithSign : DECORATIONS.lineInsert)
1817
				});
E
Erich Gamma 已提交
1818
				if (!isChangeOrDelete(lineChange) || !lineChange.charChanges) {
1819
					result.decorations.push(createDecoration(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charInsertWholeLine));
E
Erich Gamma 已提交
1820
				}
A
Alex Dima 已提交
1821
				result.overviewZones.push(new OverviewRulerZone(
A
Alex Dima 已提交
1822 1823
					lineChange.modifiedStartLineNumber,
					lineChange.modifiedEndLineNumber,
A
Alex Dima 已提交
1824
					overviewZoneColor
A
Alex Dima 已提交
1825
				));
E
Erich Gamma 已提交
1826 1827

				if (lineChange.charChanges) {
A
Alex Dima 已提交
1828 1829
					for (let j = 0, lengthJ = lineChange.charChanges.length; j < lengthJ; j++) {
						let charChange = lineChange.charChanges[j];
E
Erich Gamma 已提交
1830 1831
						if (isChangeOrInsert(charChange)) {
							if (ignoreTrimWhitespace) {
A
Alex Dima 已提交
1832 1833 1834
								for (let lineNumber = charChange.modifiedStartLineNumber; lineNumber <= charChange.modifiedEndLineNumber; lineNumber++) {
									let startColumn: number;
									let endColumn: number;
E
Erich Gamma 已提交
1835 1836 1837 1838 1839 1840 1841 1842 1843 1844
									if (lineNumber === charChange.modifiedStartLineNumber) {
										startColumn = charChange.modifiedStartColumn;
									} else {
										startColumn = modifiedModel.getLineFirstNonWhitespaceColumn(lineNumber);
									}
									if (lineNumber === charChange.modifiedEndLineNumber) {
										endColumn = charChange.modifiedEndColumn;
									} else {
										endColumn = modifiedModel.getLineLastNonWhitespaceColumn(lineNumber);
									}
1845
									result.decorations.push(createDecoration(lineNumber, startColumn, lineNumber, endColumn, DECORATIONS.charInsert));
E
Erich Gamma 已提交
1846 1847
								}
							} else {
1848
								result.decorations.push(createDecoration(charChange.modifiedStartLineNumber, charChange.modifiedStartColumn, charChange.modifiedEndLineNumber, charChange.modifiedEndColumn, DECORATIONS.charInsert));
E
Erich Gamma 已提交
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861
							}
						}
					}
				}

			}
		}
		return result;
	}
}

class SideBySideViewZonesComputer extends ViewZonesComputer {

A
Alexandru Dima 已提交
1862
	constructor(lineChanges: editorCommon.ILineChange[], originalForeignVZ: EditorWhitespace[], modifiedForeignVZ: EditorWhitespace[]) {
E
Erich Gamma 已提交
1863 1864 1865
		super(lineChanges, originalForeignVZ, modifiedForeignVZ);
	}

A
Alex Dima 已提交
1866
	protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null {
A
Alex Dima 已提交
1867 1868 1869
		return null;
	}

A
Alex Dima 已提交
1870
	protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
E
Erich Gamma 已提交
1871 1872 1873 1874 1875 1876 1877 1878 1879 1880
		if (lineChangeModifiedLength > lineChangeOriginalLength) {
			return {
				afterLineNumber: Math.max(lineChange.originalStartLineNumber, lineChange.originalEndLineNumber),
				heightInLines: (lineChangeModifiedLength - lineChangeOriginalLength),
				domNode: null
			};
		}
		return null;
	}

A
Alex Dima 已提交
1881
	protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
E
Erich Gamma 已提交
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
		if (lineChangeOriginalLength > lineChangeModifiedLength) {
			return {
				afterLineNumber: Math.max(lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber),
				heightInLines: (lineChangeOriginalLength - lineChangeModifiedLength),
				domNode: null
			};
		}
		return null;
	}
}

H
Howard Hung 已提交
1893
class DiffEditorWidgetInline extends DiffEditorWidgetStyle implements IDiffEditorWidgetStyle {
E
Erich Gamma 已提交
1894 1895 1896

	private decorationsLeft: number;

J
Johannes Rieken 已提交
1897
	constructor(dataSource: IDataSource, enableSplitViewResizing: boolean) {
E
Erich Gamma 已提交
1898 1899
		super(dataSource);

1900
		this.decorationsLeft = dataSource.getOriginalEditor().getLayoutInfo().decorationsLeft;
E
Erich Gamma 已提交
1901

1902
		this._register(dataSource.getOriginalEditor().onDidLayoutChange((layoutInfo: EditorLayoutInfo) => {
E
Erich Gamma 已提交
1903 1904 1905 1906 1907 1908 1909
			if (this.decorationsLeft !== layoutInfo.decorationsLeft) {
				this.decorationsLeft = layoutInfo.decorationsLeft;
				dataSource.relayoutEditors();
			}
		}));
	}

J
Johannes Rieken 已提交
1910
	public setEnableSplitViewResizing(enableSplitViewResizing: boolean): void {
E
Erich Gamma 已提交
1911 1912 1913
		// Nothing to do..
	}

A
Alexandru Dima 已提交
1914
	protected _getViewZones(lineChanges: editorCommon.ILineChange[], originalForeignVZ: EditorWhitespace[], modifiedForeignVZ: EditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor, renderIndicators: boolean): IEditorsZones {
1915
		let computer = new InlineViewZonesComputer(lineChanges, originalForeignVZ, modifiedForeignVZ, originalEditor, modifiedEditor, renderIndicators);
E
Erich Gamma 已提交
1916 1917 1918
		return computer.getViewZones();
	}

1919
	protected _getOriginalEditorDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorDiffDecorations {
A
Alex Dima 已提交
1920
		const overviewZoneColor = String(this._removeColor);
A
Alex Dima 已提交
1921

A
Alex Dima 已提交
1922
		let result: IEditorDiffDecorations = {
J
Johannes Rieken 已提交
1923 1924
			decorations: [],
			overviewZones: []
A
Alex Dima 已提交
1925
		};
E
Erich Gamma 已提交
1926

A
Alex Dima 已提交
1927 1928
		for (let i = 0, length = lineChanges.length; i < length; i++) {
			let lineChange = lineChanges[i];
E
Erich Gamma 已提交
1929 1930 1931

			// Add overview zones in the overview ruler
			if (isChangeOrDelete(lineChange)) {
1932
				result.decorations.push({
1933
					range: new Range(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
1934
					options: DECORATIONS.lineDeleteMargin
1935 1936
				});

A
Alex Dima 已提交
1937
				result.overviewZones.push(new OverviewRulerZone(
A
Alex Dima 已提交
1938 1939
					lineChange.originalStartLineNumber,
					lineChange.originalEndLineNumber,
A
Alex Dima 已提交
1940
					overviewZoneColor
A
Alex Dima 已提交
1941
				));
E
Erich Gamma 已提交
1942 1943 1944 1945 1946 1947
			}
		}

		return result;
	}

1948
	protected _getModifiedEditorDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorDiffDecorations {
A
Alex Dima 已提交
1949
		const overviewZoneColor = String(this._insertColor);
E
Erich Gamma 已提交
1950

A
Alex Dima 已提交
1951
		let result: IEditorDiffDecorations = {
J
Johannes Rieken 已提交
1952 1953
			decorations: [],
			overviewZones: []
A
Alex Dima 已提交
1954 1955
		};

A
Alex Dima 已提交
1956
		let modifiedModel = modifiedEditor.getModel()!;
A
Alex Dima 已提交
1957 1958 1959

		for (let i = 0, length = lineChanges.length; i < length; i++) {
			let lineChange = lineChanges[i];
E
Erich Gamma 已提交
1960 1961 1962

			// Add decorations & overview zones
			if (isChangeOrInsert(lineChange)) {
1963
				result.decorations.push({
1964
					range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
1965
					options: (renderIndicators ? DECORATIONS.lineInsertWithSign : DECORATIONS.lineInsert)
1966
				});
E
Erich Gamma 已提交
1967

A
Alex Dima 已提交
1968
				result.overviewZones.push(new OverviewRulerZone(
A
Alex Dima 已提交
1969 1970
					lineChange.modifiedStartLineNumber,
					lineChange.modifiedEndLineNumber,
A
Alex Dima 已提交
1971
					overviewZoneColor
A
Alex Dima 已提交
1972
				));
E
Erich Gamma 已提交
1973 1974

				if (lineChange.charChanges) {
A
Alex Dima 已提交
1975 1976
					for (let j = 0, lengthJ = lineChange.charChanges.length; j < lengthJ; j++) {
						let charChange = lineChange.charChanges[j];
E
Erich Gamma 已提交
1977 1978
						if (isChangeOrInsert(charChange)) {
							if (ignoreTrimWhitespace) {
A
Alex Dima 已提交
1979 1980 1981
								for (let lineNumber = charChange.modifiedStartLineNumber; lineNumber <= charChange.modifiedEndLineNumber; lineNumber++) {
									let startColumn: number;
									let endColumn: number;
E
Erich Gamma 已提交
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991
									if (lineNumber === charChange.modifiedStartLineNumber) {
										startColumn = charChange.modifiedStartColumn;
									} else {
										startColumn = modifiedModel.getLineFirstNonWhitespaceColumn(lineNumber);
									}
									if (lineNumber === charChange.modifiedEndLineNumber) {
										endColumn = charChange.modifiedEndColumn;
									} else {
										endColumn = modifiedModel.getLineLastNonWhitespaceColumn(lineNumber);
									}
1992
									result.decorations.push(createDecoration(lineNumber, startColumn, lineNumber, endColumn, DECORATIONS.charInsert));
E
Erich Gamma 已提交
1993 1994
								}
							} else {
1995
								result.decorations.push(createDecoration(charChange.modifiedStartLineNumber, charChange.modifiedStartColumn, charChange.modifiedEndLineNumber, charChange.modifiedEndColumn, DECORATIONS.charInsert));
E
Erich Gamma 已提交
1996 1997 1998 1999
							}
						}
					}
				} else {
2000
					result.decorations.push(createDecoration(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charInsertWholeLine));
E
Erich Gamma 已提交
2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016
				}
			}
		}

		return result;
	}

	public layout(): number {
		// An editor should not be smaller than 5px
		return Math.max(5, this.decorationsLeft);
	}

}

class InlineViewZonesComputer extends ViewZonesComputer {

2017
	private readonly originalModel: ITextModel;
2018
	private readonly modifiedEditorOptions: IComputedEditorOptions;
2019 2020
	private readonly modifiedEditorTabSize: number;
	private readonly renderIndicators: boolean;
E
Erich Gamma 已提交
2021

A
Alexandru Dima 已提交
2022
	constructor(lineChanges: editorCommon.ILineChange[], originalForeignVZ: EditorWhitespace[], modifiedForeignVZ: EditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor, renderIndicators: boolean) {
E
Erich Gamma 已提交
2023
		super(lineChanges, originalForeignVZ, modifiedForeignVZ);
A
Alex Dima 已提交
2024
		this.originalModel = originalEditor.getModel()!;
A
Alex Dima 已提交
2025
		this.modifiedEditorOptions = modifiedEditor.getOptions();
A
Alex Dima 已提交
2026
		this.modifiedEditorTabSize = modifiedEditor.getModel()!.getOptions().tabSize;
R
rebornix 已提交
2027
		this.renderIndicators = renderIndicators;
E
Erich Gamma 已提交
2028 2029
	}

A
Alex Dima 已提交
2030
	protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null {
A
Alex Dima 已提交
2031 2032 2033 2034 2035
		let result = document.createElement('div');
		result.className = 'inline-added-margin-view-zone';
		return result;
	}

A
Alex Dima 已提交
2036
	protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
2037 2038 2039
		let marginDomNode = document.createElement('div');
		marginDomNode.className = 'inline-added-margin-view-zone';

E
Erich Gamma 已提交
2040
		return {
J
Johannes Rieken 已提交
2041
			afterLineNumber: Math.max(lineChange.originalStartLineNumber, lineChange.originalEndLineNumber),
E
Erich Gamma 已提交
2042
			heightInLines: lineChangeModifiedLength,
2043 2044
			domNode: document.createElement('div'),
			marginDomNode: marginDomNode
E
Erich Gamma 已提交
2045 2046 2047
		};
	}

A
Alex Dima 已提交
2048
	protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
A
Alex Dima 已提交
2049
		let decorations: InlineDecoration[] = [];
E
Erich Gamma 已提交
2050
		if (lineChange.charChanges) {
A
Alex Dima 已提交
2051 2052
			for (let j = 0, lengthJ = lineChange.charChanges.length; j < lengthJ; j++) {
				let charChange = lineChange.charChanges[j];
E
Erich Gamma 已提交
2053
				if (isChangeOrDelete(charChange)) {
2054 2055
					decorations.push(new InlineDecoration(
						new Range(charChange.originalStartLineNumber, charChange.originalStartColumn, charChange.originalEndLineNumber, charChange.originalEndColumn),
2056
						'char-delete',
2057
						InlineDecorationType.Regular
2058
					));
E
Erich Gamma 已提交
2059 2060 2061 2062
				}
			}
		}

2063
		let sb = createStringBuilder(10000);
2064
		let marginHTML: string[] = [];
A
renames  
Alex Dima 已提交
2065
		const layoutInfo = this.modifiedEditorOptions.get(EditorOption.layoutInfo);
2066
		const fontInfo = this.modifiedEditorOptions.get(EditorOption.fontInfo);
A
Alex Dima 已提交
2067 2068
		const lineDecorationsWidth = layoutInfo.decorationsWidth;

A
Alex Dima 已提交
2069
		let lineHeight = this.modifiedEditorOptions.get(EditorOption.lineHeight);
2070
		const typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth;
2071
		let maxCharsPerLine = 0;
2072
		const originalContent: string[] = [];
A
Alex Dima 已提交
2073
		for (let lineNumber = lineChange.originalStartLineNumber; lineNumber <= lineChange.originalEndLineNumber; lineNumber++) {
2074
			maxCharsPerLine = Math.max(maxCharsPerLine, this._renderOriginalLine(lineNumber - lineChange.originalStartLineNumber, this.originalModel, this.modifiedEditorOptions, this.modifiedEditorTabSize, lineNumber, decorations, sb));
2075
			originalContent.push(this.originalModel.getLineContent(lineNumber));
2076

R
rebornix 已提交
2077
			if (this.renderIndicators) {
2078 2079 2080 2081 2082
				let index = lineNumber - lineChange.originalStartLineNumber;
				marginHTML = marginHTML.concat([
					`<div class="delete-sign" style="position:absolute;top:${index * lineHeight}px;width:${lineDecorationsWidth}px;height:${lineHeight}px;right:0;"></div>`
				]);
			}
E
Erich Gamma 已提交
2083
		}
A
Alex Dima 已提交
2084
		maxCharsPerLine += this.modifiedEditorOptions.get(EditorOption.scrollBeyondLastColumn);
E
Erich Gamma 已提交
2085

A
Alex Dima 已提交
2086
		let domNode = document.createElement('div');
E
Erich Gamma 已提交
2087
		domNode.className = 'view-lines line-delete';
2088
		domNode.innerHTML = sb.build();
2089
		Configuration.applyFontInfoSlow(domNode, fontInfo);
E
Erich Gamma 已提交
2090

2091 2092 2093
		let marginDomNode = document.createElement('div');
		marginDomNode.className = 'inline-deleted-margin-view-zone';
		marginDomNode.innerHTML = marginHTML.join('');
2094
		Configuration.applyFontInfoSlow(marginDomNode, fontInfo);
2095

E
Erich Gamma 已提交
2096 2097 2098 2099
		return {
			shouldNotShrink: true,
			afterLineNumber: (lineChange.modifiedEndLineNumber === 0 ? lineChange.modifiedStartLineNumber : lineChange.modifiedStartLineNumber - 1),
			heightInLines: lineChangeOriginalLength,
2100
			minWidthInPx: (maxCharsPerLine * typicalHalfwidthCharacterWidth),
2101
			domNode: domNode,
2102 2103 2104 2105 2106 2107 2108 2109
			marginDomNode: marginDomNode,
			diff: {
				originalStartLineNumber: lineChange.originalStartLineNumber,
				originalEndLineNumber: lineChange.originalEndLineNumber,
				modifiedStartLineNumber: lineChange.modifiedStartLineNumber,
				modifiedEndLineNumber: lineChange.modifiedEndLineNumber,
				originalContent: originalContent
			}
E
Erich Gamma 已提交
2110 2111 2112
		};
	}

2113
	private _renderOriginalLine(count: number, originalModel: ITextModel, options: IComputedEditorOptions, tabSize: number, lineNumber: number, decorations: InlineDecoration[], sb: IStringBuilder): number {
2114 2115
		const lineTokens = originalModel.getLineTokens(lineNumber);
		const lineContent = lineTokens.getLineContent();
2116
		const fontInfo = options.get(EditorOption.fontInfo);
A
Alex Dima 已提交
2117

2118
		const actualDecorations = LineDecoration.filter(decorations, lineNumber, 1, lineContent.length + 1);
A
Alex Dima 已提交
2119

2120 2121 2122 2123 2124 2125
		sb.appendASCIIString('<div class="view-line');
		if (decorations.length === 0) {
			// No char changes
			sb.appendASCIIString(' char-delete');
		}
		sb.appendASCIIString('" style="top:');
A
Alex Dima 已提交
2126
		sb.appendASCIIString(String(count * options.get(EditorOption.lineHeight)));
2127 2128
		sb.appendASCIIString('px;width:1000000px;">');

2129 2130
		const isBasicASCII = ViewLineRenderingData.isBasicASCII(lineContent, originalModel.mightContainNonBasicASCII());
		const containsRTL = ViewLineRenderingData.containsRTL(lineContent, isBasicASCII, originalModel.mightContainRTL());
2131
		const output = renderViewLine(new RenderLineInput(
2132
			(fontInfo.isMonospace && !options.get(EditorOption.disableMonospaceOptimizations)),
2133
			fontInfo.canUseHalfwidthRightwardsArrow,
A
Alex Dima 已提交
2134
			lineContent,
A
Alex Dima 已提交
2135
			false,
2136 2137
			isBasicASCII,
			containsRTL,
2138
			0,
A
Alex Dima 已提交
2139
			lineTokens,
2140
			actualDecorations,
A
Alex Dima 已提交
2141
			tabSize,
2142
			fontInfo.spaceWidth,
A
Alex Dima 已提交
2143 2144 2145
			options.get(EditorOption.stopRenderingLineAfter),
			options.get(EditorOption.renderWhitespace),
			options.get(EditorOption.renderControlCharacters),
2146
			options.get(EditorOption.fontLigatures) !== EditorFontLigatures.OFF,
2147
			null // Send no selections, original line cannot be selected
2148
		), sb);
E
Erich Gamma 已提交
2149

2150
		sb.appendASCIIString('</div>');
2151 2152 2153

		const absoluteOffsets = output.characterMapping.getAbsoluteOffsets();
		return absoluteOffsets.length > 0 ? absoluteOffsets[absoluteOffsets.length - 1] : 0;
E
Erich Gamma 已提交
2154 2155 2156
	}
}

J
Johannes Rieken 已提交
2157
function isChangeOrInsert(lineChange: editorCommon.IChange): boolean {
E
Erich Gamma 已提交
2158 2159 2160
	return lineChange.modifiedEndLineNumber > 0;
}

J
Johannes Rieken 已提交
2161
function isChangeOrDelete(lineChange: editorCommon.IChange): boolean {
E
Erich Gamma 已提交
2162 2163 2164 2165
	return lineChange.originalEndLineNumber > 0;
}

function createFakeLinesDiv(): HTMLElement {
A
Alex Dima 已提交
2166
	let r = document.createElement('div');
E
Erich Gamma 已提交
2167 2168 2169
	r.className = 'diagonal-fill';
	return r;
}
2170 2171

registerThemingParticipant((theme, collector) => {
2172
	const added = theme.getColor(diffInserted);
2173 2174
	if (added) {
		collector.addRule(`.monaco-editor .line-insert, .monaco-editor .char-insert { background-color: ${added}; }`);
A
Alex Dima 已提交
2175
		collector.addRule(`.monaco-diff-editor .line-insert, .monaco-diff-editor .char-insert { background-color: ${added}; }`);
2176 2177
		collector.addRule(`.monaco-editor .inline-added-margin-view-zone { background-color: ${added}; }`);
	}
2178 2179

	const removed = theme.getColor(diffRemoved);
2180 2181
	if (removed) {
		collector.addRule(`.monaco-editor .line-delete, .monaco-editor .char-delete { background-color: ${removed}; }`);
A
Alex Dima 已提交
2182
		collector.addRule(`.monaco-diff-editor .line-delete, .monaco-diff-editor .char-delete { background-color: ${removed}; }`);
2183 2184
		collector.addRule(`.monaco-editor .inline-deleted-margin-view-zone { background-color: ${removed}; }`);
	}
2185 2186

	const addedOutline = theme.getColor(diffInsertedOutline);
2187
	if (addedOutline) {
2188
		collector.addRule(`.monaco-editor .line-insert, .monaco-editor .char-insert { border: 1px ${theme.type === 'hc' ? 'dashed' : 'solid'} ${addedOutline}; }`);
2189
	}
2190 2191

	const removedOutline = theme.getColor(diffRemovedOutline);
2192
	if (removedOutline) {
2193
		collector.addRule(`.monaco-editor .line-delete, .monaco-editor .char-delete { border: 1px ${theme.type === 'hc' ? 'dashed' : 'solid'} ${removedOutline}; }`);
2194
	}
2195 2196

	const shadow = theme.getColor(scrollbarShadow);
2197 2198 2199
	if (shadow) {
		collector.addRule(`.monaco-diff-editor.side-by-side .editor.modified { box-shadow: -6px 0 5px -5px ${shadow}; }`);
	}
2200

M
Matt Bierner 已提交
2201
	const border = theme.getColor(diffBorder);
2202 2203 2204
	if (border) {
		collector.addRule(`.monaco-diff-editor.side-by-side .editor.modified { border-left: 1px solid ${border}; }`);
	}
2205
});