Skip to content

Commit 73d151d

Browse files
committed
Adopt TypeScript's readonly in editor API
1 parent 54c152f commit 73d151d

26 files changed

Lines changed: 857 additions & 857 deletions

build/monaco/monaco.d.ts.recipe

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ declare module monaco {
2424
*/
2525
export class Emitter<T> {
2626
constructor();
27-
event: Event<T>;
27+
readonly event: Event<T>;
2828
fire(event?: T): void;
2929
dispose(): void;
3030
}
@@ -43,8 +43,7 @@ declare module monaco {
4343
#include(vs/base/common/htmlContent): MarkedString
4444
#include(vs/base/browser/keyboardEvent): IKeyboardEvent
4545
#include(vs/base/browser/mouseEvent): IMouseEvent
46-
#include(vs/editor/common/editorCommon): IScrollEvent
47-
#include(vs/editor/common/editorCommon): IPosition, IRange, ISelection
46+
#include(vs/editor/common/editorCommon): IScrollEvent, IPosition, IRange, ISelection
4847
#include(vs/editor/common/core/position): Position
4948
#include(vs/editor/common/core/range): Range
5049
#include(vs/editor/common/core/selection): Selection, SelectionDirection
@@ -63,7 +62,6 @@ export interface ICommandHandler {
6362
#include(vs/platform/markers/common/markers): IMarkerData
6463
#include(vs/editor/browser/standalone/colorizer): IColorizerOptions, IColorizerElementOptions
6564
#include(vs/base/common/scrollable): ScrollbarVisibility
66-
#include(vs/base/common/actions): IAction
6765
#includeAll(vs/editor/common/editorCommon;IMode=>languages.IMode): IPosition, IRange, ISelection, SelectionDirection, IScrollEvent
6866
#includeAll(vs/editor/browser/editorBrowser;editorCommon.=>):
6967
}

src/vs/base/browser/keyboardEvent.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ export function setExtractKeyCode(newExtractKeyCode: (e: KeyboardEvent) => KeyCo
166166
}
167167

168168
export interface IKeyboardEvent {
169-
browserEvent: KeyboardEvent;
170-
target: HTMLElement;
169+
readonly browserEvent: KeyboardEvent;
170+
readonly target: HTMLElement;
171171

172-
ctrlKey: boolean;
173-
shiftKey: boolean;
174-
altKey: boolean;
175-
metaKey: boolean;
176-
keyCode: KeyCode;
172+
readonly ctrlKey: boolean;
173+
readonly shiftKey: boolean;
174+
readonly altKey: boolean;
175+
readonly metaKey: boolean;
176+
readonly keyCode: KeyCode;
177177

178178
asKeybinding(): number;
179179
equals(keybinding: number): boolean;
@@ -189,14 +189,14 @@ const metaKeyMod = (platform.isMacintosh ? KeyMod.CtrlCmd : KeyMod.WinCtrl);
189189

190190
export class StandardKeyboardEvent implements IKeyboardEvent {
191191

192-
public browserEvent: KeyboardEvent;
193-
public target: HTMLElement;
192+
public readonly browserEvent: KeyboardEvent;
193+
public readonly target: HTMLElement;
194194

195-
public ctrlKey: boolean;
196-
public shiftKey: boolean;
197-
public altKey: boolean;
198-
public metaKey: boolean;
199-
public keyCode: KeyCode;
195+
public readonly ctrlKey: boolean;
196+
public readonly shiftKey: boolean;
197+
public readonly altKey: boolean;
198+
public readonly metaKey: boolean;
199+
public readonly keyCode: KeyCode;
200200

201201
private _asKeybinding: number;
202202

src/vs/base/browser/mouseEvent.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,40 @@ import * as browser from 'vs/base/browser/browser';
99
import { IframeUtils } from 'vs/base/browser/iframe';
1010

1111
export interface IMouseEvent {
12-
browserEvent: MouseEvent;
13-
leftButton: boolean;
14-
middleButton: boolean;
15-
rightButton: boolean;
16-
target: HTMLElement;
17-
detail: number;
18-
posx: number;
19-
posy: number;
20-
ctrlKey: boolean;
21-
shiftKey: boolean;
22-
altKey: boolean;
23-
metaKey: boolean;
24-
timestamp: number;
12+
readonly browserEvent: MouseEvent;
13+
readonly leftButton: boolean;
14+
readonly middleButton: boolean;
15+
readonly rightButton: boolean;
16+
readonly target: HTMLElement;
17+
readonly detail: number;
18+
readonly posx: number;
19+
readonly posy: number;
20+
readonly ctrlKey: boolean;
21+
readonly shiftKey: boolean;
22+
readonly altKey: boolean;
23+
readonly metaKey: boolean;
24+
readonly timestamp: number;
2525

2626
preventDefault(): void;
2727
stopPropagation(): void;
2828
}
2929

3030
export class StandardMouseEvent implements IMouseEvent {
3131

32-
public browserEvent: MouseEvent;
32+
public readonly browserEvent: MouseEvent;
3333

34-
public leftButton: boolean;
35-
public middleButton: boolean;
36-
public rightButton: boolean;
37-
public target: HTMLElement;
34+
public readonly leftButton: boolean;
35+
public readonly middleButton: boolean;
36+
public readonly rightButton: boolean;
37+
public readonly target: HTMLElement;
3838
public detail: number;
39-
public posx: number;
40-
public posy: number;
41-
public ctrlKey: boolean;
42-
public shiftKey: boolean;
43-
public altKey: boolean;
44-
public metaKey: boolean;
45-
public timestamp: number;
39+
public readonly posx: number;
40+
public readonly posy: number;
41+
public readonly ctrlKey: boolean;
42+
public readonly shiftKey: boolean;
43+
public readonly altKey: boolean;
44+
public readonly metaKey: boolean;
45+
public readonly timestamp: number;
4646

4747
constructor(e: MouseEvent) {
4848
this.timestamp = Date.now();
@@ -105,7 +105,7 @@ export interface IDataTransfer {
105105

106106
export class DragMouseEvent extends StandardMouseEvent {
107107

108-
public dataTransfer: IDataTransfer;
108+
public readonly dataTransfer: IDataTransfer;
109109

110110
constructor(e: MouseEvent) {
111111
super(e);
@@ -136,10 +136,10 @@ interface IGeckoMouseWheelEvent {
136136

137137
export class StandardMouseWheelEvent {
138138

139-
public browserEvent: MouseWheelEvent;
140-
public deltaY: number;
141-
public deltaX: number;
142-
public target: Node;
139+
public readonly browserEvent: MouseWheelEvent;
140+
public readonly deltaY: number;
141+
public readonly deltaX: number;
142+
public readonly target: Node;
143143

144144
constructor(e: MouseWheelEvent, deltaX: number = 0, deltaY: number = 0) {
145145

src/vs/base/common/cancellation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import Event, { Emitter } from 'vs/base/common/event';
99

1010
export interface CancellationToken {
11-
isCancellationRequested: boolean;
11+
readonly isCancellationRequested: boolean;
1212
/**
1313
* An event emitted when cancellation is requested
1414
* @event
1515
*/
16-
onCancellationRequested: Event<any>;
16+
readonly onCancellationRequested: Event<any>;
1717
}
1818

1919
const shortcutEvent: Event<any> = Object.freeze(function (callback, context?) {

src/vs/base/common/htmlContent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* or a code-block that provides a language and a code snippet. Note that
1111
* markdown strings will be sanitized - that means html will be escaped.
1212
*/
13-
export type MarkedString = string | { language: string; value: string };
13+
export type MarkedString = string | { readonly language: string; readonly value: string };
1414

1515
export interface IHTMLContentElementCode {
1616
language: string;

src/vs/base/test/common/cancellation.test.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,6 @@ suite('CancellationToken', function () {
1414
assert.equal(typeof CancellationToken.None.onCancellationRequested, 'function');
1515
});
1616

17-
test('defaults cannot be messed with', function () {
18-
19-
assert.throws(function () {
20-
CancellationToken.Cancelled.isCancellationRequested = false;
21-
});
22-
23-
assert.throws(function () {
24-
CancellationToken.Cancelled.onCancellationRequested = null;
25-
});
26-
27-
assert.throws(function () {
28-
CancellationToken.None.isCancellationRequested = false;
29-
});
30-
31-
assert.throws(function () {
32-
CancellationToken.None.onCancellationRequested = null;
33-
});
34-
});
35-
36-
3717
test('cancel before token', function (done) {
3818

3919
var source = new CancellationTokenSource();

src/vs/editor/browser/config/configuration.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,16 @@ class CSSBasedConfiguration extends Disposable {
106106

107107
if (readConfig.typicalHalfwidthCharacterWidth <= 2 || readConfig.typicalFullwidthCharacterWidth <= 2 || readConfig.spaceWidth <= 2 || readConfig.maxDigitWidth <= 2) {
108108
// Hey, it's Bug 14341 ... we couldn't read
109-
readConfig.typicalHalfwidthCharacterWidth = Math.max(readConfig.typicalHalfwidthCharacterWidth, 5);
110-
readConfig.typicalFullwidthCharacterWidth = Math.max(readConfig.typicalFullwidthCharacterWidth, 5);
111-
readConfig.spaceWidth = Math.max(readConfig.spaceWidth, 5);
112-
readConfig.maxDigitWidth = Math.max(readConfig.maxDigitWidth, 5);
109+
readConfig = new FontInfo({
110+
fontFamily: readConfig.fontFamily,
111+
fontWeight: readConfig.fontWeight,
112+
fontSize: readConfig.fontSize,
113+
lineHeight: readConfig.lineHeight,
114+
typicalHalfwidthCharacterWidth: Math.max(readConfig.typicalHalfwidthCharacterWidth, 5),
115+
typicalFullwidthCharacterWidth: Math.max(readConfig.typicalFullwidthCharacterWidth, 5),
116+
spaceWidth: Math.max(readConfig.spaceWidth, 5),
117+
maxDigitWidth: Math.max(readConfig.maxDigitWidth, 5),
118+
});
113119
this._installChangeMonitor();
114120
}
115121

src/vs/editor/browser/editorBrowser.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,34 +352,34 @@ export interface IMouseTarget {
352352
/**
353353
* The target element
354354
*/
355-
element: Element;
355+
readonly element: Element;
356356
/**
357357
* The target type
358358
*/
359-
type: editorCommon.MouseTargetType;
359+
readonly type: editorCommon.MouseTargetType;
360360
/**
361361
* The 'approximate' editor position
362362
*/
363-
position: Position;
363+
readonly position: Position;
364364
/**
365365
* Desired mouse column (e.g. when position.column gets clamped to text length -- clicking after text on a line).
366366
*/
367-
mouseColumn: number;
367+
readonly mouseColumn: number;
368368
/**
369369
* The 'approximate' editor range
370370
*/
371-
range: Range;
371+
readonly range: Range;
372372
/**
373373
* Some extra detail.
374374
*/
375-
detail: any;
375+
readonly detail: any;
376376
}
377377
/**
378378
* A mouse event originating from the editor.
379379
*/
380380
export interface IEditorMouseEvent {
381-
event: IMouseEvent;
382-
target: IMouseTarget;
381+
readonly event: IMouseEvent;
382+
readonly target: IMouseTarget;
383383
}
384384

385385
/**

src/vs/editor/browser/standalone/standaloneEditor.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ export interface IDiffNavigator {
110110
}
111111

112112
export interface IDiffNavigatorOptions {
113-
followsCaret?: boolean;
114-
ignoreCharChanges?: boolean;
115-
alwaysRevealFirst?: boolean;
113+
readonly followsCaret?: boolean;
114+
readonly ignoreCharChanges?: boolean;
115+
readonly alwaysRevealFirst?: boolean;
116116
}
117117

118118
export function createDiffNavigator(diffEditor: IStandaloneDiffEditor, opts?: IDiffNavigatorOptions): IDiffNavigator {
@@ -192,7 +192,7 @@ export function onWillDisposeModel(listener: (model: IModel) => void): IDisposab
192192
* Emitted when a different language is set to a model.
193193
* @event
194194
*/
195-
export function onDidChangeModelLanguage(listener: (e: { model: IModel; oldLanguage: string; }) => void): IDisposable {
195+
export function onDidChangeModelLanguage(listener: (e: { readonly model: IModel; readonly oldLanguage: string; }) => void): IDisposable {
196196
return StaticServices.modelService.get().onModelModeChanged((e) => {
197197
listener({
198198
model: e.model,
@@ -290,6 +290,7 @@ export function createMonacoEditorAPI(): typeof monaco.editor {
290290
EditorLayoutInfo: <any>editorCommon.EditorLayoutInfo,
291291
BareFontInfo: <any>editorCommon.BareFontInfo,
292292
FontInfo: <any>editorCommon.FontInfo,
293+
TextModelResolvedOptions: <any>editorCommon.TextModelResolvedOptions,
293294

294295
// vars
295296
EditorType: editorCommon.EditorType,

src/vs/editor/browser/standalone/standaloneLanguages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export interface CodeActionContext {
222222
*
223223
* @readonly
224224
*/
225-
markers: IMarkerData[];
225+
readonly markers: IMarkerData[];
226226
}
227227

228228
/**

0 commit comments

Comments
 (0)