Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import './iPadShowKeyboard.css';
7
import * as dom from '../../../../base/browser/dom.js';
8
import { Disposable } from '../../../../base/common/lifecycle.js';
9
import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, OverlayWidgetPositionPreference } from '../../../browser/editorBrowser.js';
10
import { EditorContributionInstantiation, registerEditorContribution } from '../../../browser/editorExtensions.js';
11
import { IEditorContribution } from '../../../common/editorCommon.js';
12
import { EditorOption } from '../../../common/config/editorOptions.js';
13
import { isIOS } from '../../../../base/common/platform.js';
14
15
export class IPadShowKeyboard extends Disposable implements IEditorContribution {
16
17
public static readonly ID = 'editor.contrib.iPadShowKeyboard';
18
19
private readonly editor: ICodeEditor;
20
private widget: ShowKeyboardWidget | null;
21
22
constructor(editor: ICodeEditor) {
23
super();
24
this.editor = editor;
25
this.widget = null;
26
if (isIOS) {
27
this._register(editor.onDidChangeConfiguration(() => this.update()));
28
this.update();
29
}
30
}
31
32
private update(): void {
33
const shouldHaveWidget = (!this.editor.getOption(EditorOption.readOnly));
34
35
if (!this.widget && shouldHaveWidget) {
36
37
this.widget = new ShowKeyboardWidget(this.editor);
38
39
} else if (this.widget && !shouldHaveWidget) {
40
41
this.widget.dispose();
42
this.widget = null;
43
44
}
45
}
46
47
public override dispose(): void {
48
super.dispose();
49
if (this.widget) {
50
this.widget.dispose();
51
this.widget = null;
52
}
53
}
54
}
55
56
class ShowKeyboardWidget extends Disposable implements IOverlayWidget {
57
58
private static readonly ID = 'editor.contrib.ShowKeyboardWidget';
59
60
private readonly editor: ICodeEditor;
61
62
private readonly _domNode: HTMLElement;
63
64
constructor(editor: ICodeEditor) {
65
super();
66
this.editor = editor;
67
this._domNode = document.createElement('textarea');
68
this._domNode.className = 'iPadShowKeyboard';
69
70
this._register(dom.addDisposableListener(this._domNode, 'touchstart', (e) => {
71
this.editor.focus();
72
}));
73
this._register(dom.addDisposableListener(this._domNode, 'focus', (e) => {
74
this.editor.focus();
75
}));
76
77
this.editor.addOverlayWidget(this);
78
}
79
80
public override dispose(): void {
81
this.editor.removeOverlayWidget(this);
82
super.dispose();
83
}
84
85
// ----- IOverlayWidget API
86
87
public getId(): string {
88
return ShowKeyboardWidget.ID;
89
}
90
91
public getDomNode(): HTMLElement {
92
return this._domNode;
93
}
94
95
public getPosition(): IOverlayWidgetPosition {
96
return {
97
preference: OverlayWidgetPositionPreference.BOTTOM_RIGHT_CORNER
98
};
99
}
100
}
101
102
registerEditorContribution(IPadShowKeyboard.ID, IPadShowKeyboard, EditorContributionInstantiation.Eventually);
103
104