forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.ts
More file actions
50 lines (45 loc) · 1.46 KB
/
event.ts
File metadata and controls
50 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// tslint:disable: no-any
export type Event<T> = (listener: (e?: T) => any) => void;
// Simpler version of the vscode event emitter for passing down through react components.
// Easier to manage than forwarding refs when not sure what the type of the ref should be.
//
// We can't use the vscode version because pulling in vscode apis is not allowed in a webview
export class EventEmitter<T> {
private _event: Event<T> | undefined;
private _listeners: Set<(e?: T) => any> = new Set<(e?: T) => any>();
public get event(): Event<T> {
if (!this._event) {
this._event = (listener: (e?: T) => any): void => {
this._listeners.add(listener);
};
}
return this._event;
}
public fire(data?: T): void {
this._listeners.forEach(c => c(data));
}
public dispose(): void {
this._listeners.clear();
}
}
export interface IKeyboardEvent {
readonly code: string;
readonly target: HTMLElement;
readonly ctrlKey: boolean;
readonly shiftKey: boolean;
readonly altKey: boolean;
readonly metaKey: boolean;
readonly editorInfo?: {
isFirstLine: boolean;
isLastLine: boolean;
isSuggesting: boolean;
isDirty: boolean;
contents: string;
clear(): void;
};
preventDefault(): void;
stopPropagation(): void;
}