diffEditorWidget.ts 86.1 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
João Moreno 已提交
10
import { ISashEvent, IVerticalSashLayoutProvider, Sash, SashState, Orientation } from 'vs/base/browser/ui/sash/sash';
11
import { RunOnceScheduler } 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';
35
import { IEditorWhitespace } 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';
41
import { defaultInsertColor, defaultRemoveColor, diffBorder, diffInserted, diffInsertedOutline, diffRemoved, diffRemovedOutline, scrollbarShadow, scrollbarSliderBackground, scrollbarSliderHoverBackground, scrollbarSliderActiveBackground, diffDiagonalFill } from 'vs/platform/theme/common/colorRegistry';
M
Martin Aeschlimann 已提交
42
import { IColorTheme, 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';
50
import { ElementSizeObserver } from 'vs/editor/browser/config/elementSizeObserver';
M
Martin Aeschlimann 已提交
51
import { Codicon, registerIcon } from 'vs/base/common/codicons';
52
import { MOUSE_CURSOR_TEXT_CSS_CLASS_NAME } from 'vs/base/browser/ui/mouseCursor/mouseCursor';
E
Erich Gamma 已提交
53 54

interface IEditorDiffDecorations {
55
	decorations: IModelDeltaDecoration[];
A
Alex Dima 已提交
56
	overviewZones: OverviewRulerZone[];
E
Erich Gamma 已提交
57 58 59
}

interface IEditorDiffDecorationsWithZones extends IEditorDiffDecorations {
60
	zones: IMyViewZone[];
E
Erich Gamma 已提交
61 62 63
}

interface IEditorsDiffDecorationsWithZones {
J
Johannes Rieken 已提交
64 65
	original: IEditorDiffDecorationsWithZones;
	modified: IEditorDiffDecorationsWithZones;
E
Erich Gamma 已提交
66 67 68
}

interface IEditorsZones {
69 70
	original: IMyViewZone[];
	modified: IMyViewZone[];
E
Erich Gamma 已提交
71 72
}

R
rebornix 已提交
73
export interface IDiffEditorWidgetStyle {
A
Alex Dima 已提交
74
	getEditorsDiffDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalWhitespaces: IEditorWhitespace[], modifiedWhitespaces: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorsDiffDecorationsWithZones;
J
Johannes Rieken 已提交
75
	setEnableSplitViewResizing(enableSplitViewResizing: boolean): void;
M
Martin Aeschlimann 已提交
76
	applyColors(theme: IColorTheme): boolean;
E
Erich Gamma 已提交
77 78 79 80 81
	layout(): number;
	dispose(): void;
}

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

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

A
Alex Dima 已提交
97
	public getForeignViewZones(allViewZones: IEditorWhitespace[]): IEditorWhitespace[] {
E
Erich Gamma 已提交
98 99 100
		return allViewZones.filter((z) => !this._zonesMap[String(z.id)]);
	}

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

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

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

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

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

139
				if (newDecorations.zones[i].diff && viewZone.marginDomNode) {
140
					viewZone.suppressMouseDown = false;
P
Peng Lyu 已提交
141
					this.inlineDiffMargins.push(new InlineDiffMargin(zoneId, viewZone.marginDomNode, editor, newDecorations.zones[i].diff!, this._contextMenuService, this._clipboardService));
142
				}
E
Erich Gamma 已提交
143 144 145
			}
		});

A
Alex Dima 已提交
146 147 148 149
		if (scrollState) {
			scrollState.restore(editor);
		}

E
Erich Gamma 已提交
150 151 152 153
		// decorations
		this._decorations = editor.deltaDecorations(this._decorations, newDecorations.decorations);

		// overview ruler
154 155 156
		if (overviewRuler) {
			overviewRuler.setZones(newDecorations.overviewZones);
		}
E
Erich Gamma 已提交
157 158 159
	}
}

A
Alex Dima 已提交
160
let DIFF_EDITOR_ID = 0;
E
Erich Gamma 已提交
161

M
Martin Aeschlimann 已提交
162 163 164 165

const diffInsertIcon = registerIcon('diff-insert', Codicon.add);
const diffRemoveIcon = registerIcon('diff-remove', Codicon.remove);

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

168
	private static readonly ONE_OVERVIEW_WIDTH = 15;
M
Matt Bierner 已提交
169
	public static readonly ENTIRE_DIFF_OVERVIEW_WIDTH = 30;
170
	private static readonly UPDATE_DIFF_DECORATIONS_DELAY = 200; // ms
E
Erich Gamma 已提交
171

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

A
Alex Dima 已提交
175 176 177 178
	private readonly _onDidUpdateDiff: Emitter<void> = this._register(new Emitter<void>());
	public readonly onDidUpdateDiff: Event<void> = this._onDidUpdateDiff.event;

	private readonly id: number;
179
	private _state: editorBrowser.DiffEditorState;
180
	private _updatingDiffProgress: IProgressRunner | null;
E
Erich Gamma 已提交
181

182
	private readonly _domElement: HTMLElement;
A
Alex Dima 已提交
183 184 185
	protected readonly _containerDomElement: HTMLElement;
	private readonly _overviewDomElement: HTMLElement;
	private readonly _overviewViewportDomElement: FastDomNode<HTMLElement>;
E
Erich Gamma 已提交
186

187
	private readonly _elementSizeObserver: ElementSizeObserver;
E
Erich Gamma 已提交
188

A
Alex Dima 已提交
189
	private readonly originalEditor: CodeEditorWidget;
A
Alex Dima 已提交
190
	private readonly _originalDomNode: HTMLElement;
191
	private readonly _originalEditorState: VisualEditorState;
A
Alex Dima 已提交
192
	private _originalOverviewRuler: editorBrowser.IOverviewRuler | null;
E
Erich Gamma 已提交
193

A
Alex Dima 已提交
194
	private readonly modifiedEditor: CodeEditorWidget;
A
Alex Dima 已提交
195
	private readonly _modifiedDomNode: HTMLElement;
196
	private readonly _modifiedEditorState: VisualEditorState;
A
Alex Dima 已提交
197
	private _modifiedOverviewRuler: editorBrowser.IOverviewRuler | null;
E
Erich Gamma 已提交
198

J
Johannes Rieken 已提交
199 200 201
	private _currentlyChangingViewZones: boolean;
	private _beginUpdateDecorationsTimeout: number;
	private _diffComputationToken: number;
A
Alex Dima 已提交
202
	private _diffComputationResult: IDiffComputationResult | null;
E
Erich Gamma 已提交
203

J
Johannes Rieken 已提交
204 205
	private _isVisible: boolean;
	private _isHandlingScrollEvent: boolean;
E
Erich Gamma 已提交
206 207

	private _ignoreTrimWhitespace: boolean;
208
	private _originalIsEditable: boolean;
209 210
	private _originalCodeLens: boolean;
	private _modifiedCodeLens: boolean;
E
Erich Gamma 已提交
211

J
Johannes Rieken 已提交
212
	private _renderSideBySide: boolean;
213
	private _maxComputationTime: number;
214
	private _renderIndicators: boolean;
J
Johannes Rieken 已提交
215
	private _enableSplitViewResizing: boolean;
A
Alex Dima 已提交
216
	private _strategy!: IDiffEditorWidgetStyle;
E
Erich Gamma 已提交
217

218
	private readonly _updateDecorationsRunner: RunOnceScheduler;
E
Erich Gamma 已提交
219

220
	private readonly _editorWorkerService: IEditorWorkerService;
221
	protected _contextKeyService: IContextKeyService;
222 223 224
	private readonly _codeEditorService: ICodeEditorService;
	private readonly _themeService: IThemeService;
	private readonly _notificationService: INotificationService;
225

226
	private readonly _reviewPane: DiffReview;
A
Alex Dima 已提交
227

228
	constructor(
J
Johannes Rieken 已提交
229
		domElement: HTMLElement,
230
		options: IDiffEditorOptions,
231
		@IClipboardService clipboardService: IClipboardService,
232
		@IEditorWorkerService editorWorkerService: IEditorWorkerService,
233
		@IContextKeyService contextKeyService: IContextKeyService,
234
		@IInstantiationService instantiationService: IInstantiationService,
235
		@ICodeEditorService codeEditorService: ICodeEditorService,
236
		@IThemeService themeService: IThemeService,
237 238
		@INotificationService notificationService: INotificationService,
		@IContextMenuService contextMenuService: IContextMenuService,
239
		@IEditorProgressService private readonly _editorProgressService: IEditorProgressService
240
	) {
E
Erich Gamma 已提交
241
		super();
A
Alex Dima 已提交
242

243
		this._editorWorkerService = editorWorkerService;
244
		this._codeEditorService = codeEditorService;
245
		this._contextKeyService = this._register(contextKeyService.createScoped(domElement));
J
Joao Moreno 已提交
246
		this._contextKeyService.createKey('isInDiffEditor', true);
247
		this._themeService = themeService;
248
		this._notificationService = notificationService;
E
Erich Gamma 已提交
249 250

		this.id = (++DIFF_EDITOR_ID);
251
		this._state = editorBrowser.DiffEditorState.Idle;
252
		this._updatingDiffProgress = null;
E
Erich Gamma 已提交
253 254 255 256 257 258 259 260 261 262

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

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

263 264 265 266
		// maxComputationTime
		this._maxComputationTime = 5000;
		if (typeof options.maxComputationTime !== 'undefined') {
			this._maxComputationTime = options.maxComputationTime;
267 268
		}

E
Erich Gamma 已提交
269 270 271 272 273 274
		// ignoreTrimWhitespace
		this._ignoreTrimWhitespace = true;
		if (typeof options.ignoreTrimWhitespace !== 'undefined') {
			this._ignoreTrimWhitespace = options.ignoreTrimWhitespace;
		}

275 276 277 278 279 280
		// renderIndicators
		this._renderIndicators = true;
		if (typeof options.renderIndicators !== 'undefined') {
			this._renderIndicators = options.renderIndicators;
		}

281 282 283 284 285
		this._originalIsEditable = false;
		if (typeof options.originalEditable !== 'undefined') {
			this._originalIsEditable = Boolean(options.originalEditable);
		}

286 287 288 289 290 291 292 293 294 295
		this._originalCodeLens = false;
		if (typeof options.originalCodeLens !== 'undefined') {
			this._originalCodeLens = Boolean(options.originalCodeLens);
		}

		this._modifiedCodeLens = false;
		if (typeof options.modifiedCodeLens !== 'undefined') {
			this._modifiedCodeLens = Boolean(options.modifiedCodeLens);
		}

A
Alex Dima 已提交
296
		this._updateDecorationsRunner = this._register(new RunOnceScheduler(() => this._updateDecorations(), 0));
E
Erich Gamma 已提交
297 298

		this._containerDomElement = document.createElement('div');
M
Martin Aeschlimann 已提交
299
		this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getColorTheme(), this._renderSideBySide);
E
Erich Gamma 已提交
300 301 302 303
		this._containerDomElement.style.position = 'relative';
		this._containerDomElement.style.height = '100%';
		this._domElement.appendChild(this._containerDomElement);

A
Alex Dima 已提交
304 305 306
		this._overviewViewportDomElement = createFastDomNode(document.createElement('div'));
		this._overviewViewportDomElement.setClassName('diffViewport');
		this._overviewViewportDomElement.setPosition('absolute');
E
Erich Gamma 已提交
307 308 309 310 311

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

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

314
		this._register(dom.addStandardDisposableListener(this._overviewDomElement, 'mousedown', (e) => {
E
Erich Gamma 已提交
315 316 317 318
			this.modifiedEditor.delegateVerticalScrollbarMouseDown(e);
		}));
		this._containerDomElement.appendChild(this._overviewDomElement);

