Path: blob/main/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import './iPadShowKeyboard.css';6import * as dom from '../../../../base/browser/dom.js';7import { Disposable } from '../../../../base/common/lifecycle.js';8import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, OverlayWidgetPositionPreference } from '../../../browser/editorBrowser.js';9import { EditorContributionInstantiation, registerEditorContribution } from '../../../browser/editorExtensions.js';10import { IEditorContribution } from '../../../common/editorCommon.js';11import { EditorOption } from '../../../common/config/editorOptions.js';12import { isIOS } from '../../../../base/common/platform.js';1314export class IPadShowKeyboard extends Disposable implements IEditorContribution {1516public static readonly ID = 'editor.contrib.iPadShowKeyboard';1718private readonly editor: ICodeEditor;19private widget: ShowKeyboardWidget | null;2021constructor(editor: ICodeEditor) {22super();23this.editor = editor;24this.widget = null;25if (isIOS) {26this._register(editor.onDidChangeConfiguration(() => this.update()));27this.update();28}29}3031private update(): void {32const shouldHaveWidget = (!this.editor.getOption(EditorOption.readOnly));3334if (!this.widget && shouldHaveWidget) {3536this.widget = new ShowKeyboardWidget(this.editor);3738} else if (this.widget && !shouldHaveWidget) {3940this.widget.dispose();41this.widget = null;4243}44}4546public override dispose(): void {47super.dispose();48if (this.widget) {49this.widget.dispose();50this.widget = null;51}52}53}5455class ShowKeyboardWidget extends Disposable implements IOverlayWidget {5657private static readonly ID = 'editor.contrib.ShowKeyboardWidget';5859private readonly editor: ICodeEditor;6061private readonly _domNode: HTMLElement;6263constructor(editor: ICodeEditor) {64super();65this.editor = editor;66this._domNode = document.createElement('textarea');67this._domNode.className = 'iPadShowKeyboard';6869this._register(dom.addDisposableListener(this._domNode, 'touchstart', (e) => {70this.editor.focus();71}));72this._register(dom.addDisposableListener(this._domNode, 'focus', (e) => {73this.editor.focus();74}));7576this.editor.addOverlayWidget(this);77}7879public override dispose(): void {80this.editor.removeOverlayWidget(this);81super.dispose();82}8384// ----- IOverlayWidget API8586public getId(): string {87return ShowKeyboardWidget.ID;88}8990public getDomNode(): HTMLElement {91return this._domNode;92}9394public getPosition(): IOverlayWidgetPosition {95return {96preference: OverlayWidgetPositionPreference.BOTTOM_RIGHT_CORNER97};98}99}100101registerEditorContribution(IPadShowKeyboard.ID, IPadShowKeyboard, EditorContributionInstantiation.Eventually);102103104