viewImpl.ts 34.8 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.
 *--------------------------------------------------------------------------------------------*/
'use strict';

J
Johannes Rieken 已提交
7
import { onUnexpectedError } from 'vs/base/common/errors';
A
Alex Dima 已提交
8
import { EmitterEvent, IEventEmitter } from 'vs/base/common/eventEmitter';
J
Johannes Rieken 已提交
9
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
A
Alex Dima 已提交
10 11
import * as browser from 'vs/base/browser/browser';
import * as dom from 'vs/base/browser/dom';
J
Johannes Rieken 已提交
12 13 14
import { StyleMutator } from 'vs/base/browser/styleMutator';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { Range } from 'vs/editor/common/core/range';
A
Alex Dima 已提交
15
import * as editorCommon from 'vs/editor/common/editorCommon';
J
Johannes Rieken 已提交
16 17 18 19
import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler';
import { Configuration } from 'vs/editor/browser/config/configuration';
import { KeyboardHandler, IKeyboardHandlerHelper } from 'vs/editor/browser/controller/keyboardHandler';
import { PointerHandler } from 'vs/editor/browser/controller/pointerHandler';
A
Alex Dima 已提交
20
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
J
Johannes Rieken 已提交
21 22 23 24 25 26
import { ViewController, TriggerCursorHandler } from 'vs/editor/browser/view/viewController';
import { ViewEventDispatcher } from 'vs/editor/browser/view/viewEventDispatcher';
import { ContentViewOverlays, MarginViewOverlays } from 'vs/editor/browser/view/viewOverlays';
import { LayoutProvider } from 'vs/editor/browser/viewLayout/layoutProvider';
import { ViewContentWidgets } from 'vs/editor/browser/viewParts/contentWidgets/contentWidgets';
import { CurrentLineHighlightOverlay } from 'vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight';
27
import { CurrentLineMarginHighlightOverlay } from 'vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight';
J
Johannes Rieken 已提交
28 29 30 31 32
import { DecorationsOverlay } from 'vs/editor/browser/viewParts/decorations/decorations';
import { GlyphMarginOverlay } from 'vs/editor/browser/viewParts/glyphMargin/glyphMargin';
import { LineNumbersOverlay } from 'vs/editor/browser/viewParts/lineNumbers/lineNumbers';
import { IndentGuidesOverlay } from 'vs/editor/browser/viewParts/indentGuides/indentGuides';
import { ViewLines } from 'vs/editor/browser/viewParts/lines/viewLines';
33
import { Margin } from 'vs/editor/browser/viewParts/margin/margin';
J
Johannes Rieken 已提交
34
import { LinesDecorationsOverlay } from 'vs/editor/browser/viewParts/linesDecorations/linesDecorations';
35
import { MarginViewLineDecorationsOverlay } from 'vs/editor/browser/viewParts/marginDecorations/marginDecorations';
J
Johannes Rieken 已提交
36 37 38 39 40 41 42 43
import { ViewOverlayWidgets } from 'vs/editor/browser/viewParts/overlayWidgets/overlayWidgets';
import { DecorationsOverviewRuler } from 'vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler';
import { OverviewRuler } from 'vs/editor/browser/viewParts/overviewRuler/overviewRuler';
import { Rulers } from 'vs/editor/browser/viewParts/rulers/rulers';
import { ScrollDecorationViewPart } from 'vs/editor/browser/viewParts/scrollDecoration/scrollDecoration';
import { SelectionsOverlay } from 'vs/editor/browser/viewParts/selections/selections';
import { ViewCursors } from 'vs/editor/browser/viewParts/viewCursors/viewCursors';
import { ViewZones } from 'vs/editor/browser/viewParts/viewZones/viewZones';
A
Alex Dima 已提交
44
import { ViewPart, PartFingerprint, PartFingerprints } from 'vs/editor/browser/view/viewPart';
J
Johannes Rieken 已提交
45 46
import { ViewContext, IViewEventHandler } from 'vs/editor/common/view/viewContext';
import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
A
Alex Dima 已提交
47
import { RenderingContext } from 'vs/editor/common/view/renderingContext';
J
Johannes Rieken 已提交
48
import { IPointerHandlerHelper } from 'vs/editor/browser/controller/mouseHandler';
A
Alex Dima 已提交
49
import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents';
E
Erich Gamma 已提交
50

A
Alex Dima 已提交
51
export class View extends ViewEventHandler implements editorBrowser.IView, IDisposable {
E
Erich Gamma 已提交
52

J
Johannes Rieken 已提交
53
	private eventDispatcher: ViewEventDispatcher;
E
Erich Gamma 已提交
54

J
Johannes Rieken 已提交
55 56
	private listenersToRemove: IDisposable[];
	private listenersToDispose: IDisposable[];
E
Erich Gamma 已提交
57 58

	private layoutProvider: LayoutProvider;
59
	public _context: ViewContext;
E
Erich Gamma 已提交
60 61 62 63 64 65 66 67

	// The view lines
	private viewLines: ViewLines;

	// These are parts, but we must do some API related calls on them, so we keep a reference
	private viewZones: ViewZones;
	private contentWidgets: ViewContentWidgets;
	private overlayWidgets: ViewOverlayWidgets;
68
	private viewCursors: ViewCursors;
A
Alex Dima 已提交
69
	private viewParts: ViewPart[];
E
Erich Gamma 已提交
70 71 72 73

	private keyboardHandler: KeyboardHandler;
	private pointerHandler: PointerHandler;

A
Alex Dima 已提交
74
	private outgoingEvents: ViewOutgoingEvents;
E
Erich Gamma 已提交
75 76 77 78 79 80 81 82 83 84

	// Dom nodes
	private linesContent: HTMLElement;
	public domNode: HTMLElement;
	public textArea: HTMLTextAreaElement;
	private textAreaCover: HTMLElement;
	private linesContentContainer: HTMLElement;
	private overflowGuardContainer: HTMLElement;