A
Alex Dima 已提交
319 320 321 322 323 324 325 326 327 328 329 330 331
		// 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 已提交
332 333 334 335 336

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

337 338
		this._originalEditorState = new VisualEditorState(contextMenuService, clipboardService);
		this._modifiedEditorState = new VisualEditorState(contextMenuService, clipboardService);
E
Erich Gamma 已提交
339 340 341 342

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

343 344 345 346
		this._elementSizeObserver = this._register(new ElementSizeObserver(this._containerDomElement, undefined, () => this._onDidContainerSizeChanged()));
		if (options.automaticLayout) {
			this._elementSizeObserver.startObserving();
		}
E
Erich Gamma 已提交
347

A
Alex Dima 已提交
348
		this._diffComputationResult = null;
E
Erich Gamma 已提交
349

350 351
		const leftContextKeyService = this._contextKeyService.createScoped();
		leftContextKeyService.createKey('isInDiffLeftEditor', true);
J
Joao Moreno 已提交
352

353 354 355
		const leftServices = new ServiceCollection();
		leftServices.set(IContextKeyService, leftContextKeyService);
		const leftScopedInstantiationService = instantiationService.createChild(leftServices);
J
Joao Moreno 已提交
356

357 358 359 360 361 362 363
		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 已提交
364 365 366 367 368
		this.originalEditor = this._createLeftHandSideEditor(options, leftScopedInstantiationService);
		this.modifiedEditor = this._createRightHandSideEditor(options, rightScopedInstantiationService);

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

370 371 372
		this._reviewPane = new DiffReview(this);
		this._containerDomElement.appendChild(this._reviewPane.domNode.domNode);
		this._containerDomElement.appendChild(this._reviewPane.shadow.domNode);
373
		this._containerDomElement.appendChild(this._reviewPane.actionBarContainer.domNode);
374

375

E
Erich Gamma 已提交
376 377 378 379 380 381 382 383

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

		if (this._renderSideBySide) {
H
Howard Hung 已提交
384
			this._setStrategy(new DiffEditorWidgetSideBySide(this._createDataSource(), this._enableSplitViewResizing));
E
Erich Gamma 已提交
385
		} else {
H
Howard Hung 已提交
386
			this._setStrategy(new DiffEditorWidgetInline(this._createDataSource(), this._enableSplitViewResizing));
E
Erich Gamma 已提交
387
		}
388

M
Martin Aeschlimann 已提交
389
		this._register(themeService.onDidColorThemeChange(t => {
390 391 392
			if (this._strategy && this._strategy.applyColors(t)) {
				this._updateDecorationsRunner.schedule();
			}
M
Martin Aeschlimann 已提交
393
			this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getColorTheme(), this._renderSideBySide);
394
		}));
395

396 397
		const contributions: IDiffEditorContributionDescription[] = EditorExtensionsRegistry.getDiffEditorContributions();
		for (const desc of contributions) {
A
Alex Dima 已提交
398
			try {
399
				this._register(instantiationService.createInstance(desc.ctor, this));
A
Alex Dima 已提交
400 401 402 403 404
			} catch (err) {
				onUnexpectedError(err);
			}
		}

405
		this._codeEditorService.addDiffEditor(this);
E
Erich Gamma 已提交
406 407
	}

408 409 410 411 412 413 414 415
	public get ignoreTrimWhitespace(): boolean {
		return this._ignoreTrimWhitespace;
	}

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

416 417 418 419
	public get maxComputationTime(): number {
		return this._maxComputationTime;
	}

420 421 422 423
	public get renderIndicators(): boolean {
		return this._renderIndicators;
	}

424
	private _setState(newState: editorBrowser.DiffEditorState): void {
425
		if (this._state === newState) {
426 427 428
			return;
		}
		this._state = newState;
429 430 431 432 433 434 435 436 437

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

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

A
Alex Dima 已提交
440 441 442 443 444 445 446 447 448 449 450 451
	public hasWidgetFocus(): boolean {
		return dom.isAncestor(document.activeElement, this._domElement);
	}

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

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

M
Martin Aeschlimann 已提交
452
	private static _getClassName(theme: IColorTheme, renderSideBySide: boolean): string {
A
Alex Dima 已提交
453
		let result = 'monaco-diff-editor monaco-editor-background ';
E
Erich Gamma 已提交
454 455 456
		if (renderSideBySide) {
			result += 'side-by-side ';
		}
457
		result += getThemeTypeSelector(theme.type);
E
Erich Gamma 已提交
458 459 460 461 462 463 464 465
		return result;
	}

	private _recreateOverviewRulers(): void {
		if (this._originalOverviewRuler) {
			this._overviewDomElement.removeChild(this._originalOverviewRuler.getDomNode());
			this._originalOverviewRuler.dispose();
		}
A
Alex Dima 已提交
466 467 468 469
		if (this.originalEditor.hasModel()) {
			this._originalOverviewRuler = this.originalEditor.createOverviewRuler('original diffOverviewRuler')!;
			this._overviewDomElement.appendChild(this._originalOverviewRuler.getDomNode());
		}
E
Erich Gamma 已提交
470 471 472 473 474

		if (this._modifiedOverviewRuler) {
			this._overviewDomElement.removeChild(this._modifiedOverviewRuler.getDomNode());
			this._modifiedOverviewRuler.dispose();
		}
A
Alex Dima 已提交
475 476 477 478
		if (this.modifiedEditor.hasModel()) {
			this._modifiedOverviewRuler = this.modifiedEditor.createOverviewRuler('modified diffOverviewRuler')!;
			this._overviewDomElement.appendChild(this._modifiedOverviewRuler.getDomNode());
		}
E
Erich Gamma 已提交
479 480 481 482

		this._layoutOverviewRulers();
	}

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

A
Alex Dima 已提交
486
		this._register(editor.onDidScrollChange((e) => {
A
Alex Dima 已提交
487 488 489
			if (this._isHandlingScrollEvent) {
				return;
			}
490
			if (!e.scrollTopChanged && !e.scrollLeftChanged && !e.scrollHeightChanged) {
A
Alex Dima 已提交
491 492 493 494 495 496 497 498
				return;
			}
			this._isHandlingScrollEvent = true;
			this.modifiedEditor.setScrollPosition({
				scrollLeft: e.scrollLeft,
				scrollTop: e.scrollTop
			});
			this._isHandlingScrollEvent = false;
499 500

			this._layoutOverviewViewport();
A
Alex Dima 已提交
501 502
		}));

A
Alex Dima 已提交
503
		this._register(editor.onDidChangeViewZones(() => {
A
Alex Dima 已提交
504 505 506
			this._onViewZonesChanged();
		}));

A
Alex Dima 已提交
507
		this._register(editor.onDidChangeModelContent(() => {
A
Alex Dima 已提交
508 509 510 511
			if (this._isVisible) {
				this._beginUpdateDecorationsSoon();
			}
		}));
A
Alex Dima 已提交
512 513

		return editor;
E
Erich Gamma 已提交
514 515
	}

516
	private _createRightHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget {
517
		const editor = this._createInnerEditor(instantiationService, this._modifiedDomNode, this._adjustOptionsForRightHandSide(options, this._modifiedCodeLens));
A
Alex Dima 已提交
518

A
Alex Dima 已提交
519
		this._register(editor.onDidScrollChange((e) => {
A
Alex Dima 已提交
520 521 522
			if (this._isHandlingScrollEvent) {
				return;
			}
523
			if (!e.scrollTopChanged && !e.scrollLeftChanged && !e.scrollHeightChanged) {
A
Alex Dima 已提交
524 525 526 527 528 529 530 531 532 533 534 535
				return;
			}
			this._isHandlingScrollEvent = true;
			this.originalEditor.setScrollPosition({
				scrollLeft: e.scrollLeft,
				scrollTop: e.scrollTop
			});
			this._isHandlingScrollEvent = false;

			this._layoutOverviewViewport();
		}));

A
Alex Dima 已提交
536
		this._register(editor.onDidChangeViewZones(() => {
A
Alex Dima 已提交
537 538 539
			this._onViewZonesChanged();
		}));

A
Alex Dima 已提交
540
		this._register(editor.onDidChangeConfiguration((e) => {
541
			if (e.hasChanged(EditorOption.fontInfo) && editor.getModel()) {
A
Alex Dima 已提交
542 543 544 545
				this._onViewZonesChanged();
			}
		}));

A
Alex Dima 已提交
546
		this._register(editor.onDidChangeModelContent(() => {
A
Alex Dima 已提交
547 548 549 550
			if (this._isVisible) {
				this._beginUpdateDecorationsSoon();
			}
		}));
A
Alex Dima 已提交
551

552 553 554 555 556 557
		this._register(editor.onDidChangeModelOptions((e) => {
			if (e.tabSize) {
				this._updateDecorationsRunner.schedule();
			}
		}));

A
Alex Dima 已提交
558
		return editor;
E
Erich Gamma 已提交
559 560
	}

561
	protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditorWidget {
562
		return instantiationService.createInstance(CodeEditorWidget, container, options, {});
A
Alex Dima 已提交
563 564
	}

E
Erich Gamma 已提交
565
	public dispose(): void {
566 567
		this._codeEditorService.removeDiffEditor(this);

568 569 570 571 572
		if (this._beginUpdateDecorationsTimeout !== -1) {
			window.clearTimeout(this._beginUpdateDecorationsTimeout);
			this._beginUpdateDecorationsTimeout = -1;
		}

E
Erich Gamma 已提交
573 574
		this._cleanViewZonesAndDecorations();

575 576 577 578 579 580 581 582
		if (this._originalOverviewRuler) {
			this._overviewDomElement.removeChild(this._originalOverviewRuler.getDomNode());
			this._originalOverviewRuler.dispose();
		}
		if (this._modifiedOverviewRuler) {
			this._overviewDomElement.removeChild(this._modifiedOverviewRuler.getDomNode());
			this._modifiedOverviewRuler.dispose();
		}
583 584
		this._overviewDomElement.removeChild(this._overviewViewportDomElement.domNode);
		this._containerDomElement.removeChild(this._overviewDomElement);
E
Erich Gamma 已提交
585

586
		this._containerDomElement.removeChild(this._originalDomNode);
A
Alex Dima 已提交
587
		this.originalEditor.dispose();
588 589

		this._containerDomElement.removeChild(this._modifiedDomNode);
A
Alex Dima 已提交
590
		this.modifiedEditor.dispose();
E
Erich Gamma 已提交
591 592 593

		this._strategy.dispose();

594 595 596
		this._containerDomElement.removeChild(this._reviewPane.domNode.domNode);
		this._containerDomElement.removeChild(this._reviewPane.shadow.domNode);
		this._containerDomElement.removeChild(this._reviewPane.actionBarContainer.domNode);
597 598
		this._reviewPane.dispose();

599 600
		this._domElement.removeChild(this._containerDomElement);

A
Alex Dima 已提交
601
		this._onDidDispose.fire();
A
Alex Dima 已提交
602

E
Erich Gamma 已提交
603 604 605 606 607 608 609 610 611 612
		super.dispose();
	}

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

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

	public getEditorType(): string {
A
Alex Dima 已提交
613
		return editorCommon.EditorType.IDiffEditor;
E
Erich Gamma 已提交
614 615
	}

A
Alex Dima 已提交
616
	public getLineChanges(): editorCommon.ILineChange[] | null {
A
Alex Dima 已提交
617 618 619 620
		if (!this._diffComputationResult) {
			return null;
		}
		return this._diffComputationResult.changes;
E
Erich Gamma 已提交
621 622
	}

