9b121d300a3f069f70eece6d30b19dcf2bf0ed3784d6152c5fe8387cc81b3432a22ad964d34a595ae77b004615bb5a3edf9797b89fde32cd9c92809979bcd6 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. import './iPadShowKeyboard.css';
  6. import * as dom from '../../../../base/browser/dom.js';
  7. import { Disposable } from '../../../../base/common/lifecycle.js';
  8. import { registerEditorContribution } from '../../../browser/editorExtensions.js';
  9. import { isIOS } from '../../../../base/common/platform.js';
  10. export class IPadShowKeyboard extends Disposable {
  11. constructor(editor) {
  12. super();
  13. this.editor = editor;
  14. this.widget = null;
  15. if (isIOS) {
  16. this._register(editor.onDidChangeConfiguration(() => this.update()));
  17. this.update();
  18. }
  19. }
  20. update() {
  21. const shouldHaveWidget = (!this.editor.getOption(83 /* EditorOption.readOnly */));
  22. if (!this.widget && shouldHaveWidget) {
  23. this.widget = new ShowKeyboardWidget(this.editor);
  24. }
  25. else if (this.widget && !shouldHaveWidget) {
  26. this.widget.dispose();
  27. this.widget = null;
  28. }
  29. }
  30. dispose() {
  31. super.dispose();
  32. if (this.widget) {
  33. this.widget.dispose();
  34. this.widget = null;
  35. }
  36. }
  37. }
  38. IPadShowKeyboard.ID = 'editor.contrib.iPadShowKeyboard';
  39. class ShowKeyboardWidget extends Disposable {
  40. constructor(editor) {
  41. super();
  42. this.editor = editor;
  43. this._domNode = document.createElement('textarea');
  44. this._domNode.className = 'iPadShowKeyboard';
  45. this._register(dom.addDisposableListener(this._domNode, 'touchstart', (e) => {
  46. this.editor.focus();
  47. }));
  48. this._register(dom.addDisposableListener(this._domNode, 'focus', (e) => {
  49. this.editor.focus();
  50. }));
  51. this.editor.addOverlayWidget(this);
  52. }
  53. dispose() {
  54. this.editor.removeOverlayWidget(this);
  55. super.dispose();
  56. }
  57. // ----- IOverlayWidget API
  58. getId() {
  59. return ShowKeyboardWidget.ID;
  60. }
  61. getDomNode() {
  62. return this._domNode;
  63. }
  64. getPosition() {
  65. return {
  66. preference: 1 /* OverlayWidgetPositionPreference.BOTTOM_RIGHT_CORNER */
  67. };
  68. }
  69. }
  70. ShowKeyboardWidget.ID = 'editor.contrib.ShowKeyboardWidget';
  71. registerEditorContribution(IPadShowKeyboard.ID, IPadShowKeyboard);