	// Actual mutable state
J
Johannes Rieken 已提交
85
	private hasFocus: boolean;
E
Erich Gamma 已提交
86 87
	private _isDisposed: boolean;

J
Johannes Rieken 已提交
88
	private handleAccumulatedModelEventsTimeout: number;
A
Alex Dima 已提交
89
	private accumulatedModelEvents: EmitterEvent[];
A
Alex Dima 已提交
90
	private _renderAnimationFrame: IDisposable;
E
Erich Gamma 已提交
91

A
Alex Dima 已提交
92
	constructor(
93
		commandService: ICommandService,
J
Johannes Rieken 已提交
94 95 96
		configuration: Configuration,
		model: IViewModel,
		private triggerCursorHandler: TriggerCursorHandler
A
Alex Dima 已提交
97
	) {
E
Erich Gamma 已提交
98 99 100
		super();
		this._isDisposed = false;
		this._renderAnimationFrame = null;
A
Alex Dima 已提交
101
		this.outgoingEvents = new ViewOutgoingEvents(model);
E
Erich Gamma 已提交
102

A
Alex Dima 已提交
103
		let viewController = new ViewController(model, triggerCursorHandler, this.outgoingEvents, commandService);
E
Erich Gamma 已提交
104 105 106 107 108

		this.listenersToRemove = [];
		this.listenersToDispose = [];

		// The event dispatcher will always go through _renderOnce before dispatching any events
J
Johannes Rieken 已提交
109
		this.eventDispatcher = new ViewEventDispatcher((callback: () => void) => this._renderOnce(callback));
E
Erich Gamma 已提交
110 111 112

		// These two dom nodes must be constructed up front, since references are needed in the layout provider (scrolling & co.)
		this.linesContent = document.createElement('div');
A
Alex Dima 已提交
113
		this.linesContent.className = editorBrowser.ClassNames.LINES_CONTENT + ' monaco-editor-background';
A
Alex Dima 已提交
114
		this.linesContent.style.position = 'absolute';
E
Erich Gamma 已提交
115
		this.domNode = document.createElement('div');
116
		this.domNode.className = configuration.editor.viewInfo.editorClassName;
E
Erich Gamma 已提交
117 118

		this.overflowGuardContainer = document.createElement('div');
A
Alex Dima 已提交
119
		PartFingerprints.write(this.overflowGuardContainer, PartFingerprint.OverflowGuard);
A
Alex Dima 已提交
120
		this.overflowGuardContainer.className = editorBrowser.ClassNames.OVERFLOW_GUARD;
E
Erich Gamma 已提交
121 122 123 124 125 126 127 128 129

		// The layout provider has such responsibilities as:
		// - scrolling (i.e. viewport / full size) & co.
		// - whitespaces (a.k.a. view zones) management & co.
		// - line heights updating & co.
		this.layoutProvider = new LayoutProvider(configuration, model, this.eventDispatcher, this.linesContent, this.domNode, this.overflowGuardContainer);
		this.eventDispatcher.addEventHandler(this.layoutProvider);

		// The view context is passed on to most classes (basically to reduce param. counts in ctors)
130
		this._context = new ViewContext(
J
Johannes Rieken 已提交
131 132 133
			configuration, model, this.eventDispatcher,
			(eventHandler: IViewEventHandler) => this.eventDispatcher.addEventHandler(eventHandler),
			(eventHandler: IViewEventHandler) => this.eventDispatcher.removeEventHandler(eventHandler)
E
Erich Gamma 已提交
134 135
		);

136
		this.createTextArea();
E
Erich Gamma 已提交
137 138 139
		this.createViewParts();

		// Keyboard handler
140
		this.keyboardHandler = new KeyboardHandler(this._context, viewController, this.createKeyboardHandlerHelper());
E
Erich Gamma 已提交
141 142

		// Pointer handler
143
		this.pointerHandler = new PointerHandler(this._context, viewController, this.createPointerHandlerHelper());
E
Erich Gamma 已提交
144 145 146 147 148 149 150 151 152 153

		this.hasFocus = false;
		this.codeEditorHelper = null;

		this.eventDispatcher.addEventHandler(this);

		// The view lines rendering calls model.getLineTokens() that might emit events that its tokens have changed.
		// This delayed processing of incoming model events acts as a guard against undesired/unexpected recursion.
		this.handleAccumulatedModelEventsTimeout = -1;
		this.accumulatedModelEvents = [];
J
Johannes Rieken 已提交
154
		this.listenersToRemove.push(model.addBulkListener2((events: EmitterEvent[]) => {
E
Erich Gamma 已提交
155 156 157 158 159 160 161 162 163 164 165
			this.accumulatedModelEvents = this.accumulatedModelEvents.concat(events);
			if (this.handleAccumulatedModelEventsTimeout === -1) {
				this.handleAccumulatedModelEventsTimeout = setTimeout(() => {
					this.handleAccumulatedModelEventsTimeout = -1;
					this._flushAnyAccumulatedEvents();
				});
			}
		}));
	}

	private _flushAnyAccumulatedEvents(): void {
A
Alex Dima 已提交
166
		let toEmit = this.accumulatedModelEvents;
E
Erich Gamma 已提交
167 168 169 170 171 172
		this.accumulatedModelEvents = [];
		if (toEmit.length > 0) {
			this.eventDispatcher.emitMany(toEmit);
		}
	}

173
	private createTextArea(): void {
E
Erich Gamma 已提交
174 175
		// Text Area (The focus will always be in the textarea when the cursor is blinking)
		this.textArea = <HTMLTextAreaElement>document.createElement('textarea');
A
Alex Dima 已提交
176
		PartFingerprints.write(this.textArea, PartFingerprint.TextArea);
A
Alex Dima 已提交
177
		this.textArea.className = editorBrowser.ClassNames.TEXTAREA;
E
Erich Gamma 已提交
178 179 180 181
		this.textArea.setAttribute('wrap', 'off');
		this.textArea.setAttribute('autocorrect', 'off');
		this.textArea.setAttribute('autocapitalize', 'off');
		this.textArea.setAttribute('spellcheck', 'false');
182
		this.textArea.setAttribute('aria-label', this._context.configuration.editor.viewInfo.ariaLabel);
E
Erich Gamma 已提交
183 184
		this.textArea.setAttribute('role', 'textbox');
		this.textArea.setAttribute('aria-multiline', 'true');
A
Alex Dima 已提交
185 186 187
		this.textArea.setAttribute('aria-haspopup', 'false');
		this.textArea.setAttribute('aria-autocomplete', 'both');

A
Alex Dima 已提交
188 189
		StyleMutator.setTop(this.textArea, 0);
		StyleMutator.setLeft(this.textArea, 0);
E
Erich Gamma 已提交
190

A
Alex Dima 已提交
191 192
		this.listenersToDispose.push(dom.addDisposableListener(this.textArea, 'focus', () => this._setHasFocus(true)));
		this.listenersToDispose.push(dom.addDisposableListener(this.textArea, 'blur', () => this._setHasFocus(false)));
E
Erich Gamma 已提交
193 194 195 196 197

		// On top of the text area, we position a dom node to cover it up
		// (there have been reports of tiny blinking cursors)
		// (in WebKit the textarea is 1px by 1px because it cannot handle input to a 0x0 textarea)
		this.textAreaCover = document.createElement('div');
198
		if (this._context.configuration.editor.viewInfo.glyphMargin) {
A
Alex Dima 已提交
199
			this.textAreaCover.className = 'monaco-editor-background ' + editorBrowser.ClassNames.GLYPH_MARGIN + ' ' + editorBrowser.ClassNames.TEXTAREA_COVER;
E
Erich Gamma 已提交
200
		} else {
201
			if (this._context.configuration.editor.viewInfo.renderLineNumbers) {
A
Alex Dima 已提交
202
				this.textAreaCover.className = 'monaco-editor-background ' + editorBrowser.ClassNames.LINE_NUMBERS + ' ' + editorBrowser.ClassNames.TEXTAREA_COVER;
E
Erich Gamma 已提交
203
			} else {
A
Alex Dima 已提交
204
				this.textAreaCover.className = 'monaco-editor-background ' + editorBrowser.ClassNames.TEXTAREA_COVER;
E
Erich Gamma 已提交
205 206 207
			}
		}
		this.textAreaCover.style.position = 'absolute';
A
Alex Dima 已提交
208 209 210 211
		StyleMutator.setWidth(this.textAreaCover, 1);
		StyleMutator.setHeight(this.textAreaCover, 1);
		StyleMutator.setTop(this.textAreaCover, 0);
		StyleMutator.setLeft(this.textAreaCover, 0);
E
Erich Gamma 已提交
212 213 214 215 216 217
	}