623 624 625 626
	public getDiffComputationResult(): IDiffComputationResult | null {
		return this._diffComputationResult;
	}

A
Alex Dima 已提交
627
	public getOriginalEditor(): editorBrowser.ICodeEditor {
E
Erich Gamma 已提交
628 629 630
		return this.originalEditor;
	}

A
Alex Dima 已提交
631
	public getModifiedEditor(): editorBrowser.ICodeEditor {
E
Erich Gamma 已提交
632 633 634
		return this.modifiedEditor;
	}

635
	public updateOptions(newOptions: IDiffEditorOptions): void {
E
Erich Gamma 已提交
636 637

		// Handle side by side
A
Alex Dima 已提交
638
		let renderSideBySideChanged = false;
E
Erich Gamma 已提交
639 640 641 642 643 644 645
		if (typeof newOptions.renderSideBySide !== 'undefined') {
			if (this._renderSideBySide !== newOptions.renderSideBySide) {
				this._renderSideBySide = newOptions.renderSideBySide;
				renderSideBySideChanged = true;
			}
		}

646 647
		if (typeof newOptions.maxComputationTime !== 'undefined') {
			this._maxComputationTime = newOptions.maxComputationTime;
648 649 650
			if (this._isVisible) {
				this._beginUpdateDecorationsSoon();
			}
651 652
		}

653 654
		let beginUpdateDecorations = false;

E
Erich Gamma 已提交
655 656 657 658
		if (typeof newOptions.ignoreTrimWhitespace !== 'undefined') {
			if (this._ignoreTrimWhitespace !== newOptions.ignoreTrimWhitespace) {
				this._ignoreTrimWhitespace = newOptions.ignoreTrimWhitespace;
				// Begin comparing
659 660 661 662 663 664 665 666
				beginUpdateDecorations = true;
			}
		}

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

670 671 672 673
		if (beginUpdateDecorations) {
			this._beginUpdateDecorations();
		}

674 675 676
		if (typeof newOptions.originalEditable !== 'undefined') {
			this._originalIsEditable = Boolean(newOptions.originalEditable);
		}
677 678 679 680 681 682
		if (typeof newOptions.originalCodeLens !== 'undefined') {
			this._originalCodeLens = Boolean(newOptions.originalCodeLens);
		}
		if (typeof newOptions.modifiedCodeLens !== 'undefined') {
			this._modifiedCodeLens = Boolean(newOptions.modifiedCodeLens);
		}
683

684 685
		this.modifiedEditor.updateOptions(this._adjustOptionsForRightHandSide(newOptions, this._modifiedCodeLens));
		this.originalEditor.updateOptions(this._adjustOptionsForLeftHandSide(newOptions, this._originalIsEditable, this._originalCodeLens));
E
Erich Gamma 已提交
686 687 688 689 690 691 692 693 694 695

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

		// renderSideBySide
		if (renderSideBySideChanged) {
			if (this._renderSideBySide) {
H
Howard Hung 已提交
696
				this._setStrategy(new DiffEditorWidgetSideBySide(this._createDataSource(), this._enableSplitViewResizing));
E
Erich Gamma 已提交
697
			} else {
H
Howard Hung 已提交
698
				this._setStrategy(new DiffEditorWidgetInline(this._createDataSource(), this._enableSplitViewResizing));
E
Erich Gamma 已提交
699
			}
700
			// Update class name
M
Martin Aeschlimann 已提交
701
			this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getColorTheme(), this._renderSideBySide);
E
Erich Gamma 已提交
702 703 704
		}
	}

A
Alex Dima 已提交
705
	public getModel(): editorCommon.IDiffEditorModel {
E
Erich Gamma 已提交
706
		return {
A
Alex Dima 已提交
707 708
			original: this.originalEditor.getModel()!,
			modified: this.modifiedEditor.getModel()!
E
Erich Gamma 已提交
709 710 711
		};
	}

J
Johannes Rieken 已提交
712
	public setModel(model: editorCommon.IDiffEditorModel): void {
E
Erich Gamma 已提交
713 714 715 716 717 718 719 720 721 722 723 724 725
		// 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();

726 727
		// this.originalEditor.onDidChangeModelOptions

E
Erich Gamma 已提交
728 729 730 731 732 733
		if (model) {
			this.originalEditor.setScrollTop(0);
			this.modifiedEditor.setScrollTop(0);
		}

		// Disable any diff computations that will come in
A
Alex Dima 已提交
734
		this._diffComputationResult = null;
E
Erich Gamma 已提交
735
		this._diffComputationToken++;
736
		this._setState(editorBrowser.DiffEditorState.Idle);
E
Erich Gamma 已提交
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751

		if (model) {
			this._recreateOverviewRulers();

			// Begin comparing
			this._beginUpdateDecorations();
		}

		this._layoutOverviewViewport();
	}

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

A
Alex Dima 已提交
752
	public getVisibleColumnFromPosition(position: IPosition): number {
E
Erich Gamma 已提交
753 754 755
		return this.modifiedEditor.getVisibleColumnFromPosition(position);
	}

756 757 758 759
	public getStatusbarColumn(position: IPosition): number {
		return this.modifiedEditor.getStatusbarColumn(position);
	}

A
Alex Dima 已提交
760
	public getPosition(): Position | null {
E
Erich Gamma 已提交
761 762 763
		return this.modifiedEditor.getPosition();
	}

764 765
	public setPosition(position: IPosition): void {
		this.modifiedEditor.setPosition(position);
E
Erich Gamma 已提交
766 767
	}

768 769
	public revealLine(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLine(lineNumber, scrollType);
E
Erich Gamma 已提交
770 771
	}

772 773
	public revealLineInCenter(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLineInCenter(lineNumber, scrollType);
E
Erich Gamma 已提交
774 775
	}

776 777
	public revealLineInCenterIfOutsideViewport(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLineInCenterIfOutsideViewport(lineNumber, scrollType);
E
Erich Gamma 已提交
778 779
	}

780 781
	public revealLineNearTop(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLineNearTop(lineNumber, scrollType);
782 783
	}

784 785
	public revealPosition(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealPosition(position, scrollType);
E
Erich Gamma 已提交
786 787
	}

788 789
	public revealPositionInCenter(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealPositionInCenter(position, scrollType);
E
Erich Gamma 已提交
790 791
	}

792 793
	public revealPositionInCenterIfOutsideViewport(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealPositionInCenterIfOutsideViewport(position, scrollType);
E
Erich Gamma 已提交
794 795
	}

796 797
	public revealPositionNearTop(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealPositionNearTop(position, scrollType);
798 799
	}

A
Alex Dima 已提交
800
	public getSelection(): Selection | null {
E
Erich Gamma 已提交
801 802 803
		return this.modifiedEditor.getSelection();
	}

A
Alex Dima 已提交
804
	public getSelections(): Selection[] | null {
E
Erich Gamma 已提交
805 806 807
		return this.modifiedEditor.getSelections();
	}

808 809 810 811 812 813
	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 已提交
814 815
	}

816
	public setSelections(ranges: readonly ISelection[]): void {
E
Erich Gamma 已提交
817 818 819
		this.modifiedEditor.setSelections(ranges);
	}

820 821
	public revealLines(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLines(startLineNumber, endLineNumber, scrollType);
E
Erich Gamma 已提交
822 823
	}

824 825
	public revealLinesInCenter(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLinesInCenter(startLineNumber, endLineNumber, scrollType);
E
Erich Gamma 已提交
826 827
	}

828 829
	public revealLinesInCenterIfOutsideViewport(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLinesInCenterIfOutsideViewport(startLineNumber, endLineNumber, scrollType);
E
Erich Gamma 已提交
830 831
	}

832 833
	public revealLinesNearTop(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealLinesNearTop(startLineNumber, endLineNumber, scrollType);
834 835
	}

836 837
	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 已提交
838 839
	}

840 841
	public revealRangeInCenter(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealRangeInCenter(range, scrollType);
E
Erich Gamma 已提交
842 843
	}

844 845
	public revealRangeInCenterIfOutsideViewport(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealRangeInCenterIfOutsideViewport(range, scrollType);
E
Erich Gamma 已提交
846 847
	}

848 849
	public revealRangeNearTop(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealRangeNearTop(range, scrollType);
850 851
	}

852 853 854 855
	public revealRangeNearTopIfOutsideViewport(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealRangeNearTopIfOutsideViewport(range, scrollType);
	}

856 857
	public revealRangeAtTop(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this.modifiedEditor.revealRangeAtTop(range, scrollType);
858 859
	}

A
Alex Dima 已提交
860
	public getSupportedActions(): editorCommon.IEditorAction[] {
861 862 863
		return this.modifiedEditor.getSupportedActions();
	}

A
Alex Dima 已提交
864
	public saveViewState(): editorCommon.IDiffEditorViewState {
A
Alex Dima 已提交
865 866
		let originalViewState = this.originalEditor.saveViewState();
		let modifiedViewState = this.modifiedEditor.saveViewState();
E
Erich Gamma 已提交
867 868 869 870 871 872
		return {
			original: originalViewState,
			modified: modifiedViewState
		};
	}

A
Alex Dima 已提交
873
	public restoreViewState(s: editorCommon.IDiffEditorViewState): void {
A
Alex Dima 已提交
874
		if (s.original && s.modified) {
A
Alex Dima 已提交
875
			let diffEditorState = <editorCommon.IDiffEditorViewState>s;
E
Erich Gamma 已提交
876 877 878 879 880
			this.originalEditor.restoreViewState(diffEditorState.original);
			this.modifiedEditor.restoreViewState(diffEditorState.modified);
		}
	}

J
Johannes Rieken 已提交
881
	public layout(dimension?: editorCommon.IDimension): void {
882
		this._elementSizeObserver.observe(dimension);
E
Erich Gamma 已提交
883 884 885 886 887 888
	}

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

A
Alex Dima 已提交
889 890
	public hasTextFocus(): boolean {
		return this.originalEditor.hasTextFocus() || this.modifiedEditor.hasTextFocus();
E
Erich Gamma 已提交
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
	}

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

A
Alex Dima 已提交
909
	public trigger(source: string | null | undefined, handlerId: string, payload: any): void {
E
Erich Gamma 已提交
910 911 912
		this.modifiedEditor.trigger(source, handlerId, payload);
	}

913
	public changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any {
E
Erich Gamma 已提交
914 915 916 917 918 919 920 921 922
		return this.modifiedEditor.changeDecorations(callback);
	}

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



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

923
	private _onDidContainerSizeChanged(): void {
E
Erich Gamma 已提交
924 925 926
		this._doLayout();
	}

927 928 929 930
	private _getReviewHeight(): number {
		return this._reviewPane.isVisible() ? this._elementSizeObserver.getHeight() : 0;
	}

E
Erich Gamma 已提交
931
	private _layoutOverviewRulers(): void {
A
Alex Dima 已提交
932 933 934
		if (!this._originalOverviewRuler || !this._modifiedOverviewRuler) {
			return;
		}
935 936 937
		const height = this._elementSizeObserver.getHeight();
		const reviewHeight = this._getReviewHeight();

A
Alex Dima 已提交
938 939
		let freeSpace = DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH - 2 * DiffEditorWidget.ONE_OVERVIEW_WIDTH;
		let layoutInfo = this.modifiedEditor.getLayoutInfo();
E
Erich Gamma 已提交
940
		if (layoutInfo) {
A
Alex Dima 已提交
941
			this._originalOverviewRuler.setLayout({
E
Erich Gamma 已提交
942 943 944
				top: 0,
				width: DiffEditorWidget.ONE_OVERVIEW_WIDTH,
				right: freeSpace + DiffEditorWidget.ONE_OVERVIEW_WIDTH,
945
				height: (height - reviewHeight)
A
Alex Dima 已提交
946 947
			});
			this._modifiedOverviewRuler.setLayout({
E
Erich Gamma 已提交
948 949 950
				top: 0,
				right: 0,
				width: DiffEditorWidget.ONE_OVERVIEW_WIDTH,
951
				height: (height - reviewHeight)
A
Alex Dima 已提交
952
			});
E
Erich Gamma 已提交
953 954 955 956 957 958 959 960 961 962 963 964
		}
	}

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

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