	private createViewParts(): void {
		this.viewParts = [];

		// View Lines
218
		this.viewLines = new ViewLines(this._context, this.layoutProvider);
E
Erich Gamma 已提交
219 220

		// View Zones
221
		this.viewZones = new ViewZones(this._context, this.layoutProvider);
E
Erich Gamma 已提交
222 223 224
		this.viewParts.push(this.viewZones);

		// Decorations overview ruler
A
Alex Dima 已提交
225
		let decorationsOverviewRuler = new DecorationsOverviewRuler(
J
Johannes Rieken 已提交
226 227
			this._context, this.layoutProvider.getScrollHeight(),
			(lineNumber: number) => this.layoutProvider.getVerticalOffsetForLineNumber(lineNumber)
E
Erich Gamma 已提交
228 229 230 231
		);
		this.viewParts.push(decorationsOverviewRuler);


A
Alex Dima 已提交
232
		let scrollDecoration = new ScrollDecorationViewPart(this._context);
E
Erich Gamma 已提交
233 234
		this.viewParts.push(scrollDecoration);

A
Alex Dima 已提交
235
		let contentViewOverlays = new ContentViewOverlays(this._context, this.layoutProvider);
E
Erich Gamma 已提交
236
		this.viewParts.push(contentViewOverlays);
237 238 239
		contentViewOverlays.addDynamicOverlay(new CurrentLineHighlightOverlay(this._context, this.layoutProvider));
		contentViewOverlays.addDynamicOverlay(new SelectionsOverlay(this._context));
		contentViewOverlays.addDynamicOverlay(new DecorationsOverlay(this._context));
240
		contentViewOverlays.addDynamicOverlay(new IndentGuidesOverlay(this._context));
E
Erich Gamma 已提交
241

A
Alex Dima 已提交
242
		let marginViewOverlays = new MarginViewOverlays(this._context, this.layoutProvider);
E
Erich Gamma 已提交
243
		this.viewParts.push(marginViewOverlays);
244
		marginViewOverlays.addDynamicOverlay(new CurrentLineMarginHighlightOverlay(this._context, this.layoutProvider));
245
		marginViewOverlays.addDynamicOverlay(new GlyphMarginOverlay(this._context));
246
		marginViewOverlays.addDynamicOverlay(new MarginViewLineDecorationsOverlay(this._context));
247 248
		marginViewOverlays.addDynamicOverlay(new LinesDecorationsOverlay(this._context));
		marginViewOverlays.addDynamicOverlay(new LineNumbersOverlay(this._context));
E
Erich Gamma 已提交
249

250 251 252 253
		let margin = new Margin(this._context, this.layoutProvider);
		margin.domNode.appendChild(this.viewZones.marginDomNode);
		margin.domNode.appendChild(marginViewOverlays.getDomNode());
		this.viewParts.push(margin);
E
Erich Gamma 已提交
254 255

		// Content widgets
256
		this.contentWidgets = new ViewContentWidgets(this._context, this.domNode);
E
Erich Gamma 已提交
257 258
		this.viewParts.push(this.contentWidgets);

259 260
		this.viewCursors = new ViewCursors(this._context);
		this.viewParts.push(this.viewCursors);
E
Erich Gamma 已提交
261 262

		// Overlay widgets
263
		this.overlayWidgets = new ViewOverlayWidgets(this._context);
E
Erich Gamma 已提交
264 265
		this.viewParts.push(this.overlayWidgets);

A
Alex Dima 已提交
266
		let rulers = new Rulers(this._context, this.layoutProvider);
267 268
		this.viewParts.push(rulers);

E
Erich Gamma 已提交
269 270 271 272 273 274
		// -------------- Wire dom nodes up

		this.linesContentContainer = this.layoutProvider.getScrollbarContainerDomNode();
		this.linesContentContainer.style.position = 'absolute';

		if (decorationsOverviewRuler) {
A
Alex Dima 已提交
275
			let overviewRulerData = this.layoutProvider.getOverviewRulerInsertData();
E
Erich Gamma 已提交
276 277 278 279
			overviewRulerData.parent.insertBefore(decorationsOverviewRuler.getDomNode(), overviewRulerData.insertBefore);
		}

		this.linesContent.appendChild(contentViewOverlays.getDomNode());
280
		this.linesContent.appendChild(rulers.domNode);
E
Erich Gamma 已提交
281
		this.linesContent.appendChild(this.viewZones.domNode);
A
Alex Dima 已提交
282
		this.linesContent.appendChild(this.viewLines.getDomNode());
E
Erich Gamma 已提交
283
		this.linesContent.appendChild(this.contentWidgets.domNode);
284
		this.linesContent.appendChild(this.viewCursors.getDomNode());
285
		this.overflowGuardContainer.appendChild(margin.domNode);
E
Erich Gamma 已提交
286 287 288 289 290 291
		this.overflowGuardContainer.appendChild(this.linesContentContainer);
		this.overflowGuardContainer.appendChild(scrollDecoration.getDomNode());
		this.overflowGuardContainer.appendChild(this.overlayWidgets.domNode);
		this.overflowGuardContainer.appendChild(this.textArea);
		this.overflowGuardContainer.appendChild(this.textAreaCover);
		this.domNode.appendChild(this.overflowGuardContainer);
292
		this.domNode.appendChild(this.contentWidgets.overflowingContentWidgetsDomNode);
E
Erich Gamma 已提交
293 294 295 296 297 298 299
	}