A
Alex Dima 已提交
965 966 967 968 969 970 971 972 973
	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);
	}

974 975
	private _lastOriginalWarning: URI | null = null;
	private _lastModifiedWarning: URI | null = null;
976

A
Alex Dima 已提交
977
	private static _equals(a: URI | null, b: URI | null): boolean {
978 979 980 981 982 983 984 985 986
		if (!a && !b) {
			return true;
		}
		if (!a || !b) {
			return false;
		}
		return (a.toString() === b.toString());
	}

E
Erich Gamma 已提交
987 988
	private _beginUpdateDecorations(): void {
		this._beginUpdateDecorationsTimeout = -1;
989 990 991
		const currentOriginalModel = this.originalEditor.getModel();
		const currentModifiedModel = this.modifiedEditor.getModel();
		if (!currentOriginalModel || !currentModifiedModel) {
E
Erich Gamma 已提交
992 993 994 995 996 997 998
			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 已提交
999
		let currentToken = this._diffComputationToken;
1000
		this._setState(editorBrowser.DiffEditorState.ComputingDiff);
E
Erich Gamma 已提交
1001

1002 1003 1004 1005 1006 1007 1008
		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;
1009
				this._notificationService.warn(nls.localize("diff.tooLarge", "Cannot compare files because one file is too large."));
1010 1011 1012 1013
			}
			return;
		}

1014
		this._editorWorkerService.computeDiff(currentOriginalModel.uri, currentModifiedModel.uri, this._ignoreTrimWhitespace, this._maxComputationTime).then((result) => {
1015 1016 1017
			if (currentToken === this._diffComputationToken
				&& currentOriginalModel === this.originalEditor.getModel()
				&& currentModifiedModel === this.modifiedEditor.getModel()
J
Johannes Rieken 已提交
1018
			) {
1019
				this._setState(editorBrowser.DiffEditorState.DiffComputed);
A
Alex Dima 已提交
1020
				this._diffComputationResult = result;
1021
				this._updateDecorationsRunner.schedule();
A
Alex Dima 已提交
1022
				this._onDidUpdateDiff.fire();
1023 1024 1025 1026 1027
			}
		}, (error) => {
			if (currentToken === this._diffComputationToken
				&& currentOriginalModel === this.originalEditor.getModel()
				&& currentModifiedModel === this.modifiedEditor.getModel()
J
Johannes Rieken 已提交
1028
			) {
1029
				this._setState(editorBrowser.DiffEditorState.DiffComputed);
A
Alex Dima 已提交
1030
				this._diffComputationResult = null;
E
Erich Gamma 已提交
1031 1032
				this._updateDecorationsRunner.schedule();
			}
1033
		});
E
Erich Gamma 已提交
1034 1035 1036 1037 1038 1039 1040 1041
	}

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

	private _updateDecorations(): void {
A
Alex Dima 已提交
1042
		if (!this.originalEditor.getModel() || !this.modifiedEditor.getModel() || !this._originalOverviewRuler || !this._modifiedOverviewRuler) {
1043 1044
			return;
		}
A
Alex Dima 已提交
1045
		const lineChanges = (this._diffComputationResult ? this._diffComputationResult.changes : []);
E
Erich Gamma 已提交
1046

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

1050
		let diffDecorations = this._strategy.getEditorsDiffDecorations(lineChanges, this._ignoreTrimWhitespace, this._renderIndicators, foreignOriginal, foreignModified, this.originalEditor, this.modifiedEditor);
E
Erich Gamma 已提交
1051 1052 1053

		try {
			this._currentlyChangingViewZones = true;
A
Alex Dima 已提交
1054 1055
			this._originalEditorState.apply(this.originalEditor, this._originalOverviewRuler, diffDecorations.original, false);
			this._modifiedEditorState.apply(this.modifiedEditor, this._modifiedOverviewRuler, diffDecorations.modified, true);
E
Erich Gamma 已提交
1056 1057 1058 1059 1060
		} finally {
			this._currentlyChangingViewZones = false;
		}
	}

1061 1062
	private _adjustOptionsForSubEditor(options: IDiffEditorOptions): IDiffEditorOptions {
		let clonedOptions: IDiffEditorOptions = objects.deepClone(options || {});
A
Alex Dima 已提交
1063
		clonedOptions.inDiffEditor = true;
1064
		clonedOptions.wordWrap = 'off';
1065
		clonedOptions.wordWrapMinified = false;
E
Erich Gamma 已提交
1066 1067 1068
		clonedOptions.automaticLayout = false;
		clonedOptions.scrollbar = clonedOptions.scrollbar || {};
		clonedOptions.scrollbar.vertical = 'visible';
A
Alex Dima 已提交
1069
		clonedOptions.folding = false;
1070
		clonedOptions.codeLens = false;
J
Joao Moreno 已提交
1071
		clonedOptions.fixedOverflowWidgets = true;
1072
		// clonedOptions.lineDecorationsWidth = '2ch';
1073 1074 1075
		if (!clonedOptions.minimap) {
			clonedOptions.minimap = {};
		}
1076
		clonedOptions.minimap.enabled = false;
E
Erich Gamma 已提交
1077 1078 1079
		return clonedOptions;
	}

1080
	private _adjustOptionsForLeftHandSide(options: IDiffEditorOptions, isEditable: boolean, isCodeLensEnabled: boolean): IEditorOptions {
1081
		let result = this._adjustOptionsForSubEditor(options);
1082 1083 1084
		if (isCodeLensEnabled) {
			result.codeLens = true;
		}
1085
		result.readOnly = !isEditable;
1086
		result.extraEditorClassName = 'original-in-monaco-diff-editor';
1087 1088 1089
		return result;
	}

1090
	private _adjustOptionsForRightHandSide(options: IDiffEditorOptions, isCodeLensEnabled: boolean): IEditorOptions {
1091
		let result = this._adjustOptionsForSubEditor(options);
1092 1093 1094
		if (isCodeLensEnabled) {
			result.codeLens = true;
		}
A
Alex Dima 已提交
1095
		result.revealHorizontalRightPadding = EditorOptions.revealHorizontalRightPadding.defaultValue + DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH;
A
Alex Dima 已提交
1096
		result.scrollbar!.verticalHasArrows = false;
1097
		result.extraEditorClassName = 'modified-in-monaco-diff-editor';
1098
		return result;
E
Erich Gamma 已提交
1099 1100
	}

1101
	public doLayout(): void {
1102 1103
		this._elementSizeObserver.observe();
		this._doLayout();
1104 1105
	}

E
Erich Gamma 已提交
1106
	private _doLayout(): void {
1107 1108 1109 1110
		const width = this._elementSizeObserver.getWidth();
		const height = this._elementSizeObserver.getHeight();
		const reviewHeight = this._getReviewHeight();

A
Alex Dima 已提交
1111
		let splitPoint = this._strategy.layout();
E
Erich Gamma 已提交
1112 1113 1114 1115

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

1116
		this._modifiedDomNode.style.width = (width - splitPoint) + 'px';
E
Erich Gamma 已提交
1117 1118 1119
		this._modifiedDomNode.style.left = splitPoint + 'px';

		this._overviewDomElement.style.top = '0px';
1120
		this._overviewDomElement.style.height = (height - reviewHeight) + 'px';
E
Erich Gamma 已提交
1121
		this._overviewDomElement.style.width = DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH + 'px';
1122
		this._overviewDomElement.style.left = (width - DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH) + 'px';
A
Alex Dima 已提交
1123 1124
		this._overviewViewportDomElement.setWidth(DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH);
		this._overviewViewportDomElement.setHeight(30);
E
Erich Gamma 已提交
1125

1126 1127
		this.originalEditor.layout({ width: splitPoint, height: (height - reviewHeight) });
		this.modifiedEditor.layout({ width: width - splitPoint - DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH, height: (height - reviewHeight) });
E
Erich Gamma 已提交
1128 1129 1130 1131 1132

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

1133
		this._reviewPane.layout(height - reviewHeight, width, reviewHeight);
A
Alex Dima 已提交
1134

E
Erich Gamma 已提交
1135 1136 1137 1138
		this._layoutOverviewViewport();
	}

	private _layoutOverviewViewport(): void {
A
Alex Dima 已提交
1139
		let layout = this._computeOverviewViewport();
E
Erich Gamma 已提交
1140
		if (!layout) {
A
Alex Dima 已提交
1141 1142
			this._overviewViewportDomElement.setTop(0);
			this._overviewViewportDomElement.setHeight(0);
E
Erich Gamma 已提交
1143
		} else {
A
Alex Dima 已提交
1144 1145
			this._overviewViewportDomElement.setTop(layout.top);
			this._overviewViewportDomElement.setHeight(layout.height);
E
Erich Gamma 已提交
1146 1147 1148
		}
	}