	private _flushAccumulatedAndRenderNow(): void {
		this._flushAnyAccumulatedEvents();
		this._renderNow();
	}

300
	private createPointerHandlerHelper(): IPointerHandlerHelper {
E
Erich Gamma 已提交
301 302 303 304 305 306 307 308 309 310 311
		return {
			viewDomNode: this.domNode,
			linesContentDomNode: this.linesContent,

			focusTextArea: () => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.focusTextArea: View is disposed');
				}
				this.focus();
			},

312 313 314 315
			isDirty: (): boolean => {
				return (this.accumulatedModelEvents.length > 0);
			},

E
Erich Gamma 已提交
316 317 318 319 320 321
			getScrollLeft: () => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.getScrollLeft: View is disposed');
				}
				return this.layoutProvider.getScrollLeft();
			},
322 323 324 325 326 327 328
			getScrollTop: () => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.getScrollTop: View is disposed');
				}
				return this.layoutProvider.getScrollTop();
			},

J
Johannes Rieken 已提交
329
			setScrollPosition: (position: editorCommon.INewScrollPosition) => {
E
Erich Gamma 已提交
330
				if (this._isDisposed) {
331
					throw new Error('ViewImpl.pointerHandler.setScrollPosition: View is disposed');
E
Erich Gamma 已提交
332
				}
333
				this.layoutProvider.setScrollPosition(position);
E
Erich Gamma 已提交
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
			},

			isAfterLines: (verticalOffset: number) => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.isAfterLines: View is disposed');
				}
				return this.layoutProvider.isAfterLines(verticalOffset);
			},
			getLineNumberAtVerticalOffset: (verticalOffset: number) => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.getLineNumberAtVerticalOffset: View is disposed');
				}
				return this.layoutProvider.getLineNumberAtVerticalOffset(verticalOffset);
			},
			getVerticalOffsetForLineNumber: (lineNumber: number) => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.getVerticalOffsetForLineNumber: View is disposed');
				}
				return this.layoutProvider.getVerticalOffsetForLineNumber(lineNumber);
			},
			getWhitespaceAtVerticalOffset: (verticalOffset: number) => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.getWhitespaceAtVerticalOffset: View is disposed');
				}
				return this.layoutProvider.getWhitespaceAtVerticalOffset(verticalOffset);
			},
360 361 362 363 364 365
			getLastViewCursorsRenderData: () => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.getLastViewCursorsRenderData: View is disposed');
				}
				return this.viewCursors.getLastRenderData() || [];
			},
E
Erich Gamma 已提交
366 367 368 369 370 371
			shouldSuppressMouseDownOnViewZone: (viewZoneId: number) => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.shouldSuppressMouseDownOnViewZone: View is disposed');
				}
				return this.viewZones.shouldSuppressMouseDownOnViewZone(viewZoneId);
			},
372 373 374 375 376 377
			shouldSuppressMouseDownOnWidget: (widgetId: string) => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.shouldSuppressMouseDownOnWidget: View is disposed');
				}
				return this.contentWidgets.shouldSuppressMouseDownOnWidget(widgetId);
			},
E
Erich Gamma 已提交
378 379 380 381 382 383 384 385 386 387 388 389 390
			getPositionFromDOMInfo: (spanNode: HTMLElement, offset: number) => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.getPositionFromDOMInfo: View is disposed');
				}
				this._flushAccumulatedAndRenderNow();
				return this.viewLines.getPositionFromDOMInfo(spanNode, offset);
			},

			visibleRangeForPosition2: (lineNumber: number, column: number) => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.visibleRangeForPosition2: View is disposed');
				}
				this._flushAccumulatedAndRenderNow();
A
Alex Dima 已提交
391
				let visibleRanges = this.viewLines.visibleRangesForRange2(new Range(lineNumber, column, lineNumber, column), 0);
E
Erich Gamma 已提交
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
				if (!visibleRanges) {
					return null;
				}
				return visibleRanges[0];
			},

			getLineWidth: (lineNumber: number) => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.pointerHandler.getLineWidth: View is disposed');
				}
				this._flushAccumulatedAndRenderNow();
				return this.viewLines.getLineWidth(lineNumber);
			}
		};
	}

408
	private createKeyboardHandlerHelper(): IKeyboardHandlerHelper {
E
Erich Gamma 已提交
409 410 411 412 413 414 415 416
		return {
			viewDomNode: this.domNode,
			textArea: this.textArea,
			visibleRangeForPositionRelativeToEditor: (lineNumber: number, column: number) => {
				if (this._isDisposed) {
					throw new Error('ViewImpl.keyboardHandler.visibleRangeForPositionRelativeToEditor: View is disposed');
				}
				this._flushAccumulatedAndRenderNow();
A
Alex Dima 已提交
417 418
				let linesViewPortData = this.layoutProvider.getLinesViewportData();
				let visibleRanges = this.viewLines.visibleRangesForRange2(new Range(lineNumber, column, lineNumber, column), linesViewPortData.visibleRangesDeltaTop);
E
Erich Gamma 已提交
419 420 421 422
				if (!visibleRanges) {
					return null;
				}
				return visibleRanges[0];
423 424 425
			},
			flushAnyAccumulatedEvents: () => {
				this._flushAnyAccumulatedEvents();
E
Erich Gamma 已提交
426 427 428 429
			}
		};
	}