A
Alex Dima 已提交
1149
	private _computeOverviewViewport(): { height: number; top: number; } | null {
A
Alex Dima 已提交
1150
		let layoutInfo = this.modifiedEditor.getLayoutInfo();
E
Erich Gamma 已提交
1151 1152 1153 1154
		if (!layoutInfo) {
			return null;
		}

A
Alex Dima 已提交
1155 1156
		let scrollTop = this.modifiedEditor.getScrollTop();
		let scrollHeight = this.modifiedEditor.getScrollHeight();
E
Erich Gamma 已提交
1157

1158
		let computedAvailableSize = Math.max(0, layoutInfo.height);
A
Alex Dima 已提交
1159 1160
		let computedRepresentableSize = Math.max(0, computedAvailableSize - 2 * 0);
		let computedRatio = scrollHeight > 0 ? (computedRepresentableSize / scrollHeight) : 0;
E
Erich Gamma 已提交
1161

1162
		let computedSliderSize = Math.max(0, Math.floor(layoutInfo.height * computedRatio));
A
Alex Dima 已提交
1163
		let computedSliderPosition = Math.floor(scrollTop * computedRatio);
E
Erich Gamma 已提交
1164 1165 1166 1167 1168 1169 1170

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

J
Johannes Rieken 已提交
1171
	private _createDataSource(): IDataSource {
E
Erich Gamma 已提交
1172 1173
		return {
			getWidth: () => {
1174
				return this._elementSizeObserver.getWidth();
E
Erich Gamma 已提交
1175 1176 1177
			},

			getHeight: () => {
1178
				return (this._elementSizeObserver.getHeight() - this._getReviewHeight());
E
Erich Gamma 已提交
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
			},

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

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

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

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

J
Johannes Rieken 已提交
1199
	private _setStrategy(newStrategy: IDiffEditorWidgetStyle): void {
E
Erich Gamma 已提交
1200 1201 1202 1203 1204
		if (this._strategy) {
			this._strategy.dispose();
		}

		this._strategy = newStrategy;
M
Martin Aeschlimann 已提交
1205
		newStrategy.applyColors(this._themeService.getColorTheme());
E
Erich Gamma 已提交
1206

A
Alex Dima 已提交
1207
		if (this._diffComputationResult) {
E
Erich Gamma 已提交
1208 1209 1210 1211
			this._updateDecorations();
		}

		// Just do a layout, the strategy might need it
1212
		this._doLayout();
E
Erich Gamma 已提交
1213 1214
	}

A
Alex Dima 已提交
1215
	private _getLineChangeAtOrBeforeLineNumber(lineNumber: number, startLineNumberExtractor: (lineChange: editorCommon.ILineChange) => number): editorCommon.ILineChange | null {
A
Alex Dima 已提交
1216 1217
		const lineChanges = (this._diffComputationResult ? this._diffComputationResult.changes : []);
		if (lineChanges.length === 0 || lineNumber < startLineNumberExtractor(lineChanges[0])) {
E
Erich Gamma 已提交
1218 1219 1220 1221
			// There are no changes or `lineNumber` is before the first change
			return null;
		}

A
Alex Dima 已提交
1222
		let min = 0, max = lineChanges.length - 1;
E
Erich Gamma 已提交
1223
		while (min < max) {
A
Alex Dima 已提交
1224
			let mid = Math.floor((min + max) / 2);
A
Alex Dima 已提交
1225
			let midStart = startLineNumberExtractor(lineChanges[mid]);
1226
			let midEnd = (mid + 1 <= max ? startLineNumberExtractor(lineChanges[mid + 1]) : Constants.MAX_SAFE_SMALL_INTEGER);
E
Erich Gamma 已提交
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237

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

	private _getEquivalentLineForOriginalLineNumber(lineNumber: number): number {
A
Alex Dima 已提交
1242
		let lineChange = this._getLineChangeAtOrBeforeLineNumber(lineNumber, (lineChange) => lineChange.originalStartLineNumber);
E
Erich Gamma 已提交
1243 1244 1245 1246 1247

		if (!lineChange) {
			return lineNumber;
		}

A
Alex Dima 已提交
1248 1249 1250 1251
		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 已提交
1252 1253


A
Alex Dima 已提交
1254
		let delta = lineNumber - originalEquivalentLineNumber;
E
Erich Gamma 已提交
1255 1256 1257 1258 1259

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

J
Johannes Rieken 已提交
1260
		return modifiedEquivalentLineNumber + lineChangeModifiedLength - lineChangeOriginalLength + delta;
E
Erich Gamma 已提交
1261 1262 1263
	}

	private _getEquivalentLineForModifiedLineNumber(lineNumber: number): number {
A
Alex Dima 已提交
1264
		let lineChange = this._getLineChangeAtOrBeforeLineNumber(lineNumber, (lineChange) => lineChange.modifiedStartLineNumber);
E
Erich Gamma 已提交
1265 1266 1267 1268 1269

		if (!lineChange) {
			return lineNumber;
		}

A
Alex Dima 已提交
1270 1271 1272 1273
		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 已提交
1274 1275


A
Alex Dima 已提交
1276
		let delta = lineNumber - modifiedEquivalentLineNumber;
E
Erich Gamma 已提交
1277 1278 1279 1280 1281

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

J
Johannes Rieken 已提交
1282
		return originalEquivalentLineNumber + lineChangeOriginalLength - lineChangeModifiedLength + delta;
E
Erich Gamma 已提交
1283 1284
	}

A
Alex Dima 已提交
1285
	public getDiffLineInformationForOriginal(lineNumber: number): editorBrowser.IDiffLineInformation | null {
A
Alex Dima 已提交
1286
		if (!this._diffComputationResult) {
E
Erich Gamma 已提交
1287 1288 1289 1290 1291 1292 1293 1294
			// Cannot answer that which I don't know
			return null;
		}
		return {
			equivalentLineNumber: this._getEquivalentLineForOriginalLineNumber(lineNumber)
		};
	}

A
Alex Dima 已提交
1295
	public getDiffLineInformationForModified(lineNumber: number): editorBrowser.IDiffLineInformation | null {
A
Alex Dima 已提交
1296
		if (!this._diffComputationResult) {
E
Erich Gamma 已提交
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
			// 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 已提交
1312 1313
	getOriginalEditor(): editorBrowser.ICodeEditor;
	getModifiedEditor(): editorBrowser.ICodeEditor;
E
Erich Gamma 已提交
1314 1315
}

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

J
Johannes Rieken 已提交
1318
	_dataSource: IDataSource;
A
Alex Dima 已提交
1319 1320
	_insertColor: Color | null;
	_removeColor: Color | null;
E
Erich Gamma 已提交
1321

J
Johannes Rieken 已提交
1322
	constructor(dataSource: IDataSource) {
A
Alex Dima 已提交
1323
		super();
E
Erich Gamma 已提交
1324
		this._dataSource = dataSource;
A
Alex Dima 已提交
1325 1326
		this._insertColor = null;
		this._removeColor = null;
E
Erich Gamma 已提交
1327 1328
	}

M
Martin Aeschlimann 已提交
1329
	public applyColors(theme: IColorTheme): boolean {
1330 1331 1332 1333 1334 1335 1336 1337
		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
Alex Dima 已提交
1338
	public getEditorsDiffDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalWhitespaces: IEditorWhitespace[], modifiedWhitespaces: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorsDiffDecorationsWithZones {
E
Erich Gamma 已提交
1339 1340 1341 1342 1343 1344 1345
		// Get view zones
		modifiedWhitespaces = modifiedWhitespaces.sort((a, b) => {
			return a.afterLineNumber - b.afterLineNumber;
		});
		originalWhitespaces = originalWhitespaces.sort((a, b) => {
			return a.afterLineNumber - b.afterLineNumber;
		});
1346
		let zones = this._getViewZones(lineChanges, originalWhitespaces, modifiedWhitespaces, originalEditor, modifiedEditor, renderIndicators);
E
Erich Gamma 已提交
1347 1348

		// Get decorations & overview ruler zones
1349 1350
		let originalDecorations = this._getOriginalEditorDecorations(lineChanges, ignoreTrimWhitespace, renderIndicators, originalEditor, modifiedEditor);
		let modifiedDecorations = this._getModifiedEditorDecorations(lineChanges, ignoreTrimWhitespace, renderIndicators, originalEditor, modifiedEditor);
E
Erich Gamma 已提交
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365

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

1366 1367 1368
	protected abstract _getViewZones(lineChanges: editorCommon.ILineChange[], originalForeignVZ: IEditorWhitespace[], modifiedForeignVZ: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor, renderIndicators: boolean): IEditorsZones;
	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 已提交
1369 1370 1371

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

A
Alex Dima 已提交
1374
interface IMyViewZone {
E
Erich Gamma 已提交
1375
	shouldNotShrink?: boolean;
A
Alex Dima 已提交
1376 1377 1378 1379 1380
	afterLineNumber: number;
	heightInLines: number;
	minWidthInPx?: number;
	domNode: HTMLElement | null;
	marginDomNode?: HTMLElement | null;
1381
	diff?: IDiffLinesChange;
E
Erich Gamma 已提交
1382 1383 1384 1385 1386
}

class ForeignViewZonesIterator {

	private _index: number;
1387
	private readonly _source: IEditorWhitespace[];
A
Alex Dima 已提交
1388
	public current: IEditorWhitespace | null;
E
Erich Gamma 已提交
1389

A
Alex Dima 已提交
1390
	constructor(source: IEditorWhitespace[]) {
E
Erich Gamma 已提交
1391 1392
		this._source = source;
		this._index = -1;
A
Alex Dima 已提交
1393
		this.current = null;
E
Erich Gamma 已提交
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406
		this.advance();
	}

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

1407
abstract class ViewZonesComputer {
E
Erich Gamma 已提交
1408

1409 1410
	private readonly lineChanges: editorCommon.ILineChange[];
	private readonly originalForeignVZ: IEditorWhitespace[];
1411
	private readonly originalLineHeight: number;
1412
	private readonly modifiedForeignVZ: IEditorWhitespace[];
1413
	private readonly modifiedLineHeight: number;
E
Erich Gamma 已提交
1414

1415
	constructor(lineChanges: editorCommon.ILineChange[], originalForeignVZ: IEditorWhitespace[], originalLineHeight: number, modifiedForeignVZ: IEditorWhitespace[], modifiedLineHeight: number) {
E
Erich Gamma 已提交
1416 1417
		this.lineChanges = lineChanges;
		this.originalForeignVZ = originalForeignVZ;
1418
		this.originalLineHeight = originalLineHeight;
E
Erich Gamma 已提交
1419
		this.modifiedForeignVZ = modifiedForeignVZ;
1420
		this.modifiedLineHeight = modifiedLineHeight;
E
Erich Gamma 已提交
1421 1422 1423
	}

	public getViewZones(): IEditorsZones {
A
Alex Dima 已提交
1424
		let result: { original: IMyViewZone[]; modified: IMyViewZone[]; } = {
E
Erich Gamma 已提交
1425 1426 1427 1428
			original: [],
			modified: []
		};

A
Alex Dima 已提交
1429 1430 1431 1432 1433 1434 1435 1436
		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 已提交
1437 1438 1439
			return a.afterLineNumber - b.afterLineNumber;
		};

A
Alex Dima 已提交
1440
		let addAndCombineIfPossible = (destination: IMyViewZone[], item: IMyViewZone) => {
E
Erich Gamma 已提交
1441
			if (item.domNode === null && destination.length > 0) {
A
Alex Dima 已提交
1442
				let lastItem = destination[destination.length - 1];
E
Erich Gamma 已提交
1443 1444 1445 1446 1447 1448 1449 1450
				if (lastItem.afterLineNumber === item.afterLineNumber && lastItem.domNode === null) {
					lastItem.heightInLines += item.heightInLines;
					return;
				}
			}
			destination.push(item);
		};

A
Alex Dima 已提交
1451 1452
		let modifiedForeignVZ = new ForeignViewZonesIterator(this.modifiedForeignVZ);
		let originalForeignVZ = new ForeignViewZonesIterator(this.originalForeignVZ);
E
Erich Gamma 已提交
1453 1454

		// 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 已提交
1455 1456
		for (let i = 0, length = this.lineChanges.length; i <= length; i++) {
			let lineChange = (i < length ? this.lineChanges[i] : null);
E
Erich Gamma 已提交
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473

			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 已提交
1474 1475
			let stepOriginal: IMyViewZone[] = [];
			let stepModified: IMyViewZone[] = [];
E
Erich Gamma 已提交
1476 1477 1478 1479 1480

			// ---------------------------- 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 已提交
1481
				let viewZoneLineNumber: number;
E
Erich Gamma 已提交
1482 1483 1484 1485 1486
				if (modifiedForeignVZ.current.afterLineNumber <= modifiedEquivalentLineNumber) {
					viewZoneLineNumber = originalEquivalentLineNumber - modifiedEquivalentLineNumber + modifiedForeignVZ.current.afterLineNumber;
				} else {
					viewZoneLineNumber = originalEndEquivalentLineNumber;
				}
A
Alex Dima 已提交
1487

1488
				let marginDomNode: HTMLDivElement | null = null;
A
Alex Dima 已提交
1489 1490 1491 1492
				if (lineChange && lineChange.modifiedStartLineNumber <= modifiedForeignVZ.current.afterLineNumber && modifiedForeignVZ.current.afterLineNumber <= lineChange.modifiedEndLineNumber) {
					marginDomNode = this._createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion();
				}

E
Erich Gamma 已提交
1493 1494
				stepOriginal.push({
					afterLineNumber: viewZoneLineNumber,
1495
					heightInLines: modifiedForeignVZ.current.height / this.modifiedLineHeight,
A
Alex Dima 已提交
1496 1497
					domNode: null,
					marginDomNode: marginDomNode
E
Erich Gamma 已提交
1498 1499 1500 1501 1502 1503
				});
				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 已提交
1504
				let viewZoneLineNumber: number;
E
Erich Gamma 已提交
1505 1506 1507 1508 1509 1510 1511
				if (originalForeignVZ.current.afterLineNumber <= originalEquivalentLineNumber) {
					viewZoneLineNumber = modifiedEquivalentLineNumber - originalEquivalentLineNumber + originalForeignVZ.current.afterLineNumber;
				} else {
					viewZoneLineNumber = modifiedEndEquivalentLineNumber;
				}
				stepModified.push({
					afterLineNumber: viewZoneLineNumber,
1512
					heightInLines: originalForeignVZ.current.height / this.originalLineHeight,
E
Erich Gamma 已提交
1513 1514 1515 1516 1517 1518
					domNode: null
				});
				originalForeignVZ.advance();
			}

			if (lineChange !== null && isChangeOrInsert(lineChange)) {
A
Alex Dima 已提交
1519
				let r = this._produceOriginalFromDiff(lineChange, lineChangeOriginalLength, lineChangeModifiedLength);
E
Erich Gamma 已提交
1520 1521 1522 1523 1524 1525
				if (r) {
					stepOriginal.push(r);
				}
			}

			if (lineChange !== null && isChangeOrDelete(lineChange)) {
A
Alex Dima 已提交
1526
				let r = this._produceModifiedFromDiff(lineChange, lineChangeOriginalLength, lineChangeModifiedLength);
E
Erich Gamma 已提交
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
				if (r) {
					stepModified.push(r);
				}
			}

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


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

			// [CANCEL & EMIT] Try to cancel view zones out
A
Alex Dima 已提交
1538 1539
			let stepOriginalIndex = 0;
			let stepModifiedIndex = 0;
E
Erich Gamma 已提交
1540 1541 1542 1543 1544

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

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

A
Alex Dima 已提交
1548 1549
				let originalDelta = original.afterLineNumber - originalEquivalentLineNumber;
				let modifiedDelta = modified.afterLineNumber - modifiedEquivalentLineNumber;
E
Erich Gamma 已提交
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590

				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 已提交
1591 1592 1593 1594 1595 1596
		return {
			original: ViewZonesComputer._ensureDomNodes(result.original),
			modified: ViewZonesComputer._ensureDomNodes(result.modified),
		};
	}

1597
	private static _ensureDomNodes(zones: IMyViewZone[]): IMyViewZone[] {
A
Alex Dima 已提交
1598
		return zones.map((z) => {
E
Erich Gamma 已提交
1599 1600 1601
			if (!z.domNode) {
				z.domNode = createFakeLinesDiv();
			}
1602
			return z;
A
Alex Dima 已提交
1603
		});
E
Erich Gamma 已提交
1604 1605
	}

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

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

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

R
rebornix 已提交
1613
export function createDecoration(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number, options: ModelDecorationOptions) {
1614 1615 1616 1617 1618 1619
	return {
		range: new Range(startLineNumber, startColumn, endLineNumber, endColumn),
		options: options
	};
}

R
rebornix 已提交
1620
export const DECORATIONS = {
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644

	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',
M
Martin Aeschlimann 已提交
1645
		linesDecorationsClassName: 'insert-sign ' + diffInsertIcon.classNames,
1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656
		marginClassName: 'line-insert',
		isWholeLine: true
	}),

	lineDelete: ModelDecorationOptions.register({
		className: 'line-delete',
		marginClassName: 'line-delete',
		isWholeLine: true
	}),
	lineDeleteWithSign: ModelDecorationOptions.register({
		className: 'line-delete',
M
Martin Aeschlimann 已提交
1657
		linesDecorationsClassName: 'delete-sign ' + diffRemoveIcon.classNames,
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
		marginClassName: 'line-delete',
		isWholeLine: true

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

};

R
rebornix 已提交
1668
export class DiffEditorWidgetSideBySide extends DiffEditorWidgetStyle implements IDiffEditorWidgetStyle, IVerticalSashLayoutProvider {
E
Erich Gamma 已提交
1669

1670
	static readonly MINIMUM_EDITOR_WIDTH = 100;
E
Erich Gamma 已提交
1671 1672

	private _disableSash: boolean;
1673
	private readonly _sash: Sash;
A
Alex Dima 已提交
1674 1675
	private _sashRatio: number | null;
	private _sashPosition: number | null;
A
Alex Dima 已提交
1676
	private _startSashPosition: number | null;
E
Erich Gamma 已提交
1677

J
Johannes Rieken 已提交
1678
	constructor(dataSource: IDataSource, enableSplitViewResizing: boolean) {
E
Erich Gamma 已提交
1679 1680 1681 1682 1683
		super(dataSource);

		this._disableSash = (enableSplitViewResizing === false);
		this._sashRatio = null;
		this._sashPosition = null;
A
Alex Dima 已提交
1684
		this._startSashPosition = null;
J
João Moreno 已提交
1685
		this._sash = this._register(new Sash(this._dataSource.getContainerDomNode(), this, { orientation: Orientation.VERTICAL }));
E
Erich Gamma 已提交
1686 1687

		if (this._disableSash) {
J
Joao Moreno 已提交
1688
			this._sash.state = SashState.Disabled;
E
Erich Gamma 已提交
1689 1690
		}

I
isidor 已提交
1691 1692 1693 1694
		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 已提交
1695 1696
	}

J
Johannes Rieken 已提交
1697
	public setEnableSplitViewResizing(enableSplitViewResizing: boolean): void {
A
Alex Dima 已提交
1698
		let newDisableSash = (enableSplitViewResizing === false);
E
Erich Gamma 已提交
1699 1700
		if (this._disableSash !== newDisableSash) {
			this._disableSash = newDisableSash;
J
Joao Moreno 已提交
1701
			this._sash.state = this._disableSash ? SashState.Disabled : SashState.Enabled;
E
Erich Gamma 已提交
1702 1703 1704
		}
	}

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

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

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

H
Howard Hung 已提交
1714 1715 1716
		if (contentWidth > DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH * 2) {
			if (sashPosition < DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH) {
				sashPosition = DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH;
E
Erich Gamma 已提交
1717 1718
			}

H
Howard Hung 已提交
1719 1720
			if (sashPosition > contentWidth - DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH) {
				sashPosition = contentWidth - DiffEditorWidgetSideBySide.MINIMUM_EDITOR_WIDTH;
E
Erich Gamma 已提交
1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
			}
		} else {
			sashPosition = midPoint;
		}

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

		return this._sashPosition;
	}

M
Maxime Quandalle 已提交
1734
	private onSashDragStart(): void {
A
Alex Dima 已提交
1735
		this._startSashPosition = this._sashPosition!;
E
Erich Gamma 已提交
1736 1737
	}

J
Johannes Rieken 已提交
1738
	private onSashDrag(e: ISashEvent): void {
A
Alex Dima 已提交
1739 1740
		let w = this._dataSource.getWidth();
		let contentWidth = w - DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH;
A
Alex Dima 已提交
1741
		let sashPosition = this.layout((this._startSashPosition! + (e.currentX - e.startX)) / contentWidth);
E
Erich Gamma 已提交
1742 1743 1744 1745 1746 1747

		this._sashRatio = sashPosition / contentWidth;

		this._dataSource.relayoutEditors();
	}

M
Maxime Quandalle 已提交
1748 1749 1750 1751 1752 1753 1754
	private onSashDragEnd(): void {
		this._sash.layout();
	}

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

A
Alex Dima 已提交
1758
	public getVerticalSashTop(sash: Sash): number {
E
Erich Gamma 已提交
1759 1760 1761
		return 0;
	}

A
Alex Dima 已提交
1762
	public getVerticalSashLeft(sash: Sash): number {
A
Alex Dima 已提交
1763
		return this._sashPosition!;
E
Erich Gamma 已提交
1764 1765
	}

A
Alex Dima 已提交
1766
	public getVerticalSashHeight(sash: Sash): number {
E
Erich Gamma 已提交
1767 1768 1769
		return this._dataSource.getHeight();
	}

1770
	protected _getViewZones(lineChanges: editorCommon.ILineChange[], originalForeignVZ: IEditorWhitespace[], modifiedForeignVZ: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorsZones {
1771
		let c = new SideBySideViewZonesComputer(lineChanges, originalForeignVZ, originalEditor.getOption(EditorOption.lineHeight), modifiedForeignVZ, modifiedEditor.getOption(EditorOption.lineHeight));
E
Erich Gamma 已提交
1772 1773 1774
		return c.getViewZones();
	}

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

A
Alex Dima 已提交
1778
		let result: IEditorDiffDecorations = {
J
Johannes Rieken 已提交
1779 1780
			decorations: [],
			overviewZones: []
P
Peng Lyu 已提交
1781
		};
A
Alex Dima 已提交
1782

A
Alex Dima 已提交
1783
		let originalModel = originalEditor.getModel()!;
A
Alex Dima 已提交
1784 1785 1786

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

			if (isChangeOrDelete(lineChange)) {
1789
				result.decorations.push({
1790
					range: new Range(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
1791
					options: (renderIndicators ? DECORATIONS.lineDeleteWithSign : DECORATIONS.lineDelete)
1792
				});
E
Erich Gamma 已提交
1793
				if (!isChangeOrInsert(lineChange) || !lineChange.charChanges) {
1794
					result.decorations.push(createDecoration(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charDeleteWholeLine));
E
Erich Gamma 已提交
1795 1796
				}

A
Alex Dima 已提交
1797
				result.overviewZones.push(new OverviewRulerZone(
A
Alex Dima 已提交
1798 1799
					lineChange.originalStartLineNumber,
					lineChange.originalEndLineNumber,
A
Alex Dima 已提交
1800
					overviewZoneColor
A
Alex Dima 已提交
1801
				));
E
Erich Gamma 已提交
1802 1803

				if (lineChange.charChanges) {
A
Alex Dima 已提交
1804 1805
					for (let j = 0, lengthJ = lineChange.charChanges.length; j < lengthJ; j++) {
						let charChange = lineChange.charChanges[j];
E
Erich Gamma 已提交
1806 1807
						if (isChangeOrDelete(charChange)) {
							if (ignoreTrimWhitespace) {
A
Alex Dima 已提交
1808 1809 1810
								for (let lineNumber = charChange.originalStartLineNumber; lineNumber <= charChange.originalEndLineNumber; lineNumber++) {
									let startColumn: number;
									let endColumn: number;
E
Erich Gamma 已提交
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820
									if (lineNumber === charChange.originalStartLineNumber) {
										startColumn = charChange.originalStartColumn;
									} else {
										startColumn = originalModel.getLineFirstNonWhitespaceColumn(lineNumber);
									}
									if (lineNumber === charChange.originalEndLineNumber) {
										endColumn = charChange.originalEndColumn;
									} else {
										endColumn = originalModel.getLineLastNonWhitespaceColumn(lineNumber);
									}
1821
									result.decorations.push(createDecoration(lineNumber, startColumn, lineNumber, endColumn, DECORATIONS.charDelete));
E
Erich Gamma 已提交
1822 1823
								}
							} else {
1824
								result.decorations.push(createDecoration(charChange.originalStartLineNumber, charChange.originalStartColumn, charChange.originalEndLineNumber, charChange.originalEndColumn, DECORATIONS.charDelete));
E
Erich Gamma 已提交
1825 1826 1827 1828 1829 1830 1831 1832 1833 1834
							}
						}
					}
				}
			}
		}

		return result;
	}

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

A
Alex Dima 已提交
1838
		let result: IEditorDiffDecorations = {
J
Johannes Rieken 已提交
1839 1840
			decorations: [],
			overviewZones: []
A
Alex Dima 已提交
1841 1842
		};

A
Alex Dima 已提交
1843
		let modifiedModel = modifiedEditor.getModel()!;
A
Alex Dima 已提交
1844 1845 1846

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

			if (isChangeOrInsert(lineChange)) {

1850
				result.decorations.push({
1851
					range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
1852
					options: (renderIndicators ? DECORATIONS.lineInsertWithSign : DECORATIONS.lineInsert)
1853
				});
E
Erich Gamma 已提交
1854
				if (!isChangeOrDelete(lineChange) || !lineChange.charChanges) {
1855
					result.decorations.push(createDecoration(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charInsertWholeLine));
E
Erich Gamma 已提交
1856
				}
A
Alex Dima 已提交
1857
				result.overviewZones.push(new OverviewRulerZone(
A
Alex Dima 已提交
1858 1859
					lineChange.modifiedStartLineNumber,
					lineChange.modifiedEndLineNumber,
A
Alex Dima 已提交
1860
					overviewZoneColor
A
Alex Dima 已提交
1861
				));
E
Erich Gamma 已提交
1862 1863

				if (lineChange.charChanges) {
A
Alex Dima 已提交
1864 1865
					for (let j = 0, lengthJ = lineChange.charChanges.length; j < lengthJ; j++) {
						let charChange = lineChange.charChanges[j];
E
Erich Gamma 已提交
1866 1867
						if (isChangeOrInsert(charChange)) {
							if (ignoreTrimWhitespace) {
A
Alex Dima 已提交
1868 1869 1870
								for (let lineNumber = charChange.modifiedStartLineNumber; lineNumber <= charChange.modifiedEndLineNumber; lineNumber++) {
									let startColumn: number;
									let endColumn: number;
E
Erich Gamma 已提交
1871 1872 1873 1874 1875 1876 1877 1878 1879 1880
									if (lineNumber === charChange.modifiedStartLineNumber) {
										startColumn = charChange.modifiedStartColumn;
									} else {
										startColumn = modifiedModel.getLineFirstNonWhitespaceColumn(lineNumber);
									}
									if (lineNumber === charChange.modifiedEndLineNumber) {
										endColumn = charChange.modifiedEndColumn;
									} else {
										endColumn = modifiedModel.getLineLastNonWhitespaceColumn(lineNumber);
									}
1881
									result.decorations.push(createDecoration(lineNumber, startColumn, lineNumber, endColumn, DECORATIONS.charInsert));
E
Erich Gamma 已提交
1882 1883
								}
							} else {
1884
								result.decorations.push(createDecoration(charChange.modifiedStartLineNumber, charChange.modifiedStartColumn, charChange.modifiedEndLineNumber, charChange.modifiedEndColumn, DECORATIONS.charInsert));
E
Erich Gamma 已提交
1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897
							}
						}
					}
				}

			}
		}
		return result;
	}
}

class SideBySideViewZonesComputer extends ViewZonesComputer {

1898 1899
	constructor(lineChanges: editorCommon.ILineChange[], originalForeignVZ: IEditorWhitespace[], originalLineHeight: number, modifiedForeignVZ: IEditorWhitespace[], modifiedLineHeight: number) {
		super(lineChanges, originalForeignVZ, originalLineHeight, modifiedForeignVZ, modifiedLineHeight);
E
Erich Gamma 已提交
1900 1901
	}

A
Alex Dima 已提交
1902
	protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null {
A
Alex Dima 已提交
1903 1904 1905
		return null;
	}

A
Alex Dima 已提交
1906
	protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
E
Erich Gamma 已提交
1907 1908 1909 1910 1911 1912 1913 1914 1915 1916
		if (lineChangeModifiedLength > lineChangeOriginalLength) {
			return {
				afterLineNumber: Math.max(lineChange.originalStartLineNumber, lineChange.originalEndLineNumber),
				heightInLines: (lineChangeModifiedLength - lineChangeOriginalLength),
				domNode: null
			};
		}
		return null;
	}

A
Alex Dima 已提交
1917
	protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
E
Erich Gamma 已提交
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928
		if (lineChangeOriginalLength > lineChangeModifiedLength) {
			return {
				afterLineNumber: Math.max(lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber),
				heightInLines: (lineChangeOriginalLength - lineChangeModifiedLength),
				domNode: null
			};
		}
		return null;
	}
}

H
Howard Hung 已提交
1929
class DiffEditorWidgetInline extends DiffEditorWidgetStyle implements IDiffEditorWidgetStyle {
E
Erich Gamma 已提交
1930 1931 1932

	private decorationsLeft: number;

J
Johannes Rieken 已提交
1933
	constructor(dataSource: IDataSource, enableSplitViewResizing: boolean) {
E
Erich Gamma 已提交
1934 1935
		super(dataSource);

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

1938
		this._register(dataSource.getOriginalEditor().onDidLayoutChange((layoutInfo: EditorLayoutInfo) => {
E
Erich Gamma 已提交
1939 1940 1941 1942 1943 1944 1945
			if (this.decorationsLeft !== layoutInfo.decorationsLeft) {
				this.decorationsLeft = layoutInfo.decorationsLeft;
				dataSource.relayoutEditors();
			}
		}));
	}

J
Johannes Rieken 已提交
1946
	public setEnableSplitViewResizing(enableSplitViewResizing: boolean): void {
E
Erich Gamma 已提交
1947 1948 1949
		// Nothing to do..
	}

1950
	protected _getViewZones(lineChanges: editorCommon.ILineChange[], originalForeignVZ: IEditorWhitespace[], modifiedForeignVZ: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor, renderIndicators: boolean): IEditorsZones {
1951
		let computer = new InlineViewZonesComputer(lineChanges, originalForeignVZ, modifiedForeignVZ, originalEditor, modifiedEditor, renderIndicators);
E
Erich Gamma 已提交
1952 1953 1954
		return computer.getViewZones();
	}

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

A
Alex Dima 已提交
1958
		let result: IEditorDiffDecorations = {
J
Johannes Rieken 已提交
1959 1960
			decorations: [],
			overviewZones: []
A
Alex Dima 已提交
1961
		};
E
Erich Gamma 已提交
1962

A
Alex Dima 已提交
1963 1964
		for (let i = 0, length = lineChanges.length; i < length; i++) {
			let lineChange = lineChanges[i];
E
Erich Gamma 已提交
1965 1966 1967

			// Add overview zones in the overview ruler
			if (isChangeOrDelete(lineChange)) {
1968
				result.decorations.push({
1969
					range: new Range(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
1970
					options: DECORATIONS.lineDeleteMargin
1971 1972
				});

A
Alex Dima 已提交
1973
				result.overviewZones.push(new OverviewRulerZone(
A
Alex Dima 已提交
1974 1975
					lineChange.originalStartLineNumber,
					lineChange.originalEndLineNumber,
A
Alex Dima 已提交
1976
					overviewZoneColor
A
Alex Dima 已提交
1977
				));
E
Erich Gamma 已提交
1978 1979 1980 1981 1982 1983
			}
		}

		return result;
	}

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

A
Alex Dima 已提交
1987
		let result: IEditorDiffDecorations = {
J
Johannes Rieken 已提交
1988 1989
			decorations: [],
			overviewZones: []
A
Alex Dima 已提交
1990 1991
		};

A
Alex Dima 已提交
1992
		let modifiedModel = modifiedEditor.getModel()!;
A
Alex Dima 已提交
1993 1994 1995

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

			// Add decorations & overview zones
			if (isChangeOrInsert(lineChange)) {
1999
				result.decorations.push({
2000
					range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
2001
					options: (renderIndicators ? DECORATIONS.lineInsertWithSign : DECORATIONS.lineInsert)
2002
				});
E
Erich Gamma 已提交
2003

A
Alex Dima 已提交
2004
				result.overviewZones.push(new OverviewRulerZone(
A
Alex Dima 已提交
2005 2006
					lineChange.modifiedStartLineNumber,
					lineChange.modifiedEndLineNumber,
A
Alex Dima 已提交
2007
					overviewZoneColor
A
Alex Dima 已提交
2008
				));
E
Erich Gamma 已提交
2009 2010

				if (lineChange.charChanges) {
A
Alex Dima 已提交
2011 2012
					for (let j = 0, lengthJ = lineChange.charChanges.length; j < lengthJ; j++) {
						let charChange = lineChange.charChanges[j];
E
Erich Gamma 已提交
2013 2014
						if (isChangeOrInsert(charChange)) {
							if (ignoreTrimWhitespace) {
A
Alex Dima 已提交
2015 2016 2017
								for (let lineNumber = charChange.modifiedStartLineNumber; lineNumber <= charChange.modifiedEndLineNumber; lineNumber++) {
									let startColumn: number;
									let endColumn: number;
E
Erich Gamma 已提交
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027
									if (lineNumber === charChange.modifiedStartLineNumber) {
										startColumn = charChange.modifiedStartColumn;
									} else {
										startColumn = modifiedModel.getLineFirstNonWhitespaceColumn(lineNumber);
									}
									if (lineNumber === charChange.modifiedEndLineNumber) {
										endColumn = charChange.modifiedEndColumn;
									} else {
										endColumn = modifiedModel.getLineLastNonWhitespaceColumn(lineNumber);
									}
2028
									result.decorations.push(createDecoration(lineNumber, startColumn, lineNumber, endColumn, DECORATIONS.charInsert));
E
Erich Gamma 已提交
2029 2030
								}
							} else {
2031
								result.decorations.push(createDecoration(charChange.modifiedStartLineNumber, charChange.modifiedStartColumn, charChange.modifiedEndLineNumber, charChange.modifiedEndColumn, DECORATIONS.charInsert));
E
Erich Gamma 已提交
2032 2033 2034 2035
							}
						}
					}
				} else {
2036
					result.decorations.push(createDecoration(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charInsertWholeLine));
E
Erich Gamma 已提交
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052
				}
			}
		}

		return result;
	}

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

}

class InlineViewZonesComputer extends ViewZonesComputer {

2053
	private readonly originalModel: ITextModel;
2054
	private readonly modifiedEditorOptions: IComputedEditorOptions;
2055 2056
	private readonly modifiedEditorTabSize: number;
	private readonly renderIndicators: boolean;
E
Erich Gamma 已提交
2057

A
Alex Dima 已提交
2058
	constructor(lineChanges: editorCommon.ILineChange[], originalForeignVZ: IEditorWhitespace[], modifiedForeignVZ: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor, renderIndicators: boolean) {
2059
		super(lineChanges, originalForeignVZ, originalEditor.getOption(EditorOption.lineHeight), modifiedForeignVZ, modifiedEditor.getOption(EditorOption.lineHeight));
A
Alex Dima 已提交
2060
		this.originalModel = originalEditor.getModel()!;
A
Alex Dima 已提交
2061
		this.modifiedEditorOptions = modifiedEditor.getOptions();
A
Alex Dima 已提交
2062
		this.modifiedEditorTabSize = modifiedEditor.getModel()!.getOptions().tabSize;
R
rebornix 已提交
2063
		this.renderIndicators = renderIndicators;
E
Erich Gamma 已提交
2064 2065
	}

A
Alex Dima 已提交
2066
	protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null {
A
Alex Dima 已提交
2067 2068 2069 2070 2071
		let result = document.createElement('div');
		result.className = 'inline-added-margin-view-zone';
		return result;
	}

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

E
Erich Gamma 已提交
2076
		return {
J
Johannes Rieken 已提交
2077
			afterLineNumber: Math.max(lineChange.originalStartLineNumber, lineChange.originalEndLineNumber),
E
Erich Gamma 已提交
2078
			heightInLines: lineChangeModifiedLength,
2079 2080
			domNode: document.createElement('div'),
			marginDomNode: marginDomNode
E
Erich Gamma 已提交
2081 2082 2083
		};
	}

A
Alex Dima 已提交
2084
	protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
A
Alex Dima 已提交
2085
		let decorations: InlineDecoration[] = [];
E
Erich Gamma 已提交
2086
		if (lineChange.charChanges) {
A
Alex Dima 已提交
2087 2088
			for (let j = 0, lengthJ = lineChange.charChanges.length; j < lengthJ; j++) {
				let charChange = lineChange.charChanges[j];
E
Erich Gamma 已提交
2089
				if (isChangeOrDelete(charChange)) {
2090 2091
					decorations.push(new InlineDecoration(
						new Range(charChange.originalStartLineNumber, charChange.originalStartColumn, charChange.originalEndLineNumber, charChange.originalEndColumn),
2092
						'char-delete',
2093
						InlineDecorationType.Regular
2094
					));
E
Erich Gamma 已提交
2095 2096 2097 2098
				}
			}
		}

2099
		let sb = createStringBuilder(10000);
2100
		let marginHTML: string[] = [];
A
renames  
Alex Dima 已提交
2101
		const layoutInfo = this.modifiedEditorOptions.get(EditorOption.layoutInfo);
2102
		const fontInfo = this.modifiedEditorOptions.get(EditorOption.fontInfo);
A
Alex Dima 已提交
2103 2104
		const lineDecorationsWidth = layoutInfo.decorationsWidth;

A
Alex Dima 已提交
2105
		let lineHeight = this.modifiedEditorOptions.get(EditorOption.lineHeight);
2106
		const typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth;
2107
		let maxCharsPerLine = 0;
2108
		const originalContent: string[] = [];
A
Alex Dima 已提交
2109
		for (let lineNumber = lineChange.originalStartLineNumber; lineNumber <= lineChange.originalEndLineNumber; lineNumber++) {
2110
			maxCharsPerLine = Math.max(maxCharsPerLine, this._renderOriginalLine(lineNumber - lineChange.originalStartLineNumber, this.originalModel, this.modifiedEditorOptions, this.modifiedEditorTabSize, lineNumber, decorations, sb));
2111
			originalContent.push(this.originalModel.getLineContent(lineNumber));
2112

R
rebornix 已提交
2113
			if (this.renderIndicators) {
2114 2115
				let index = lineNumber - lineChange.originalStartLineNumber;
				marginHTML = marginHTML.concat([
M
Martin Aeschlimann 已提交
2116
					`<div class="delete-sign ${diffRemoveIcon.classNames}" style="position:absolute;top:${index * lineHeight}px;width:${lineDecorationsWidth}px;height:${lineHeight}px;right:0;"></div>`
2117 2118
				]);
			}
E
Erich Gamma 已提交
2119
		}
A
Alex Dima 已提交
2120
		maxCharsPerLine += this.modifiedEditorOptions.get(EditorOption.scrollBeyondLastColumn);
E
Erich Gamma 已提交
2121

A
Alex Dima 已提交
2122
		let domNode = document.createElement('div');
2123
		domNode.className = `view-lines line-delete ${MOUSE_CURSOR_TEXT_CSS_CLASS_NAME}`;
2124
		domNode.innerHTML = sb.build();
2125
		Configuration.applyFontInfoSlow(domNode, fontInfo);
E
Erich Gamma 已提交
2126

2127 2128 2129
		let marginDomNode = document.createElement('div');
		marginDomNode.className = 'inline-deleted-margin-view-zone';
		marginDomNode.innerHTML = marginHTML.join('');
2130
		Configuration.applyFontInfoSlow(marginDomNode, fontInfo);
2131

E
Erich Gamma 已提交
2132 2133 2134 2135
		return {
			shouldNotShrink: true,
			afterLineNumber: (lineChange.modifiedEndLineNumber === 0 ? lineChange.modifiedStartLineNumber : lineChange.modifiedStartLineNumber - 1),
			heightInLines: lineChangeOriginalLength,
2136
			minWidthInPx: (maxCharsPerLine * typicalHalfwidthCharacterWidth),
2137
			domNode: domNode,
2138 2139 2140 2141 2142 2143 2144 2145
			marginDomNode: marginDomNode,
			diff: {
				originalStartLineNumber: lineChange.originalStartLineNumber,
				originalEndLineNumber: lineChange.originalEndLineNumber,
				modifiedStartLineNumber: lineChange.modifiedStartLineNumber,
				modifiedEndLineNumber: lineChange.modifiedEndLineNumber,
				originalContent: originalContent
			}
E
Erich Gamma 已提交
2146 2147 2148
		};
	}

2149
	private _renderOriginalLine(count: number, originalModel: ITextModel, options: IComputedEditorOptions, tabSize: number, lineNumber: number, decorations: InlineDecoration[], sb: IStringBuilder): number {
2150 2151
		const lineTokens = originalModel.getLineTokens(lineNumber);
		const lineContent = lineTokens.getLineContent();
2152
		const fontInfo = options.get(EditorOption.fontInfo);
A
Alex Dima 已提交
2153

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

2156 2157 2158 2159 2160 2161
		sb.appendASCIIString('<div class="view-line');
		if (decorations.length === 0) {
			// No char changes
			sb.appendASCIIString(' char-delete');
		}
		sb.appendASCIIString('" style="top:');
A
Alex Dima 已提交
2162
		sb.appendASCIIString(String(count * options.get(EditorOption.lineHeight)));
2163 2164
		sb.appendASCIIString('px;width:1000000px;">');

2165 2166
		const isBasicASCII = ViewLineRenderingData.isBasicASCII(lineContent, originalModel.mightContainNonBasicASCII());
		const containsRTL = ViewLineRenderingData.containsRTL(lineContent, isBasicASCII, originalModel.mightContainRTL());
2167
		const output = renderViewLine(new RenderLineInput(
2168
			(fontInfo.isMonospace && !options.get(EditorOption.disableMonospaceOptimizations)),
2169
			fontInfo.canUseHalfwidthRightwardsArrow,
A
Alex Dima 已提交
2170
			lineContent,
A
Alex Dima 已提交
2171
			false,
2172 2173
			isBasicASCII,
			containsRTL,
2174
			0,
A
Alex Dima 已提交
2175
			lineTokens,
2176
			actualDecorations,
A
Alex Dima 已提交
2177
			tabSize,
2178
			0,
2179
			fontInfo.spaceWidth,
2180
			fontInfo.middotWidth,
2181
			fontInfo.wsmiddotWidth,
A
Alex Dima 已提交
2182 2183 2184
			options.get(EditorOption.stopRenderingLineAfter),
			options.get(EditorOption.renderWhitespace),
			options.get(EditorOption.renderControlCharacters),
2185
			options.get(EditorOption.fontLigatures) !== EditorFontLigatures.OFF,
2186
			null // Send no selections, original line cannot be selected
2187
		), sb);
E
Erich Gamma 已提交
2188

2189
		sb.appendASCIIString('</div>');
2190 2191 2192

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

R
rebornix 已提交
2196
export function isChangeOrInsert(lineChange: editorCommon.IChange): boolean {
E
Erich Gamma 已提交
2197 2198 2199
	return lineChange.modifiedEndLineNumber > 0;
}

R
rebornix 已提交
2200
export function isChangeOrDelete(lineChange: editorCommon.IChange): boolean {
E
Erich Gamma 已提交
2201 2202 2203 2204
	return lineChange.originalEndLineNumber > 0;
}

function createFakeLinesDiv(): HTMLElement {
A
Alex Dima 已提交
2205
	let r = document.createElement('div');
E
Erich Gamma 已提交
2206 2207 2208
	r.className = 'diagonal-fill';
	return r;
}
2209 2210

registerThemingParticipant((theme, collector) => {
2211
	const added = theme.getColor(diffInserted);
2212 2213
	if (added) {
		collector.addRule(`.monaco-editor .line-insert, .monaco-editor .char-insert { background-color: ${added}; }`);
A
Alex Dima 已提交
2214
		collector.addRule(`.monaco-diff-editor .line-insert, .monaco-diff-editor .char-insert { background-color: ${added}; }`);
2215 2216
		collector.addRule(`.monaco-editor .inline-added-margin-view-zone { background-color: ${added}; }`);
	}
2217 2218

	const removed = theme.getColor(diffRemoved);
2219 2220
	if (removed) {
		collector.addRule(`.monaco-editor .line-delete, .monaco-editor .char-delete { background-color: ${removed}; }`);
A
Alex Dima 已提交
2221
		collector.addRule(`.monaco-diff-editor .line-delete, .monaco-diff-editor .char-delete { background-color: ${removed}; }`);
2222 2223
		collector.addRule(`.monaco-editor .inline-deleted-margin-view-zone { background-color: ${removed}; }`);
	}
2224 2225

	const addedOutline = theme.getColor(diffInsertedOutline);
2226
	if (addedOutline) {
2227
		collector.addRule(`.monaco-editor .line-insert, .monaco-editor .char-insert { border: 1px ${theme.type === 'hc' ? 'dashed' : 'solid'} ${addedOutline}; }`);
2228
	}
2229 2230

	const removedOutline = theme.getColor(diffRemovedOutline);
2231
	if (removedOutline) {
2232
		collector.addRule(`.monaco-editor .line-delete, .monaco-editor .char-delete { border: 1px ${theme.type === 'hc' ? 'dashed' : 'solid'} ${removedOutline}; }`);
2233
	}
2234 2235

	const shadow = theme.getColor(scrollbarShadow);
2236 2237 2238
	if (shadow) {
		collector.addRule(`.monaco-diff-editor.side-by-side .editor.modified { box-shadow: -6px 0 5px -5px ${shadow}; }`);
	}
2239

M
Matt Bierner 已提交
2240
	const border = theme.getColor(diffBorder);
2241 2242 2243
	if (border) {
		collector.addRule(`.monaco-diff-editor.side-by-side .editor.modified { border-left: 1px solid ${border}; }`);
	}
2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271

	const scrollbarSliderBackgroundColor = theme.getColor(scrollbarSliderBackground);
	if (scrollbarSliderBackgroundColor) {
		collector.addRule(`
			.monaco-diff-editor .diffViewport {
				background: ${scrollbarSliderBackgroundColor};
			}
		`);
	}

	const scrollbarSliderHoverBackgroundColor = theme.getColor(scrollbarSliderHoverBackground);
	if (scrollbarSliderHoverBackgroundColor) {
		collector.addRule(`
			.monaco-diff-editor .diffViewport:hover {
				background: ${scrollbarSliderHoverBackgroundColor};
			}
		`);
	}

	const scrollbarSliderActiveBackgroundColor = theme.getColor(scrollbarSliderActiveBackground);
	if (scrollbarSliderActiveBackgroundColor) {
		collector.addRule(`
			.monaco-diff-editor .diffViewport:active {
				background: ${scrollbarSliderActiveBackgroundColor};
			}
		`);
	}

2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284
	const diffDiagonalFillColor = theme.getColor(diffDiagonalFill);
	collector.addRule(`
	.monaco-editor .diagonal-fill {
		background-image: linear-gradient(
			-45deg,
			${diffDiagonalFillColor} 12.5%,
			#0000 12.5%, #0000 50%,
			${diffDiagonalFillColor} 50%, ${diffDiagonalFillColor} 62.5%,
			#0000 62.5%, #0000 100%
		);
		background-size: 8px 8px;
	}
	`);
2285
});