J
Johannes Rieken 已提交
430
	public setAriaActiveDescendant(id: string): void {
A
Alex Dima 已提交
431 432 433 434 435 436 437 438 439 440 441 442 443
		if (id) {
			this.textArea.setAttribute('role', 'combobox');
			if (this.textArea.getAttribute('aria-activedescendant') !== id) {
				this.textArea.setAttribute('aria-haspopup', 'true');
				this.textArea.setAttribute('aria-activedescendant', id);
			}
		} else {
			this.textArea.setAttribute('role', 'textbox');
			this.textArea.removeAttribute('aria-activedescendant');
			this.textArea.removeAttribute('aria-haspopup');
		}
	}

E
Erich Gamma 已提交
444 445
	// --- begin event handlers

J
Johannes Rieken 已提交
446
	public onLayoutChanged(layoutInfo: editorCommon.EditorLayoutInfo): boolean {
A
Alex Dima 已提交
447
		if (browser.isChrome) {
A
tslint  
Alex Dima 已提交
448
			/* tslint:disable:no-unused-variable */
E
Erich Gamma 已提交
449 450
			// Access overflowGuardContainer.clientWidth to prevent relayouting bug in Chrome
			// See Bug 19676: Editor misses a layout event
A
Alex Dima 已提交
451
			let clientWidth = this.overflowGuardContainer.clientWidth + 'px';
A
tslint  
Alex Dima 已提交
452
			/* tslint:enable:no-unused-variable */
E
Erich Gamma 已提交
453
		}
A
Alex Dima 已提交
454 455
		StyleMutator.setWidth(this.domNode, layoutInfo.width);
		StyleMutator.setHeight(this.domNode, layoutInfo.height);
E
Erich Gamma 已提交
456

A
Alex Dima 已提交
457 458
		StyleMutator.setWidth(this.overflowGuardContainer, layoutInfo.width);
		StyleMutator.setHeight(this.overflowGuardContainer, layoutInfo.height);
E
Erich Gamma 已提交
459

A
Alex Dima 已提交
460 461
		StyleMutator.setWidth(this.linesContent, 1000000);
		StyleMutator.setHeight(this.linesContent, 1000000);
E
Erich Gamma 已提交
462

A
Alex Dima 已提交
463 464 465
		StyleMutator.setLeft(this.linesContentContainer, layoutInfo.contentLeft);
		StyleMutator.setWidth(this.linesContentContainer, layoutInfo.contentWidth);
		StyleMutator.setHeight(this.linesContentContainer, layoutInfo.contentHeight);
E
Erich Gamma 已提交
466

A
Alex Dima 已提交
467
		this.outgoingEvents.emitViewLayoutChanged(layoutInfo);
E
Erich Gamma 已提交
468 469
		return false;
	}
A
Alex Dima 已提交
470
	public onConfigurationChanged(e: editorCommon.IConfigurationChangedEvent): boolean {
471 472
		if (e.viewInfo.editorClassName) {
			this.domNode.className = this._context.configuration.editor.viewInfo.editorClassName;
E
Erich Gamma 已提交
473
		}
474 475
		if (e.viewInfo.ariaLabel) {
			this.textArea.setAttribute('aria-label', this._context.configuration.editor.viewInfo.ariaLabel);
476
		}
E
Erich Gamma 已提交
477 478
		return false;
	}
J
Johannes Rieken 已提交
479
	public onScrollChanged(e: editorCommon.IScrollEvent): boolean {
A
Alex Dima 已提交
480
		this.outgoingEvents.emitScrollChanged(e);
481
		return false;
E
Erich Gamma 已提交
482
	}
J
Johannes Rieken 已提交
483
	public onViewFocusChanged(isFocused: boolean): boolean {
A
Alex Dima 已提交
484
		dom.toggleClass(this.domNode, 'focused', isFocused);
E
Erich Gamma 已提交
485
		if (isFocused) {
A
Alex Dima 已提交
486
			this.outgoingEvents.emitViewFocusGained();
E
Erich Gamma 已提交
487
		} else {
A
Alex Dima 已提交
488
			this.outgoingEvents.emitViewFocusLost();
E
Erich Gamma 已提交
489 490 491
		}
		return false;
	}
492 493 494 495 496 497 498 499 500 501 502 503 504

	public onCursorRevealRange(e: editorCommon.IViewRevealRangeEvent): boolean {
		return e.revealCursor ? this.revealCursor() : false;
	}

	public onCursorScrollRequest(e: editorCommon.ICursorScrollRequestEvent): boolean {
		return e.revealCursor ? this.revealCursor() : false;
	}

	private revealCursor(): boolean {
		this.triggerCursorHandler('revealCursor', editorCommon.Handler.CursorMove, { to: editorCommon.CursorMovePosition.ViewPortIfOutside });
		return false;
	}
E
Erich Gamma 已提交
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
	// --- end event handlers

	public dispose(): void {
		this._isDisposed = true;
		if (this.handleAccumulatedModelEventsTimeout !== -1) {
			clearTimeout(this.handleAccumulatedModelEventsTimeout);
			this.handleAccumulatedModelEventsTimeout = -1;
		}
		if (this._renderAnimationFrame !== null) {
			this._renderAnimationFrame.dispose();
			this._renderAnimationFrame = null;
		}
		this.accumulatedModelEvents = [];

		this.eventDispatcher.removeEventHandler(this);
A
Alex Dima 已提交
520
		this.outgoingEvents.dispose();
A
Alex Dima 已提交
521
		this.listenersToRemove = dispose(this.listenersToRemove);
J
Joao Moreno 已提交
522
		this.listenersToDispose = dispose(this.listenersToDispose);
E
Erich Gamma 已提交
523 524 525 526 527 528 529

		this.keyboardHandler.dispose();
		this.pointerHandler.dispose();

		this.viewLines.dispose();

		// Destroy IViewPart second
A
Alex Dima 已提交
530
		for (let i = 0, len = this.viewParts.length; i < len; i++) {
E
Erich Gamma 已提交
531 532 533 534 535 536 537 538 539
			this.viewParts[i].dispose();
		}
		this.viewParts = [];

		this.layoutProvider.dispose();
	}

	// --- begin Code Editor APIs

J
Johannes Rieken 已提交
540
	private codeEditorHelper: editorBrowser.ICodeEditorHelper;
A
Alex Dima 已提交
541
	public getCodeEditorHelper(): editorBrowser.ICodeEditorHelper {
E
Erich Gamma 已提交
542 543
		if (!this.codeEditorHelper) {
			this.codeEditorHelper = {
544
				getScrollWidth: () => {
E
Erich Gamma 已提交
545
					if (this._isDisposed) {
546
						throw new Error('ViewImpl.codeEditorHelper.getScrollWidth: View is disposed');
E
Erich Gamma 已提交
547
					}
548
					return this.layoutProvider.getScrollWidth();
E
Erich Gamma 已提交
549 550 551 552 553 554 555
				},
				getScrollLeft: () => {
					if (this._isDisposed) {
						throw new Error('ViewImpl.codeEditorHelper.getScrollLeft: View is disposed');
					}
					return this.layoutProvider.getScrollLeft();
				},
556

E
Erich Gamma 已提交
557 558 559 560 561 562
				getScrollHeight: () => {
					if (this._isDisposed) {
						throw new Error('ViewImpl.codeEditorHelper.getScrollHeight: View is disposed');
					}
					return this.layoutProvider.getScrollHeight();
				},
563
				getScrollTop: () => {
E
Erich Gamma 已提交
564
					if (this._isDisposed) {
565
						throw new Error('ViewImpl.codeEditorHelper.getScrollTop: View is disposed');
E
Erich Gamma 已提交
566
					}
567
					return this.layoutProvider.getScrollTop();
E
Erich Gamma 已提交
568
				},
569

J
Johannes Rieken 已提交
570
				setScrollPosition: (position: editorCommon.INewScrollPosition) => {
571 572 573 574 575 576
					if (this._isDisposed) {
						throw new Error('ViewImpl.codeEditorHelper.setScrollPosition: View is disposed');
					}
					this.layoutProvider.setScrollPosition(position);
				},

J
Johannes Rieken 已提交
577
				getVerticalOffsetForPosition: (modelLineNumber: number, modelColumn: number) => {
E
Erich Gamma 已提交
578 579 580
					if (this._isDisposed) {
						throw new Error('ViewImpl.codeEditorHelper.getVerticalOffsetForPosition: View is disposed');
					}
A
Alex Dima 已提交
581
					let modelPosition = this._context.model.validateModelPosition({
E
Erich Gamma 已提交
582 583 584
						lineNumber: modelLineNumber,
						column: modelColumn
					});
A
Alex Dima 已提交
585
					let viewPosition = this._context.model.convertModelPositionToViewPosition(modelPosition.lineNumber, modelPosition.column);
E
Erich Gamma 已提交
586 587 588 589 590 591 592 593 594 595 596 597
					return this.layoutProvider.getVerticalOffsetForLineNumber(viewPosition.lineNumber);
				},
				delegateVerticalScrollbarMouseDown: (browserEvent: MouseEvent) => {
					if (this._isDisposed) {
						throw new Error('ViewImpl.codeEditorHelper.delegateVerticalScrollbarMouseDown: View is disposed');
					}
					this.layoutProvider.delegateVerticalScrollbarMouseDown(browserEvent);
				},
				getOffsetForColumn: (modelLineNumber: number, modelColumn: number) => {
					if (this._isDisposed) {
						throw new Error('ViewImpl.codeEditorHelper.getOffsetForColumn: View is disposed');
					}
A
Alex Dima 已提交
598
					let modelPosition = this._context.model.validateModelPosition({
E
Erich Gamma 已提交
599 600 601
						lineNumber: modelLineNumber,
						column: modelColumn
					});
A
Alex Dima 已提交
602
					let viewPosition = this._context.model.convertModelPositionToViewPosition(modelPosition.lineNumber, modelPosition.column);
E
Erich Gamma 已提交
603
					this._flushAccumulatedAndRenderNow();
A
Alex Dima 已提交
604
					let visibleRanges = this.viewLines.visibleRangesForRange2(new Range(viewPosition.lineNumber, viewPosition.column, viewPosition.lineNumber, viewPosition.column), 0);
E
Erich Gamma 已提交
605 606 607 608
					if (!visibleRanges) {
						return -1;
					}
					return visibleRanges[0].left;
609 610 611 612 613 614 615
				},

				getTargetAtClientPoint: (clientX: number, clientY: number): editorBrowser.IMouseTarget => {
					if (this._isDisposed) {
						throw new Error('ViewImpl.codeEditorHelper.getTargetAtClientPoint: View is disposed');
					}
					return this.pointerHandler.getTargetAtClientPoint(clientX, clientY);
E
Erich Gamma 已提交
616
				}
617

E
Erich Gamma 已提交
618 619 620 621 622
			};
		}
		return this.codeEditorHelper;
	}

623
	public getCenteredRangeInViewport(): Range {
E
Erich Gamma 已提交
624 625 626
		if (this._isDisposed) {
			throw new Error('ViewImpl.getCenteredRangeInViewport: View is disposed');
		}
A
Alex Dima 已提交
627 628 629
		let viewLineNumber = this.layoutProvider.getCenteredViewLineNumberInViewport();
		let viewModel = this._context.model;
		let currentCenteredViewRange = new Range(viewLineNumber, 1, viewLineNumber, viewModel.getLineMaxColumn(viewLineNumber));
E
Erich Gamma 已提交
630 631 632
		return viewModel.convertViewRangeToModelRange(currentCenteredViewRange);
	}

633
	public getCompletelyVisibleLinesRangeInViewport(): Range {
634
		if (this._isDisposed) {
635
			throw new Error('ViewImpl.getVisibleRangeInViewportExcludingPartialRenderedLines: View is disposed');
636
		}
637 638
		let completelyVisibleLinesRange = this.layoutProvider.getLinesViewportData().completelyVisibleLinesRange;
		return this._context.model.convertViewRangeToModelRange(completelyVisibleLinesRange);
639 640
	}

J
Johannes Rieken 已提交
641 642 643
	//	public getLineInfoProvider():view.ILineInfoProvider {
	//		return this.viewLines;
	//	}
E
Erich Gamma 已提交
644

A
Alex Dima 已提交
645
	public getInternalEventBus(): IEventEmitter {
E
Erich Gamma 已提交
646 647 648
		if (this._isDisposed) {
			throw new Error('ViewImpl.getInternalEventBus: View is disposed');
		}
A
Alex Dima 已提交
649
		return this.outgoingEvents.getInternalEventBus();
E
Erich Gamma 已提交
650 651
	}

A
Alex Dima 已提交
652
	public saveState(): editorCommon.IViewState {
E
Erich Gamma 已提交
653 654 655 656 657 658
		if (this._isDisposed) {
			throw new Error('ViewImpl.saveState: View is disposed');
		}
		return this.layoutProvider.saveState();
	}

A
Alex Dima 已提交
659
	public restoreState(state: editorCommon.IViewState): void {
E
Erich Gamma 已提交
660 661 662 663 664 665 666 667 668 669 670
		if (this._isDisposed) {
			throw new Error('ViewImpl.restoreState: View is disposed');
		}
		this._flushAnyAccumulatedEvents();
		return this.layoutProvider.restoreState(state);
	}

	public focus(): void {
		if (this._isDisposed) {
			throw new Error('ViewImpl.focus: View is disposed');
		}
671
		this.keyboardHandler.focusTextArea();
E
Erich Gamma 已提交
672 673

		// IE does not trigger the focus event immediately, so we must help it a little bit
674 675 676
		if (document.activeElement === this.textArea) {
			this._setHasFocus(true);
		}
E
Erich Gamma 已提交
677 678 679 680 681 682 683 684 685 686 687 688 689 690
	}

	public isFocused(): boolean {
		if (this._isDisposed) {
			throw new Error('ViewImpl.isFocused: View is disposed');
		}
		return this.hasFocus;
	}

	public createOverviewRuler(cssClassName: string, minimumHeight: number, maximumHeight: number): OverviewRuler {
		if (this._isDisposed) {
			throw new Error('ViewImpl.createOverviewRuler: View is disposed');
		}
		return new OverviewRuler(
J
Johannes Rieken 已提交
691 692
			this._context, cssClassName, this.layoutProvider.getScrollHeight(), minimumHeight, maximumHeight,
			(lineNumber: number) => this.layoutProvider.getVerticalOffsetForLineNumber(lineNumber)
E
Erich Gamma 已提交
693 694 695
		);
	}

A
Alex Dima 已提交
696
	public change(callback: (changeAccessor: editorBrowser.IViewZoneChangeAccessor) => any): boolean {
E
Erich Gamma 已提交
697 698 699
		if (this._isDisposed) {
			throw new Error('ViewImpl.change: View is disposed');
		}
A
Alex Dima 已提交
700
		let zonesHaveChanged = false;
A
Alex Dima 已提交
701

E
Erich Gamma 已提交
702 703 704
		this._renderOnce(() => {
			// Handle events to avoid "adjusting" newly inserted view zones
			this._flushAnyAccumulatedEvents();
A
Alex Dima 已提交
705
			let changeAccessor: editorBrowser.IViewZoneChangeAccessor = {
J
Johannes Rieken 已提交
706
				addZone: (zone: editorBrowser.IViewZone): number => {
E
Erich Gamma 已提交
707 708 709
					zonesHaveChanged = true;
					return this.viewZones.addZone(zone);
				},
J
Johannes Rieken 已提交
710
				removeZone: (id: number): void => {
711 712 713
					if (!id) {
						return;
					}
E
Erich Gamma 已提交
714 715 716
					zonesHaveChanged = this.viewZones.removeZone(id) || zonesHaveChanged;
				},
				layoutZone: (id: number): void => {
717 718 719
					if (!id) {
						return;
					}
E
Erich Gamma 已提交
720 721 722 723
					zonesHaveChanged = this.viewZones.layoutZone(id) || zonesHaveChanged;
				}
			};

A
Alex Dima 已提交
724
			let r: any = safeInvoke1Arg(callback, changeAccessor);
E
Erich Gamma 已提交
725 726 727 728 729 730

			// Invalidate changeAccessor
			changeAccessor.addZone = null;
			changeAccessor.removeZone = null;

			if (zonesHaveChanged) {
731
				this._context.privateViewEventBus.emit(editorCommon.EventType.ViewZonesChanged, null);
E
Erich Gamma 已提交
732 733 734 735 736 737 738
			}

			return r;
		});
		return zonesHaveChanged;
	}

J
Johannes Rieken 已提交
739
	public getWhitespaces(): editorCommon.IEditorWhitespace[] {
E
Erich Gamma 已提交
740 741 742 743 744 745
		if (this._isDisposed) {
			throw new Error('ViewImpl.getWhitespaces: View is disposed');
		}
		return this.layoutProvider.getWhitespaces();
	}

A
Alex Dima 已提交
746
	public addContentWidget(widgetData: editorBrowser.IContentWidgetData): void {
E
Erich Gamma 已提交
747 748 749
		if (this._isDisposed) {
			throw new Error('ViewImpl.addContentWidget: View is disposed');
		}
A
Alex Dima 已提交
750 751 752
		this.contentWidgets.addWidget(widgetData.widget);
		this.layoutContentWidget(widgetData);
		this._scheduleRender();
E
Erich Gamma 已提交
753 754
	}

A
Alex Dima 已提交
755
	public layoutContentWidget(widgetData: editorBrowser.IContentWidgetData): void {
E
Erich Gamma 已提交
756 757 758
		if (this._isDisposed) {
			throw new Error('ViewImpl.layoutContentWidget: View is disposed');
		}
759

A
Alex Dima 已提交
760 761 762 763
		let newPosition = widgetData.position ? widgetData.position.position : null;
		let newPreference = widgetData.position ? widgetData.position.preference : null;
		this.contentWidgets.setWidgetPosition(widgetData.widget, newPosition, newPreference);
		this._scheduleRender();
E
Erich Gamma 已提交
764 765
	}

A
Alex Dima 已提交
766
	public removeContentWidget(widgetData: editorBrowser.IContentWidgetData): void {
E
Erich Gamma 已提交
767 768 769
		if (this._isDisposed) {
			throw new Error('ViewImpl.removeContentWidget: View is disposed');
		}
A
Alex Dima 已提交
770 771
		this.contentWidgets.removeWidget(widgetData.widget);
		this._scheduleRender();
E
Erich Gamma 已提交
772 773
	}

A
Alex Dima 已提交
774
	public addOverlayWidget(widgetData: editorBrowser.IOverlayWidgetData): void {
E
Erich Gamma 已提交
775 776 777
		if (this._isDisposed) {
			throw new Error('ViewImpl.addOverlayWidget: View is disposed');
		}
A
Alex Dima 已提交
778 779 780
		this.overlayWidgets.addWidget(widgetData.widget);
		this.layoutOverlayWidget(widgetData);
		this._scheduleRender();
E
Erich Gamma 已提交
781 782
	}

A
Alex Dima 已提交
783
	public layoutOverlayWidget(widgetData: editorBrowser.IOverlayWidgetData): void {
E
Erich Gamma 已提交
784 785 786
		if (this._isDisposed) {
			throw new Error('ViewImpl.layoutOverlayWidget: View is disposed');
		}
787 788 789 790 791 792

		let newPreference = widgetData.position ? widgetData.position.preference : null;
		let shouldRender = this.overlayWidgets.setWidgetPosition(widgetData.widget, newPreference);
		if (shouldRender) {
			this._scheduleRender();
		}
E
Erich Gamma 已提交
793 794
	}

A
Alex Dima 已提交
795
	public removeOverlayWidget(widgetData: editorBrowser.IOverlayWidgetData): void {
E
Erich Gamma 已提交
796 797 798
		if (this._isDisposed) {
			throw new Error('ViewImpl.removeOverlayWidget: View is disposed');
		}
A
Alex Dima 已提交
799 800
		this.overlayWidgets.removeWidget(widgetData.widget);
		this._scheduleRender();
E
Erich Gamma 已提交
801 802
	}

J
Johannes Rieken 已提交
803
	public render(now: boolean, everything: boolean): void {
E
Erich Gamma 已提交
804 805 806
		if (this._isDisposed) {
			throw new Error('ViewImpl.render: View is disposed');
		}
807 808 809 810
		if (everything) {
			// Force a render with a layout event
			this.layoutProvider.emitLayoutChangedEvent();
		}
811 812 813
		if (now) {
			this._flushAccumulatedAndRenderNow();
		}
E
Erich Gamma 已提交
814 815 816 817 818 819 820 821
	}

	// --- end Code Editor APIs

	private _renderOnce(callback: () => any): any {
		if (this._isDisposed) {
			throw new Error('ViewImpl._renderOnce: View is disposed');
		}
A
Alex Dima 已提交
822
		return this.outgoingEvents.deferredEmit(() => {
A
Alex Dima 已提交
823 824
			let r = safeInvokeNoArg(callback);
			this._scheduleRender();
E
Erich Gamma 已提交
825 826 827 828 829 830 831 832 833
			return r;
		});
	}

	private _scheduleRender(): void {
		if (this._isDisposed) {
			throw new Error('ViewImpl._scheduleRender: View is disposed');
		}
		if (this._renderAnimationFrame === null) {
A
Alex Dima 已提交
834
			this._renderAnimationFrame = dom.runAtThisOrScheduleAtNextAnimationFrame(this._onRenderScheduled.bind(this), 100);
E
Erich Gamma 已提交
835 836 837 838 839 840 841 842 843
		}
	}

	private _onRenderScheduled(): void {
		this._renderAnimationFrame = null;
		this._flushAccumulatedAndRenderNow();
	}

	private _renderNow(): void {
A
Alex Dima 已提交
844
		safeInvokeNoArg(() => this._actualRender());
E
Erich Gamma 已提交
845 846
	}

847
	private _getViewPartsToRender(): ViewPart[] {
J
Johannes Rieken 已提交
848
		let result: ViewPart[] = [];
849 850 851 852 853 854 855 856 857
		for (let i = 0, len = this.viewParts.length; i < len; i++) {
			let viewPart = this.viewParts[i];
			if (viewPart.shouldRender()) {
				result.push(viewPart);
			}
		}
		return result;
	}

A
Alex Dima 已提交
858
	private _actualRender(): void {
A
Alex Dima 已提交
859
		if (!dom.isInDOM(this.domNode)) {
E
Erich Gamma 已提交
860 861 862
			return;
		}

863
		let viewPartsToRender = this._getViewPartsToRender();
E
Erich Gamma 已提交
864

A
Alex Dima 已提交
865 866
		if (!this.viewLines.shouldRender() && viewPartsToRender.length === 0) {
			// Nothing to render
867
			this.keyboardHandler.writeToTextArea();
A
Alex Dima 已提交
868 869
			return;
		}
E
Erich Gamma 已提交
870

A
Alex Dima 已提交
871
		let linesViewportData = this.layoutProvider.getLinesViewportData();
E
Erich Gamma 已提交
872

A
Alex Dima 已提交
873
		if (this.viewLines.shouldRender()) {
874 875 876
			this.viewLines.renderText(linesViewportData, () => {
				this.keyboardHandler.writeToTextArea();
			});
A
Alex Dima 已提交
877
			this.viewLines.onDidRender();
878 879 880

			// Rendering of viewLines might cause scroll events to occur, so collect view parts to render again
			viewPartsToRender = this._getViewPartsToRender();
881 882
		} else {
			this.keyboardHandler.writeToTextArea();
A
Alex Dima 已提交
883
		}
E
Erich Gamma 已提交
884

A
Alex Dima 已提交
885
		let renderingContext = new RenderingContext(this.viewLines, this.layoutProvider, linesViewportData);
A
Alex Dima 已提交
886

A
Alex Dima 已提交
887 888 889 890 891
		// Render the rest of the parts
		for (let i = 0, len = viewPartsToRender.length; i < len; i++) {
			let viewPart = viewPartsToRender[i];
			viewPart.prepareRender(renderingContext);
		}
A
Alex Dima 已提交
892

A
Alex Dima 已提交
893 894 895 896
		for (let i = 0, len = viewPartsToRender.length; i < len; i++) {
			let viewPart = viewPartsToRender[i];
			viewPart.render(renderingContext);
			viewPart.onDidRender();
E
Erich Gamma 已提交
897 898
		}

899 900
		// Render the scrollbar
		this.layoutProvider.renderScrollbar();
E
Erich Gamma 已提交
901 902
	}

J
Johannes Rieken 已提交
903
	private _setHasFocus(newHasFocus: boolean): void {
E
Erich Gamma 已提交
904 905
		if (this.hasFocus !== newHasFocus) {
			this.hasFocus = newHasFocus;
906
			this._context.privateViewEventBus.emit(editorCommon.EventType.ViewFocusChanged, this.hasFocus);
E
Erich Gamma 已提交
907 908 909 910
		}
	}
}

J
Johannes Rieken 已提交
911
function safeInvokeNoArg(func: Function): any {
A
Alex Dima 已提交
912 913
	try {
		return func();
J
Johannes Rieken 已提交
914
	} catch (e) {
A
Alex Dima 已提交
915 916 917 918
		onUnexpectedError(e);
	}
}

J
Johannes Rieken 已提交
919
function safeInvoke1Arg(func: Function, arg1: any): any {
A
Alex Dima 已提交
920 921
	try {
		return func(arg1);
J
Johannes Rieken 已提交
922
	} catch (e) {
A
Alex Dima 已提交
923 924 925
		onUnexpectedError(e);
	}
}